MCPcopy Create free account
hub / github.com/OpenBitSys/BitDistiller / token_f1_score

Function token_f1_score

test/general/lm_eval/tasks/qasper.py:88–101  ·  view source on GitHub ↗

Taken from the official evaluation script for v1.1 of the SQuAD dataset.

(prediction, ground_truth)

Source from the content-addressed store, hash-verified

86
87
88def token_f1_score(prediction, ground_truth):
89 """
90 Taken from the official evaluation script for v1.1 of the SQuAD dataset.
91 """
92 prediction_tokens = normalize_answer(prediction).split()
93 ground_truth_tokens = normalize_answer(ground_truth).split()
94 common = Counter(prediction_tokens) & Counter(ground_truth_tokens)
95 num_same = sum(common.values())
96 if num_same == 0:
97 return 0
98 precision = 1.0 * num_same / len(prediction_tokens)
99 recall = 1.0 * num_same / len(ground_truth_tokens)
100 f1 = (2 * precision * recall) / (precision + recall)
101 return f1
102
103
104class QASPER(Task):

Callers 1

process_resultsMethod · 0.85

Calls 2

normalize_answerFunction · 0.85
sumFunction · 0.85

Tested by

no test coverage detected