Unverified Commit 2bde99e4 authored by tawsif's avatar tawsif Committed by GitHub
Browse files

Update utils.py (#2870)

parent 86a3b270
from functools import partial from functools import partial
choices = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J"]
choices = [
"A",
"B",
"C",
"D",
"E",
"F",
"G",
"H",
"I",
"J",
"K",
"L",
"M",
"N",
"O",
"P",
]
def format_cot_example(example, including_answer=True): def format_cot_example(example, including_answer=True):
prompt = "Question:\n" prompt = "Question:\n"
...@@ -27,8 +8,12 @@ def format_cot_example(example, including_answer=True): ...@@ -27,8 +8,12 @@ def format_cot_example(example, including_answer=True):
options = example["options"] options = example["options"]
prompt += question + "\n" prompt += question + "\n"
prompt += "Options:\n" prompt += "Options:\n"
for i, opt in enumerate(options): for i, opt in enumerate(options):
if i >= len(choices):
break
prompt += "{}. {}\n".format(choices[i], opt) prompt += "{}. {}\n".format(choices[i], opt)
if including_answer: if including_answer:
cot_content = example["cot_content"].replace( cot_content = example["cot_content"].replace(
"A: Let's think step by step.", "Answer: Let's think step by step." "A: Let's think step by step.", "Answer: Let's think step by step."
...@@ -36,17 +21,15 @@ def format_cot_example(example, including_answer=True): ...@@ -36,17 +21,15 @@ def format_cot_example(example, including_answer=True):
prompt += cot_content + "\n\n" prompt += cot_content + "\n\n"
else: else:
prompt += "Answer: Let's think step by step." prompt += "Answer: Let's think step by step."
return prompt return prompt
doc_to_text = partial(format_cot_example, including_answer=False) doc_to_text = partial(format_cot_example, including_answer=False)
fewshot_to_text = partial(format_cot_example, including_answer=True) fewshot_to_text = partial(format_cot_example, including_answer=True)
def process_docs(dataset, subject): def process_docs(dataset, subject):
return dataset.filter(lambda x: x["category"] == subject) return dataset.filter(lambda x: x["category"] == subject)
process_biology = partial(process_docs, subject="biology") process_biology = partial(process_docs, subject="biology")
process_business = partial(process_docs, subject="business") process_business = partial(process_docs, subject="business")
process_chemistry = partial(process_docs, subject="chemistry") process_chemistry = partial(process_docs, subject="chemistry")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment