Taken from the official evaluation script for v1.1 of the SQuAD dataset. Lower text and remove punctuation, articles and extra whitespace.
(s)
| 41 | |
| 42 | |
| 43 | def 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 | |
| 65 | def categorise_answer(answer_blob): |
no test coverage detected