-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlexical_match.py
27 lines (19 loc) · 910 Bytes
/
lexical_match.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
def normalize_answer(s):
def remove_articles(text):
return regex.sub(r'\b(a|an|the)\b', ' ', text)
def white_space_fix(text):
return ' '.join(text.split())
def remove_punc(text):
exclude = set(string.punctuation)
return ''.join(ch for ch in text if ch not in exclude)
def lower(text):
return text.lower()
return white_space_fix(remove_articles(remove_punc(lower(s))))
def exact_match_score(prediction, ground_truth):
return normalize_answer(prediction) == normalize_answer(ground_truth)
def ems(prediction, ground_truths):
return max([exact_match_score(prediction, gt) for gt in ground_truths])
def lexical_match_score(prediction, ground_truth):
return normalize_answer(ground_truth) in normalize_answer(prediction)
def lms(prediction, ground_truths):
return max([lexical_match_score(prediction, gt) for gt in ground_truths])