Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -31,9 +31,12 @@ def summarize_document(document):
|
|
31 |
# Function to get answer to question
|
32 |
def get_answer(question, context):
|
33 |
inputs = qa_tokenizer(question, context, return_tensors="pt", padding=True, truncation=True, max_length=512)
|
34 |
-
|
35 |
-
|
36 |
-
|
|
|
|
|
|
|
37 |
answer = qa_tokenizer.convert_tokens_to_string(qa_tokenizer.convert_ids_to_tokens(inputs["input_ids"][0][answer_start:answer_end]))
|
38 |
return answer
|
39 |
|
|
|
31 |
# Function to get answer to question
|
32 |
def get_answer(question, context):
|
33 |
inputs = qa_tokenizer(question, context, return_tensors="pt", padding=True, truncation=True, max_length=512)
|
34 |
+
outputs = qa_model(**inputs)
|
35 |
+
start_scores = outputs.start_logits
|
36 |
+
end_scores = outputs.end_logits
|
37 |
+
|
38 |
+
answer_start = torch.argmax(start_scores)
|
39 |
+
answer_end = torch.argmax(end_scores) + 1
|
40 |
answer = qa_tokenizer.convert_tokens_to_string(qa_tokenizer.convert_ids_to_tokens(inputs["input_ids"][0][answer_start:answer_end]))
|
41 |
return answer
|
42 |
|