MCPcopy Create free account
hub / github.com/THUDM/GLM / normalize_answer

Function normalize_answer

tasks/superglue/evaluate.py:17–33  ·  view source on GitHub ↗

Lower text and remove punctuation, articles and extra whitespace.

(s)

Source from the content-addressed store, hash-verified

15
16
17def normalize_answer(s):
18 """Lower text and remove punctuation, articles and extra whitespace."""
19
20 def remove_articles(text):
21 return re.sub(r'\b(a|an|the)\b', ' ', text)
22
23 def white_space_fix(text):
24 return ' '.join(text.split())
25
26 def remove_punc(text):
27 exclude = set(string.punctuation)
28 return ''.join(ch for ch in text if ch not in exclude)
29
30 def lower(text):
31 return unidecode.unidecode(text.lower())
32
33 return white_space_fix(remove_articles(remove_punc(lower(s))))
34
35
36def f1_score(prediction, ground_truth):

Callers 2

f1_scoreFunction · 0.85
exact_match_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