You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
701 B
Python
26 lines
701 B
Python
10 months ago
|
import re
|
||
|
import string
|
||
|
class Evaluator:
|
||
|
def __init__(self, choices, model_name, k=-1):
|
||
|
self.choices = choices
|
||
|
self.model_name = model_name
|
||
|
self.k = k
|
||
|
self.puncs = list(string.punctuation)
|
||
|
|
||
|
def normalize_answer(self,s):
|
||
|
|
||
|
def white_space_fix(text):
|
||
|
return ' '.join(text.split())
|
||
|
|
||
|
def remove_punc(text):
|
||
|
exclude=set(self.puncs)
|
||
|
return ''.join(ch for ch in text if ch not in exclude)
|
||
|
|
||
|
def lower(text):
|
||
|
return text.lower()
|
||
|
|
||
|
return white_space_fix(remove_punc(lower(s)))
|
||
|
|
||
|
def exact_match(self,pred, target):
|
||
|
return self.normalize_answer(pred)==self.normalize_answer(target)
|