in utils/evaluate_retrieval.py [0:0]
def compute_f1_for_retrieved_passage(line: str) -> dict:
"""
Given a serialized JSON line, with fields 'content' and 'answer', find the closest span matching answer,
update the deserialized dict with the span and F1 score, and return the dict.
"""
data = json.loads(line)
content, answer = data['content'], data['answer']
# If there is no answer, although the closest extractive answer is '', in the MRR and recall@k functions below
# we do not count any passage for these questions as relevant.
if len(answer) < 1:
data['heuristic_answer'] = ''
data['f1'] = compute_f1(answer, '')
return data
best_span, best_f1 = find_closest_span_match(content, answer)
data['heuristic_answer'] = best_span
data['f1'] = best_f1
return data