For short-answer tasks the simplest metric is whether the model's answer equals the reference. Taken literally it is brutal: "The Eiffel Tower." and "eiffel tower" are the same answer to a human and different strings to a computer. Benchmarks therefore normalize both sides first (lowercase, strip punctuation and articles, collapse whitespace) and then compare. Exact match is all-or-nothing, so a partially correct answer scores zero. Token F1 gives partial credit by measuring the overlap of words between prediction and reference, which is why question-answering leaderboards usually report both.
Implement normalize_answer, exact_match and token_f1.
normalize_answer(s): lowercase, delete every character in string.punctuation, remove the standalone words a, an and the, then collapse runs of whitespace to single spaces and strip.exact_match(prediction, golds) is 1.0 if the normalized prediction equals the normalized form of any reference in golds, else 0.0.token_f1(prediction, gold) splits both normalized strings on whitespace and counts overlapping tokens as a multiset intersection. If either side is empty the score is 1.0 when both are empty and 0.0 otherwise. Otherwise precision is overlap / len(pred tokens), recall is overlap / len(gold tokens) and F1 is their harmonic mean, or 0.0 if the overlap is 0.Remove punctuation before removing articles, so "the," does not survive as a token.
collections.Counter(a) & Counter(b) is the multiset intersection and sum(c.values()) its size.
No results yet
Run your code to check it against the examples, or submit to run every test.