Skip to content

Commit

Permalink
Merge pull request #205 from neulab/fix_qa_bug
Browse files Browse the repository at this point in the history
Fixed bug in QA metrics

Former-commit-id: c462f38
  • Loading branch information
pfliu-nlp authored Apr 2, 2022
2 parents bc49336 + f53f456 commit 4da06d8
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions explainaboard/metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,14 +418,17 @@ class QAMetric(Metric):

def normalize_answer(self, s: str) -> str:
"""Lower text and remove punctuation, articles and extra whitespace."""
s = re.sub(r'\b(a|an|the)\b', ' ', s)
s = ' '.join(s.split())
s = s.lower()
exclude_punc = set(string.punctuation)
s = ''.join(ch for ch in s if ch not in exclude_punc)
s = s.lower()
s = re.sub(r'\b(a|an|the)\b', ' ', s)
s = ' '.join(s.split())
return s

def calc_stats_from_data(self, true_data: list, pred_data: list) -> MetricStats:
def calc_stats_from_data(
self, true_data: list[Union[str, list[str]]], pred_data: list[str]
) -> MetricStats:
true_data = [[x] if isinstance(x, str) else x for x in true_data]
return MetricStats(
np.array(
[
Expand Down

0 comments on commit 4da06d8

Please sign in to comment.