The generation parameters are set to produce a concise answer (maximum of 10 new tokens). This helps in parsing the response to get the specific answer choice.
Answer Parsing
We parse out the specific answer choice from our models response.
def parse_answer(response):
match = re.search(r"Answer:\s*Option\s*(\d+)", response, re.IGNORECASE)
if match:
answer = f"Option {match.group(1)}"
else:
match = re.search(r"(\d+)", response, re.IGNORECASE)
if match:
answer = f"Option {match.group(1)}"
else:
answer = "Error"
return answer