Rehan3024 commited on
Commit
0c41870
1 Parent(s): 393ec5b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -3
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
- start_positions, end_positions = qa_model(**inputs)
35
- answer_start = torch.argmax(start_positions)
36
- answer_end = torch.argmax(end_positions) + 1
 
 
 
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