harshhpareek lorenzoscottb commited on
Commit
d24654e
0 Parent(s):

Duplicate from lorenzoscottb/phrase-entailment

Browse files

Co-authored-by: Lorenzo Bertolini <[email protected]>

Files changed (5) hide show
  1. .gitattributes +34 -0
  2. OOV_Train_2.pkl +3 -0
  3. README.md +14 -0
  4. app.py +68 -0
  5. requirements.txt +1 -0
.gitattributes ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tflite filter=lfs diff=lfs merge=lfs -text
29
+ *.tgz filter=lfs diff=lfs merge=lfs -text
30
+ *.wasm filter=lfs diff=lfs merge=lfs -text
31
+ *.xz filter=lfs diff=lfs merge=lfs -text
32
+ *.zip filter=lfs diff=lfs merge=lfs -text
33
+ *.zst filter=lfs diff=lfs merge=lfs -text
34
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
OOV_Train_2.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6fb9dff8ebc3bfff5fe07d2ed347b1ed0d9d05d84643f51a91bcf16b5e54be32
3
+ size 4128194
README.md ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Phrase Entailment
3
+ emoji: ❌✅
4
+ colorFrom: blue
5
+ colorTo: blue
6
+ sdk: gradio
7
+ sdk_version: 3.16.2
8
+ app_file: app.py
9
+ pinned: false
10
+ license: cc-by-nc-2.0
11
+ duplicated_from: lorenzoscottb/phrase-entailment
12
+ ---
13
+
14
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pickle
3
+ import pandas as pd
4
+
5
+
6
+ data = pickle.load(open("OOV_Train_2.pkl", "rb"))
7
+ data = pd.DataFrame(
8
+ data,
9
+ columns=["Input_Seq", "Label", "Adj_Class", "Adj", "Nn", "Hypr", "Adj_NN"]
10
+ )
11
+
12
+ adjs = set(data["Adj"])
13
+ Nns = set(list(data["Nn"]) + list(data["Hypr"]))
14
+ all_set = set(list(adjs) + list(Nns))
15
+
16
+ def test_input(words):
17
+ word_dict = ""
18
+ for w in words.split(","):
19
+ if w in all_set:
20
+ word_dict += "{} : in-distribution\n".format(w)
21
+ else:
22
+ word_dict += "{} : out-of-distribution\n".format(w)
23
+ return word_dict
24
+
25
+
26
+ title = "Phrase-Entailment Detection with BERT"
27
+
28
+ description = """
29
+ Did you know that logically speaking **A small cat is not a small animal**, and that **A fake smile is not a smile**? Learn more by testing our BERT model tuned to perform phrase-level adjective-noun entailment. The proposed model was tuned with a section of the PLANE (**P**hrase-**L**evel **A**djective-**N**oun **E**ntailment) dataset, introduced in COLING 2022 [Bertolini et al.,](https://aclanthology.org/2022.coling-1.359/). Please note that the scope of the model is not to run lexical-entailment or hypernym detection (e.g., *"A dog is an animal*"), but to perform a very specific subset of phrase-level compositional entailment over adjective-noun phrases. The type of question you can ask the model are limited, and should have one of three forms:
30
+
31
+ - An *Adjective-Noun* is a *Noun* (e.g. A red car is a car)
32
+
33
+ - An *Adjective-Noun* is a *Hypernym(Noun)* (e.g. A red car is a vehicle)
34
+
35
+ - An *Adjective-Noun* is a *Adjective-Hypernym(Noun)* (e.g. A red car is a red vehicle)
36
+
37
+ As in the examples above, the **adjective should be the same for both phrases**, and the **Hypernym(Noun) should be a true hypernym of the selected noun**.
38
+
39
+ The current model achieves an accuracy of 90% on out-of-distribution evaluation.
40
+ Use the next page to check if your test-items (i.e. adjective, noun and hypernyms) were part of the training data!"""
41
+
42
+ examples = [["A red car is a vehicle"], ["A fake smile is a smile"], ["A small cat is a small animal"]]
43
+
44
+ interface_model = gr.Interface.load(
45
+ "huggingface/lorenzoscottb/bert-base-cased-PLANE-ood-2",
46
+ description=description,
47
+ examples=examples,
48
+ title=title,
49
+ )
50
+
51
+
52
+ description_w = """
53
+ You can use this page to test if a set of words was included in the training data used to tune the model. As in the samples below, use as input a series of words separated solely by a comma (e.g. *red,car,vehicle*).
54
+ """
55
+
56
+ examples_w = [["red,car,vehicle"], ["fake,smile"], ["small,cat,animal"]]
57
+
58
+ interface_words = gr.Interface(
59
+ fn=test_input,
60
+ inputs=gr.Textbox(label="Input:word_1,word2,...,word_n"),
61
+ outputs=gr.Textbox(label="In training-distribution?"),
62
+ description=description_w,
63
+ examples=examples_w,
64
+ )
65
+
66
+ gr.TabbedInterface(
67
+ [interface_model, interface_words], ["Test Model", "Check if words in/out-distribution"]
68
+ ).launch()
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ pandas