hf-dongpyo commited on
Commit
84fb171
·
1 Parent(s): 71c9e6d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -6
app.py CHANGED
@@ -1,12 +1,22 @@
1
- from transformers import pipeline
 
2
  import gradio as grad
3
 
4
- zero_shot_classifier = pipeline("zero-shot-classification")
 
 
5
 
6
- def classify(text, labels):
7
- classifier_labels = labels.split(",")
8
- #["software", "politics", "love", "movies", "emergency", "advertisment", "sports"]
9
- response = zero_shot_classifier(text, classifier_labels)
 
 
 
 
 
 
 
10
 
11
  return response
12
 
 
1
+ # from transformers import pipeline
2
+ from transformers import BartForSequenceClassification, BartTokenizer
3
  import gradio as grad
4
 
5
+ # zero_shot_classifier = pipeline("zero-shot-classification")
6
+ bart_tkn = BartTokenizer.from_pretrained('facebook/bart-large-mnli')
7
+ mdl = BartForSequenceClassification.from_pretrained('facebook/bart-large-mnli')
8
 
9
+ # def classify(text, labels):
10
+ def classify(text, label):
11
+ # classifier_labels = labels.split(",")
12
+ # #["software", "politics", "love", "movies", "emergency", "advertisment", "sports"]
13
+ # response = zero_shot_classifier(text, classifier_labels)
14
+
15
+ tkn_ids = bart_tkn.encode(text, label, return_tensors = "pt")
16
+ tkn_lgts = mdl(tkn_ids)[0]
17
+ entail_contra_tkn_lgts = tkn_lgts[:, [0, 2]]
18
+ probab = entail_contra_tkn_lgts.softmax(dim = 1)
19
+ response = probab[:, 1].item() * 100
20
 
21
  return response
22