def _normalize_answer(s):
"""Normalize string to score answers according to SQuAD dataset scoring rules.
Remove articles, remove punctuation, fix multiple whitespaces in string, and convert all characters to lowercase.
"""
def remove_articles(text):
return re.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))))
评论列表
文章目录