MCPcopy
hub / github.com/ymcui/Chinese-LLaMA-Alpaca-2 / normalize_answer

Function normalize_answer

scripts/longbench/metrics.py:12–28  ·  view source on GitHub ↗

Lower text and remove punctuation, articles and extra whitespace.

(s)

Source from the content-addressed store, hash-verified

10from rouge import Rouge
11
12def normalize_answer(s):
13 """Lower text and remove punctuation, articles and extra whitespace."""
14
15 def remove_articles(text):
16 return re.sub(r"\b(a|an|the)\b", " ", text)
17
18 def white_space_fix(text):
19 return " ".join(text.split())
20
21 def remove_punc(text):
22 exclude = set(string.punctuation)
23 return "".join(ch for ch in text if ch not in exclude)
24
25 def lower(text):
26 return text.lower()
27
28 return white_space_fix(remove_articles(remove_punc(lower(s))))
29
30
31def normalize_zh_answer(s):

Callers 1

qa_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