Spaces:
Sleeping
Sleeping
Commit
·
ee04bd8
1
Parent(s):
f132c1d
first
Browse files
app.py
CHANGED
|
@@ -14,18 +14,9 @@ def answer_question(context, question):
|
|
| 14 |
# Encode the context and question
|
| 15 |
inputs = tokenizer(context, question, return_tensors="pt")
|
| 16 |
|
| 17 |
-
# Perform question answering
|
| 18 |
-
outputs = model(**inputs)
|
| 19 |
-
|
| 20 |
-
# Get the predicted start and end token positions
|
| 21 |
-
start_scores, end_scores = outputs.start_logits, outputs.end_logits
|
| 22 |
-
|
| 23 |
-
# Decode the answer based on predicted positions
|
| 24 |
-
answer_start = torch.argmax(start_scores)
|
| 25 |
-
answer_end = torch.argmax(end_scores) + 1
|
| 26 |
|
| 27 |
# Get answer tokens and convert them to string
|
| 28 |
-
answer = tokenizer.convert_ids_to_tokens(inputs["input_ids"][0]
|
| 29 |
answer = "".join(answer)
|
| 30 |
|
| 31 |
return answer
|
|
|
|
| 14 |
# Encode the context and question
|
| 15 |
inputs = tokenizer(context, question, return_tensors="pt")
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
# Get answer tokens and convert them to string
|
| 19 |
+
answer = tokenizer.convert_ids_to_tokens(inputs["input_ids"][0])
|
| 20 |
answer = "".join(answer)
|
| 21 |
|
| 22 |
return answer
|