rickxzo commited on
Commit
72f383a
·
verified ·
1 Parent(s): c24d815

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -0
app.py CHANGED
@@ -5,8 +5,26 @@ from transformers import AutoTokenizer as AT
5
  model = ASC.from_pretrained("rickxzo/albert-large-v2-s.a.m-nli")
6
  tokenizer = AT.from_pretrained("rickxzo/albert-large-v2-s.a.m-nli")
7
 
 
 
 
 
 
 
 
 
 
8
  st.title("Contradiction Detector using AlBERT model")
9
  premise = st.text_area("Enter the premise: ")
10
  hypothesis = st.text_area("Enter the hypothesis: ")
11
 
 
 
 
 
 
 
 
 
 
12
 
 
5
  model = ASC.from_pretrained("rickxzo/albert-large-v2-s.a.m-nli")
6
  tokenizer = AT.from_pretrained("rickxzo/albert-large-v2-s.a.m-nli")
7
 
8
+ def infer(sentence1, sentence2):
9
+ inputs = tokenizer(sentence1, sentence2, return_tensors="pt", truncation=True, padding=True)
10
+ with torch.no_grad():
11
+ outputs = model(**inputs)
12
+
13
+ logits = outputs.logits
14
+ probs = torch.nn.functional.softmax(logits, dim=-1)
15
+ return torch.argmax(probs).item()
16
+
17
  st.title("Contradiction Detector using AlBERT model")
18
  premise = st.text_area("Enter the premise: ")
19
  hypothesis = st.text_area("Enter the hypothesis: ")
20
 
21
+ if premise and hypothesis:
22
+ k = infer(premise, hypothesis)
23
+ if k == 2:
24
+ st.write("Contradicting Statements Detected!")
25
+ elif k == 1:
26
+ st.write("Neutral Statements Detected.")
27
+ elif k == 0:
28
+ st.write("Entailing Statements Detected.")
29
+
30