Nighter commited on
Commit
a9f133d
1 Parent(s): 22d7759

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -6
app.py CHANGED
@@ -50,15 +50,24 @@ def predict_answer(context, question):
50
  # Load short model
51
  short_answer_model = pipeline(model="Nighter/QA_wiki_data_short_answer", from_tf=True)
52
 
53
- def answer_questions(context, question):
54
- long_answer = predict_answer(context, question)
55
- short_answer_result = short_answer_model(question=question, context=remove_parentheses(context))
56
- return short_answer_result['answer'], long_answer
57
 
58
  def answer_questions(context, question):
59
  long_score, long_answer = predict_answer(context, question)
60
- short_answer_result = short_answer_model(question=question, context=remove_parentheses(context))
61
- # short_answer_result = short_answer_model(question=question, context=remove_parentheses(long_answer))
 
 
 
 
 
 
 
 
 
62
  return short_answer_result['answer'], short_answer_result['score'], long_answer, long_score
63
 
64
 
 
50
  # Load short model
51
  short_answer_model = pipeline(model="Nighter/QA_wiki_data_short_answer", from_tf=True)
52
 
53
+ # def answer_questions(context, question):
54
+ # long_answer = predict_answer(context, question)
55
+ # short_answer_result = short_answer_model(question=question, context=remove_parentheses(context))
56
+ # return short_answer_result['answer'], long_answer
57
 
58
  def answer_questions(context, question):
59
  long_score, long_answer = predict_answer(context, question)
60
+
61
+ # Check if the original context is longer than 512 tokens
62
+ if len(tokenizer.texts_to_sequences([context])[0]) > 512:
63
+ # If yes, use the long answer as the context for the short answer model
64
+ short_context = long_answer
65
+ else:
66
+ # If no, use the original context
67
+ short_context = remove_parentheses(context)
68
+
69
+ short_answer_result = short_answer_model(question=question, context=short_context)
70
+
71
  return short_answer_result['answer'], short_answer_result['score'], long_answer, long_score
72
 
73