shahrukhx01
commited on
Commit
·
5c44a3f
1
Parent(s):
1086d8a
Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
from transformers import (
|
3 |
+
AutoModelForSequenceClassification,
|
4 |
+
AutoTokenizer,
|
5 |
+
)
|
6 |
+
|
7 |
+
model = AutoModelForSequenceClassification.from_pretrained("shahrukhx01/roberta-base-boolq")
|
8 |
+
model.to(device)
|
9 |
+
#model.push_to_hub("roberta-base-boolq")
|
10 |
+
|
11 |
+
tokenizer = AutoTokenizer.from_pretrained("shahrukhx01/roberta-base-boolq")
|
12 |
+
|
13 |
+
def predict(question, passage):
|
14 |
+
sequence = tokenizer.encode_plus(question, passage, return_tensors="pt")['input_ids'].to(device)
|
15 |
+
|
16 |
+
logits = model(sequence)[0]
|
17 |
+
probabilities = torch.softmax(logits, dim=1).detach().cpu().tolist()[0]
|
18 |
+
proba_yes = round(probabilities[1], 2)
|
19 |
+
proba_no = round(probabilities[0], 2)
|
20 |
+
|
21 |
+
print(f"Question: {question}, Yes: {proba_yes}, No: {proba_no}")
|
22 |
+
|
23 |
+
passage = """Berlin is the capital and largest city of Germany by both area and population. Its 3.8 million inhabitants make it the European Union's most populous city,
|
24 |
+
according to population within city limits."""
|
25 |
+
|
26 |
+
question = "Is Berlin the smallest city of Germany?"
|
27 |
+
predict(s_question, passage)
|