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

Function normalize_answer

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

Taken from the official evaluation script for v1.1 of the SQuAD dataset. Lower text and remove punctuation, articles and extra whitespace.

(s)

Source from the content-addressed store, hash-verified

41
42
43def normalize_answer(s):
44 """
45 Taken from the official evaluation script for v1.1 of the SQuAD dataset.
46 Lower text and remove punctuation, articles and extra whitespace.
47 """
48
49 def remove_articles(text):
50 return re.sub(r"\b(a|an|the)\b", " ", text)
51
52 def white_space_fix(text):
53 return " ".join(text.split())
54
55 def remove_punc(text):
56 exclude = set(string.punctuation)
57 return "".join(ch for ch in text if ch not in exclude)
58
59 def lower(text):
60 return text.lower()
61
62 return white_space_fix(remove_articles(remove_punc(lower(s))))
63
64
65def categorise_answer(answer_blob):

Callers 1

token_f1_scoreFunction · 0.85

Calls 4

white_space_fixFunction · 0.85
remove_articlesFunction · 0.85
remove_puncFunction · 0.85
lowerFunction · 0.85

Tested by

no test coverage detected