etweedy commited on
Commit
3fe1714
·
1 Parent(s): 3c3dc6d

Upload utils.py

Browse files
Files changed (1) hide show
  1. lib/utils.py +7 -3
lib/utils.py CHANGED
@@ -177,12 +177,16 @@ def make_predictions(model,tokenizer,inputs,examples,
177
  answer_probs = softmax(answer_logits)
178
 
179
  if len(answers)>0:
180
- best_answer = max(answers, key=lambda x:x['logit_score'])
 
181
  predicted_answers.append(
182
- {'id':example_id, 'prediction_text':best_answer['text'], 'confidence':answer_probs[0]}
 
 
183
  )
184
  else:
185
- predicted_answers.append({'id':example_id, 'prediction_text':'','confidence':answer_probs[0]})
 
186
  for pred in predicted_answers:
187
  if pred['prediction_text'] == '':
188
  pred['prediction_text'] = "I don't have an answer based on the context provided."
 
177
  answer_probs = softmax(answer_logits)
178
 
179
  if len(answers)>0:
180
+ # best_answer = max(answers, key=lambda x:x['logit_score'])
181
+ best_answer_idx = np.argmax(answer_logits)
182
  predicted_answers.append(
183
+ {'id':example_id,
184
+ 'prediction_text':answers[best_answer_idx]['text'],
185
+ 'confidence':answer_probs[best_answer_idx]}
186
  )
187
  else:
188
+ predicted_answers.append({'id':example_id, 'prediction_text':'',
189
+ 'confidence':answer_probs[best_answer_idx]})
190
  for pred in predicted_answers:
191
  if pred['prediction_text'] == '':
192
  pred['prediction_text'] = "I don't have an answer based on the context provided."