Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions evaluation/benchmarks/toolqa/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,15 @@ def encode_question(question):

# imported from https://github.com/night-chen/ToolQA/tree/main/benchmark/ReAct/code/agents_chatgpt.py
def normalize_answer(s):
def remove_articles(text):
return re.sub(r'\b(a|an|the|usd)\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))))
# Remove articles and convert to lowercase
s = re.sub(r'\b(a|an|the|usd)\b', ' ', s.lower())

# Remove punctuation using translation, it is generally faster than list comprehensions
translator = str.maketrans('', '', string.punctuation)
s = s.translate(translator)

# Fix white space
return ' '.join(s.split())


def eval_answer(pred, answer):
Expand Down