Update app.py
Browse files
app.py
CHANGED
|
@@ -25,8 +25,8 @@ tokenizer = AutoTokenizer.from_pretrained(model_name,use_fast=False)
|
|
| 25 |
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
| 26 |
|
| 27 |
|
| 28 |
-
premise =
|
| 29 |
-
hypothesis =
|
| 30 |
input = tokenizer(premise, hypothesis, truncation=True, return_tensors="pt")
|
| 31 |
output = model(input["input_ids"].to(device)) # device = "cuda:0" or "cpu"
|
| 32 |
prediction = torch.softmax(output["logits"][0], -1).tolist()
|
|
@@ -35,14 +35,10 @@ prediction = {name: round(float(pred) * 100, 1) for pred, name in zip(prediction
|
|
| 35 |
print(prediction)
|
| 36 |
|
| 37 |
|
| 38 |
-
from
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
#Convert scores to labels
|
| 43 |
-
label_mapping = ['contradiction', 'entailment', 'neutral']
|
| 44 |
-
labels = [label_mapping[score_max] for score_max in scores1.argmax(axis=1)]
|
| 45 |
-
labels
|
| 46 |
|
| 47 |
|
| 48 |
|
|
@@ -67,8 +63,8 @@ def extract_person_names(sentence):
|
|
| 67 |
|
| 68 |
return person_names[0]
|
| 69 |
|
| 70 |
-
person_name1 = extract_person_names(
|
| 71 |
-
person_name2 = extract_person_names(
|
| 72 |
|
| 73 |
st.write("Result:", prediction)
|
| 74 |
|
|
|
|
| 25 |
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
| 26 |
|
| 27 |
|
| 28 |
+
premise = selected_sentence1
|
| 29 |
+
hypothesis = selected_sentence2
|
| 30 |
input = tokenizer(premise, hypothesis, truncation=True, return_tensors="pt")
|
| 31 |
output = model(input["input_ids"].to(device)) # device = "cuda:0" or "cpu"
|
| 32 |
prediction = torch.softmax(output["logits"][0], -1).tolist()
|
|
|
|
| 35 |
print(prediction)
|
| 36 |
|
| 37 |
|
| 38 |
+
from transformers import pipeline
|
| 39 |
+
pipe = pipeline("text-classification",model="sileod/deberta-v3-base-tasksource-nli")
|
| 40 |
+
labels=pipe([dict(text=selected_sentence1,
|
| 41 |
+
text_pair=selected_sentence2)])
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
|
| 44 |
|
|
|
|
| 63 |
|
| 64 |
return person_names[0]
|
| 65 |
|
| 66 |
+
person_name1 = extract_person_names(selected_sentence1)
|
| 67 |
+
person_name2 = extract_person_names(selected_sentence2)
|
| 68 |
|
| 69 |
st.write("Result:", prediction)
|
| 70 |
|