[Sync] update 20240308 (#953)

This commit is contained in:
Fengzhe Zhou 2024-03-11 22:34:19 +08:00 committed by GitHub
parent 848e7c8a76
commit bdd85358cc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 374 additions and 43 deletions

View File

@ -0,0 +1,114 @@
from opencompass.openicl.icl_prompt_template import PromptTemplate
from opencompass.openicl.icl_retriever import ZeroRetriever
from opencompass.openicl.icl_inferencer import GenInferencer
from opencompass.openicl.icl_evaluator import CircularEvaluator, AccEvaluator
from opencompass.datasets import MathBenchDataset, mathbench_postprocess
from opencompass.utils.text_postprocessors import first_option_postprocess
single_choice_prompts = {
"single_choice_cn_with_reasoning": "以下是一道关于数学的单项选择题请你一步一步推理并在最后用“所以答案为选项X”给出答案其中“X”为选项ABCD中你认为正确的选项。下面是你要回答的问题\n{question}\n让我们一步一步思考:\n",
"single_choice_cn": "以下是一道关于数学的单项选择题,请你直接回答正确答案的选项序号。\n下面是你要回答的题目:\n{question}\n答案选项:",
"single_choice_en_with_reasoning": "Here is a multiple-choice question about mathematics. Please reason through it step by step, and at the end, provide your answer option with 'Therefore, the correct answer is option X', Where 'X' is the correct option you think from ABCD. Here is the question you need to answer:\n{question}\nLet's think step by step:",
"single_choice_en": "Here is a multiple-choice question about mathematics. Please provide the correct answer option directly.\nHere is the question you need to answer:\n{question}\nAnswer option:",
}
cloze_prompts = {
"cloze_cn": [
dict(role='HUMAN', prompt='Q: 林中有15棵树。林务工人员今天将在林中种植树木。完成后将有21棵树。林务工人员今天种植了多少棵树'),
dict(role='BOT', prompt='A: 我们从15棵树开始。后来有21棵树。差值必定是他们种植的树木数量。所以他们必须种植了21 - 15 = 6棵树。答案是 6\n'),
dict(role='HUMAN', prompt='Q: 如果停车场有3辆车又有2辆车进来停车场里有多少辆车'),
dict(role='BOT', prompt='A: 停车场已经有3辆车。又进来了2辆车。现在有3 + 2 = 5辆车。答案是 5\n'),
dict(role='HUMAN', prompt='Q: 黎恩有32块巧克力她的妹妹有42块。如果他们吃了35块他们总共剩下多少块'),
dict(role='BOT', prompt='A: 黎恩有32块巧克力Leah的妹妹有42块。这意味着原本有32 + 42 = 74块巧克力。被吃掉了35块。所以他们总共还剩下74 - 35 = 39块巧克力。答案是 39\n'),
dict(role='HUMAN', prompt='Q: 杰森有20个棒棒糖。他给丹妮一些棒棒糖。现在Jason只剩下12个棒棒糖。杰森给丹妮多少个棒棒糖'),
dict(role='BOT', prompt='A: 杰森有20个棒棒糖。因为他现在只剩下12个所以他必须把剩下的都给了丹妮。他给丹妮的棒棒糖数量必定是20 - 12 = 8个。答案是 8\n'),
dict(role='HUMAN', prompt='Q: 莎莎有五个玩具。在圣诞节,他从他的爸爸和妈妈那里各得到了两个玩具。现在他有多少个玩具?'),
dict(role='BOT', prompt='A: 她有5个玩具。他从妈妈那里得到了2个所以之后他有5 + 2 = 7个玩具。然后他从爸爸那里得到了2个所以总共他有7 + 2 = 9个玩具。答案是 9\n'),
dict(role='HUMAN', prompt='Q: 服务器房间里有九台电脑。从周一到周四每天增加五台电脑。现在服务器房里有多少台电脑?'),
dict(role='BOT', prompt='A: 从周一到周四有4天。每天增加5台电脑。这意味着总共增加了4 * 5 = 20台电脑。一开始有9台电脑所以现在有9 + 20 = 29台电脑。答案是 29\n'),
dict(role='HUMAN', prompt='Q: 迈克尔有58个高尔夫球。星期二他丢失了23个高尔夫球。星期三他又丢失了2个。星期三结束时他还剩下多少个高尔夫球'),
dict(role='BOT', prompt='A: 迈克尔一开始有58个球。星期二他丢失了23个所以之后他还剩下58 - 23 = 35个球。星期三他又丢失了2个所以现在他还剩下35 - 2 = 33个球。答案是 33\n'),
dict(role='HUMAN', prompt='Q: 奥利弗有23美元。她用每个3美元的价格买了五个百吉饼。她还剩下多少钱'),
dict(role='BOT', prompt='A: 她以每个3美元的价格买了5个百吉饼。这意味着她在百吉饼上花费了5 * 3 = 15美元。她一开始有23美元所以现在她还剩下23 - 15 = 8美元。答案是 8\n'),
dict(role='HUMAN', prompt='Q: {question}'),
dict(role='BOT', prompt='A: {answer}'),
],
"cloze_en": [
dict(role='HUMAN', prompt='Q: There are 15 trees in the grove. Grove workers will plant trees in the grove today. After they are done, there will be 21 trees. How many trees did the grove workers plant today?'),
dict(role='BOT', prompt='A: We start with 15 trees. Later we have 21 trees. The difference must be the number of trees they planted. So, they must have planted 21 - 15 = 6 trees. The answer is 6.\n'),
dict(role='HUMAN', prompt='Q: If there are 3 cars in the parking lot and 2 more cars arrive, how many cars are in the parking lot?'),
dict(role='BOT', prompt='A: There are 3 cars in the parking lot already. 2 more arrive. Now there are 3 + 2 = 5 cars. The answer is 5.\n'),
dict(role='HUMAN', prompt='Q: Leah had 32 chocolates and her sister had 42. If they ate 35, how many pieces do they have left in total?'),
dict(role='BOT', prompt="A: Leah had 32 chocolates and Leah's sister had 42. That means there were originally 32 + 42 = 74 chocolates. 35 have been eaten. So in total they still have 74 - 35 = 39 chocolates. The answer is 39.\n"),
dict(role='HUMAN', prompt='Q: Jason had 20 lollipops. He gave Denny some lollipops. Now Jason has 12 lollipops. How many lollipops did Jason give to Denny?'),
dict(role='BOT', prompt='A: Jason had 20 lollipops. Since he only has 12 now, he must have given the rest to Denny. The number of lollipops he has given to Denny must have been 20 - 12 = 8 lollipops. The answer is 8.\n'),
dict(role='HUMAN', prompt='Q: Shawn has five toys. For Christmas, he got two toys each from his mom and dad. How many toys does he have now?'),
dict(role='BOT', prompt='A: He has 5 toys. He got 2 from mom, so after that he has 5 + 2 = 7 toys. Then he got 2 more from dad, so in total he has 7 + 2 = 9 toys. The answer is 9.\n'),
dict(role='HUMAN', prompt='Q: There were nine computers in the server room. Five more computers were installed each day, from monday to thursday. How many computers are now in the server room?'),
dict(role='BOT', prompt='A: There are 4 days from monday to thursday. 5 computers were added each day. That means in total 4 * 5 = 20 computers were added. There were 9 computers in the beginning, so now there are 9 + 20 = 29 computers. The answer is 29.\n'),
dict(role='HUMAN', prompt='Q: Michael had 58 golf balls. On tuesday, he lost 23 golf balls. On wednesday, he lost 2 more. How many golf balls did he have at the end of wednesday?'),
dict(role='BOT', prompt='A: Michael initially had 58 balls. He lost 23 on Tuesday, so after that he has 58 - 23 = 35 balls. On Wednesday he lost 2 more so now he has 35 - 2 = 33 balls. The answer is 33.\n'),
dict(role='HUMAN', prompt='Q: Olivia has $23. She bought five bagels for $3 each. How much money does she have left?'),
dict(role='BOT', prompt='A: She bought 5 bagels for $3 each. This means she spent 5 * $3 = $15 on the bagels. She had $23 in beginning, so now she has $23 - $15 = $8. The answer is 8.\n'),
dict(role='HUMAN', prompt='Q: {question}'),
dict(role='BOT', prompt='A: {answer}\n'),
]}
mathbench_sets = {
# Practice Part
'college': ['single_choice_cn', 'single_choice_en'],
'high': ['single_choice_cn', 'single_choice_en'],
'middle': ['single_choice_cn', 'single_choice_en'],
'primary': ['cloze_cn', 'cloze_en'],
'calculate': ['cloze_en'],
# Theory part
'college_knowledge': ['single_choice_cn','single_choice_en'],
'high_knowledge': ['single_choice_cn','single_choice_en'],
'middle_knowledge': ['single_choice_cn','single_choice_en'],
'primary_knowledge': ['single_choice_cn','single_choice_en'],
}
# Generate reasoning path or not, only for single choice
with_reasoning = True
# Use circular evaluation or not
with_circular_eval = True
mathbench_datasets = []
for _split in list(mathbench_sets.keys()):
for _name in mathbench_sets[_split]:
mathbench_infer_cfg = dict(
prompt_template=dict(
type=PromptTemplate,
template=dict(
round=[
dict(
role="HUMAN",
prompt=single_choice_prompts[_name + "_with_reasoning"] if with_reasoning else single_choice_prompts[_name],
),
dict(role="BOT", prompt="{answer}")] if 'choice' in _name else cloze_prompts[_name],
),
),
retriever=dict(type=ZeroRetriever),
inferencer=dict(type=GenInferencer, max_out_len=512),
)
mathbench_eval_cfg = dict(
evaluator=dict(type=CircularEvaluator if 'choice' in _name and with_circular_eval else AccEvaluator),
pred_postprocessor=dict(type=first_option_postprocess, options='ABCD') if 'single_choice' in _name else dict(type=mathbench_postprocess, name=_name))
mathbench_datasets.append(
dict(
abbr="mathbench-" + _split + '-' + _name,
type=MathBenchDataset,
path=f"./data/mathbench_v1_ori/{_split}",
name=_name,
with_circular=with_circular_eval,
reader_cfg=dict(
input_columns=["question"],
output_column="answer"
),
infer_cfg=mathbench_infer_cfg,
eval_cfg=mathbench_eval_cfg,
))

View File

@ -0,0 +1,124 @@
from opencompass.openicl.icl_prompt_template import PromptTemplate
from opencompass.openicl.icl_retriever import ZeroRetriever
from opencompass.openicl.icl_inferencer import GenInferencer
from opencompass.openicl.icl_evaluator import CircularEvaluator, AccEvaluator
from opencompass.datasets import MathBenchDataset, mathbench_postprocess
from opencompass.utils.text_postprocessors import first_option_postprocess
single_choice_prompts = {
"single_choice_cn_with_reasoning": "以下是一道关于数学的单项选择题请你一步一步推理并在最后用“所以答案为选项X”给出答案其中“X”为选项ABCD中你认为正确的选项。下面是你要回答的问题\n{question}\n让我们一步一步思考:\n",
"single_choice_cn": "以下是一道关于数学的单项选择题,请你直接回答正确答案的选项序号。\n下面是你要回答的题目:\n{question}\n答案选项:",
"single_choice_en_with_reasoning": "Here is a multiple-choice question about mathematics. Please reason through it step by step, and at the end, provide your answer option with 'Therefore, the correct answer is option X', Where 'X' is the correct option you think from ABCD. Here is the question you need to answer:\n{question}\nLet's think step by step:",
"single_choice_en": "Here is a multiple-choice question about mathematics. Please provide the correct answer option directly.\nHere is the question you need to answer:\n{question}\nAnswer option:",
}
cloze_prompts = {
"cloze_cn": [
dict(role="HUMAN", prompt="Q: 林中有15棵树。林务工人员今天将在林中种植树木。完成后将有21棵树。林务工人员今天种植了多少棵树"),
dict(role="BOT", prompt="A: 我们从15棵树开始。后来有21棵树。差值必定是他们种植的树木数量。所以他们必须种植了21 - 15 = 6棵树。答案是 6\n"),
dict(role="HUMAN", prompt="Q: 如果停车场有3辆车又有2辆车进来停车场里有多少辆车"),
dict(role="BOT", prompt="A: 停车场已经有3辆车。又进来了2辆车。现在有3 + 2 = 5辆车。答案是 5\n"),
dict(role="HUMAN", prompt="Q: 黎恩有32块巧克力她的妹妹有42块。如果他们吃了35块他们总共剩下多少块"),
dict(role="BOT", prompt="A: 黎恩有32块巧克力Leah的妹妹有42块。这意味着原本有32 + 42 = 74块巧克力。被吃掉了35块。所以他们总共还剩下74 - 35 = 39块巧克力。答案是 39\n"),
dict(role="HUMAN", prompt="Q: 杰森有20个棒棒糖。他给丹妮一些棒棒糖。现在Jason只剩下12个棒棒糖。杰森给丹妮多少个棒棒糖"),
dict(role="BOT", prompt="A: 杰森有20个棒棒糖。因为他现在只剩下12个所以他必须把剩下的都给了丹妮。他给丹妮的棒棒糖数量必定是20 - 12 = 8个。答案是 8\n"),
dict(role="HUMAN", prompt="Q: 莎莎有五个玩具。在圣诞节,他从他的爸爸和妈妈那里各得到了两个玩具。现在他有多少个玩具?"),
dict(role="BOT", prompt="A: 她有5个玩具。他从妈妈那里得到了2个所以之后他有5 + 2 = 7个玩具。然后他从爸爸那里得到了2个所以总共他有7 + 2 = 9个玩具。答案是 9\n"),
dict(role="HUMAN", prompt="Q: 服务器房间里有九台电脑。从周一到周四每天增加五台电脑。现在服务器房里有多少台电脑?"),
dict(role="BOT", prompt="A: 从周一到周四有4天。每天增加5台电脑。这意味着总共增加了4 * 5 = 20台电脑。一开始有9台电脑所以现在有9 + 20 = 29台电脑。答案是 29\n"),
dict(role="HUMAN", prompt="Q: 迈克尔有58个高尔夫球。星期二他丢失了23个高尔夫球。星期三他又丢失了2个。星期三结束时他还剩下多少个高尔夫球"),
dict(role="BOT", prompt="A: 迈克尔一开始有58个球。星期二他丢失了23个所以之后他还剩下58 - 23 = 35个球。星期三他又丢失了2个所以现在他还剩下35 - 2 = 33个球。答案是 33\n"),
dict(role="HUMAN", prompt="Q: 奥利弗有23美元。她用每个3美元的价格买了五个百吉饼。她还剩下多少钱"),
dict(role="BOT", prompt="A: 她以每个3美元的价格买了5个百吉饼。这意味着她在百吉饼上花费了5 * 3 = 15美元。她一开始有23美元所以现在她还剩下23 - 15 = 8美元。答案是 8\n"),
dict(role="HUMAN", prompt="Q: {question}"),
dict(role="BOT", prompt="A: {answer}"),
],
"cloze_en": [
dict(role="HUMAN", prompt="Q: There are 15 trees in the grove. Grove workers will plant trees in the grove today. After they are done, there will be 21 trees. How many trees did the grove workers plant today?"),
dict(role="BOT", prompt="A: We start with 15 trees. Later we have 21 trees. The difference must be the number of trees they planted. So, they must have planted 21 - 15 = 6 trees. The answer is 6.\n"),
dict(role="HUMAN", prompt="Q: If there are 3 cars in the parking lot and 2 more cars arrive, how many cars are in the parking lot?"),
dict(role="BOT", prompt="A: There are 3 cars in the parking lot already. 2 more arrive. Now there are 3 + 2 = 5 cars. The answer is 5.\n"),
dict(role="HUMAN", prompt="Q: Leah had 32 chocolates and her sister had 42. If they ate 35, how many pieces do they have left in total?"),
dict(role="BOT", prompt="A: Leah had 32 chocolates and Leah's sister had 42. That means there were originally 32 + 42 = 74 chocolates. 35 have been eaten. So in total they still have 74 - 35 = 39 chocolates. The answer is 39.\n"),
dict(role="HUMAN", prompt="Q: Jason had 20 lollipops. He gave Denny some lollipops. Now Jason has 12 lollipops. How many lollipops did Jason give to Denny?"),
dict(role="BOT", prompt="A: Jason had 20 lollipops. Since he only has 12 now, he must have given the rest to Denny. The number of lollipops he has given to Denny must have been 20 - 12 = 8 lollipops. The answer is 8.\n"),
dict(role="HUMAN", prompt="Q: Shawn has five toys. For Christmas, he got two toys each from his mom and dad. How many toys does he have now?"),
dict(role="BOT", prompt="A: He has 5 toys. He got 2 from mom, so after that he has 5 + 2 = 7 toys. Then he got 2 more from dad, so in total he has 7 + 2 = 9 toys. The answer is 9.\n"),
dict(role="HUMAN", prompt="Q: There were nine computers in the server room. Five more computers were installed each day, from monday to thursday. How many computers are now in the server room?"),
dict(role="BOT", prompt="A: There are 4 days from monday to thursday. 5 computers were added each day. That means in total 4 * 5 = 20 computers were added. There were 9 computers in the beginning, so now there are 9 + 20 = 29 computers. The answer is 29.\n"),
dict(role="HUMAN", prompt="Q: Michael had 58 golf balls. On tuesday, he lost 23 golf balls. On wednesday, he lost 2 more. How many golf balls did he have at the end of wednesday?"),
dict(role="BOT", prompt="A: Michael initially had 58 balls. He lost 23 on Tuesday, so after that he has 58 - 23 = 35 balls. On Wednesday he lost 2 more so now he has 35 - 2 = 33 balls. The answer is 33.\n"),
dict(role="HUMAN", prompt="Q: Olivia has $23. She bought five bagels for $3 each. How much money does she have left?"),
dict(role="BOT", prompt="A: She bought 5 bagels for $3 each. This means she spent 5 * $3 = $15 on the bagels. She had $23 in beginning, so now she has $23 - $15 = $8. The answer is 8.\n"),
dict(role="HUMAN", prompt="Q: {question}"),
dict(role="BOT", prompt="A: {answer}\n"),
],
}
mathbench_sets = {
# Practice Part
"college": ["single_choice_cn", "single_choice_en"],
"high": ["single_choice_cn", "single_choice_en"],
"middle": ["single_choice_cn", "single_choice_en"],
"primary": ["cloze_cn", "cloze_en"],
"calculate": ["cloze_en"],
# Theory part
"college_knowledge": ["single_choice_cn", "single_choice_en"],
"high_knowledge": ["single_choice_cn", "single_choice_en"],
"middle_knowledge": ["single_choice_cn", "single_choice_en"],
"primary_knowledge": ["single_choice_cn", "single_choice_en"],
}
# Generate reasoning path or not, only for single choice
with_reasoning = True
# Use circular evaluation or not
with_circular_eval = False
mathbench_datasets = []
for _split in list(mathbench_sets.keys()):
for _name in mathbench_sets[_split]:
mathbench_reader_cfg = dict(
input_columns=["question"],
output_column="answer",
)
if "single_choice" in _name:
template_round = [
dict(role="HUMAN", prompt=(single_choice_prompts[_name + "_with_reasoning"] if with_reasoning else single_choice_prompts[_name])),
dict(role="BOT", prompt="{answer}")
]
else:
template_round = cloze_prompts[_name]
mathbench_infer_cfg = dict(
prompt_template=dict(type=PromptTemplate, template=dict(round=template_round)),
retriever=dict(type=ZeroRetriever),
inferencer=dict(type=GenInferencer, max_out_len=512),
)
if "single_choice" in _name:
pred_postprocessor = dict(type=first_option_postprocess, options="ABCD")
else:
pred_postprocessor = dict(type=mathbench_postprocess, name=_name)
if "single_choice" in _name and with_circular_eval:
evaluator = dict(type=CircularEvaluator)
else:
evaluator = dict(type=AccEvaluator)
mathbench_eval_cfg = dict(
evaluator=evaluator,
pred_postprocessor=pred_postprocessor,
)
mathbench_datasets.append(
dict(
abbr="mathbench-" + _split + "-" + _name,
type=MathBenchDataset,
path=f"./data/mathbench_v1_ori/{_split}",
name=_name,
with_circular=with_circular_eval,
reader_cfg=mathbench_reader_cfg,
infer_cfg=mathbench_infer_cfg,
eval_cfg=mathbench_eval_cfg,
)
)

View File

@ -8,7 +8,7 @@ with read_base():
from ..triviaqa.triviaqa_wiki_1shot_gen_20a989 import triviaqa_datasets from ..triviaqa.triviaqa_wiki_1shot_gen_20a989 import triviaqa_datasets
from ..nq.nq_open_1shot_gen_20a989 import nq_datasets from ..nq.nq_open_1shot_gen_20a989 import nq_datasets
from ..race.race_ppl_abed12 import race_datasets from ..race.race_ppl_abed12 import race_datasets
from ..winogrande.winogrande_5shot_ll_9d81d7 import winogrande_datasets from ..winogrande.winogrande_5shot_ll_252f01 import winogrande_datasets
from ..hellaswag.hellaswag_10shot_ppl_59c85e import hellaswag_datasets from ..hellaswag.hellaswag_10shot_ppl_59c85e import hellaswag_datasets
from ..bbh.bbh_gen_0a5495 import bbh_datasets from ..bbh.bbh_gen_0a5495 import bbh_datasets
from ..gsm8k.gsm8k_gen_ee684f import gsm8k_datasets from ..gsm8k.gsm8k_gen_ee684f import gsm8k_datasets

View File

@ -1,4 +1,4 @@
from mmengine.config import read_base from mmengine.config import read_base
with read_base(): with read_base():
from .gpqa_gen_a27c4d import gpqa_datasets from .gpqa_gen_4baadb import gpqa_datasets

View File

@ -13,7 +13,7 @@ gpqa_infer_cfg = dict(
type=PromptTemplate, type=PromptTemplate,
template=dict( template=dict(
round=[ round=[
dict(role='HUMAN', prompt='{question}\nChoices:\n' dict(role='HUMAN', prompt='What is the correct answer to this question: {question}\nChoices:\n'
'(A){A}\n' '(A){A}\n'
'(B){B}\n' '(B){B}\n'
'(C){C}\n' '(C){C}\n'
@ -28,8 +28,8 @@ gpqa_eval_cfg = dict(evaluator=dict(type=GPQAEvaluator),
gpqa_datasets = [] gpqa_datasets = []
gpqa_subsets = { gpqa_subsets = {
'extended': 'gpqa_extended.csv', # 'extended': 'gpqa_extended.csv',
'main': 'gpqa_main.csv', # 'main': 'gpqa_main.csv',
'diamond': 'gpqa_diamond.csv' 'diamond': 'gpqa_diamond.csv'
} }

View File

@ -0,0 +1,40 @@
from opencompass.openicl.icl_prompt_template import PromptTemplate
from opencompass.openicl.icl_retriever import ZeroRetriever
from opencompass.openicl.icl_inferencer import PPLInferencer
from opencompass.datasets import GPQADataset, GPQAEvaluator
from opencompass.utils import first_option_postprocess
gpqa_reader_cfg = dict(
input_columns=['question', 'A', 'B', 'C', 'D'],
output_column='answer')
gpqa_infer_cfg = dict(
prompt_template=dict(
type=PromptTemplate,
template={
opt: f'Question: {{question}}\n(A){{A}}\n(B){{B}}\n(C){{C}}\n(D){{D}}\nAnswer: {opt}' for opt in ['A', 'B', 'C', 'D']
}),
retriever=dict(type=ZeroRetriever),
inferencer=dict(type=PPLInferencer))
gpqa_eval_cfg = dict(evaluator=dict(type=GPQAEvaluator),
pred_postprocessor=dict(type=first_option_postprocess, options='ABCD'))
gpqa_datasets = []
gpqa_subsets = {
# 'extended': 'gpqa_extended.csv',
# 'main': 'gpqa_main.csv',
'diamond': 'gpqa_diamond.csv'
}
for split in list(gpqa_subsets.keys()):
gpqa_datasets.append(
dict(
abbr='GPQA_' + split,
type=GPQADataset,
path='./data/gpqa/',
name=gpqa_subsets[split],
reader_cfg=gpqa_reader_cfg,
infer_cfg=gpqa_infer_cfg,
eval_cfg=gpqa_eval_cfg)
)

View File

@ -15,11 +15,11 @@ question_and_options = "Which of the following is a good sentence:\nA. {opt1}\nB
winogrande_infer_cfg = dict( winogrande_infer_cfg = dict(
ice_template=dict( ice_template=dict(
type=PromptTemplate, type=PromptTemplate,
template={answer: f"{question_and_options}\nAnswer: {answer}\n" for answer in ["A", "B"]}, template={'A': '{opt1}', 'B': '{opt2}'},
), ),
prompt_template=dict( prompt_template=dict(
type=PromptTemplate, type=PromptTemplate,
template={answer: f"</E>{question_and_options}\nAnswer: {answer}" for answer in ["A", "B"]}, template={'A': '</E>{opt1}', 'B': '</E>{opt2}'},
ice_token="</E>", ice_token="</E>",
), ),
retriever=dict(type=FixKRetriever, fix_id_list=[0, 2, 4, 6, 8]), retriever=dict(type=FixKRetriever, fix_id_list=[0, 2, 4, 6, 8]),

View File

@ -0,0 +1,35 @@
from opencompass.models import HuggingFaceCausalLM
_meta_template = dict(
round=[
dict(role='HUMAN', begin='<|im_start|>user\n', end='<|im_end|>\n'),
dict(role='BOT', begin='<|im_start|>assistant\n', end='<|im_end|>\n', generate=True),
],
eos_token_id=92542
)
models = [
dict(
type=HuggingFaceCausalLM,
abbr='internlm2-chat-1.8b-hf',
path="internlm/internlm2-chat-1_8b",
tokenizer_path='internlm/internlm2-chat-1_8b',
model_kwargs=dict(
trust_remote_code=True,
device_map='auto',
),
tokenizer_kwargs=dict(
padding_side='left',
truncation_side='left',
use_fast=False,
trust_remote_code=True,
),
max_out_len=100,
max_seq_len=2048,
batch_size=8,
meta_template=_meta_template,
run_cfg=dict(num_gpus=1, num_procs=1),
end_str='<|im_end|>',
)
]

View File

@ -17,6 +17,15 @@ summarizer = dict(
['mathbench-high-single_choice_en', 'perf_4'], ['mathbench-high-single_choice_en', 'perf_4'],
['mathbench-middle-single_choice_cn', 'perf_4'], ['mathbench-middle-single_choice_cn', 'perf_4'],
['mathbench-middle-single_choice_en', 'perf_4'], ['mathbench-middle-single_choice_en', 'perf_4'],
'######## MathBench Knowledge ########', # category
['mathbench-college_knowledge-single_choice_cn', 'perf_4'],
['mathbench-college_knowledge-single_choice_en', 'perf_4'],
['mathbench-high_knowledge-single_choice_cn', 'perf_4'],
['mathbench-high_knowledge-single_choice_en', 'perf_4'],
['mathbench-middle_knowledge-single_choice_cn', 'perf_4'],
['mathbench-middle_knowledge-single_choice_en', 'perf_4'],
['mathbench-primary_knowledge-single_choice_cn', 'perf_4'],
['mathbench-primary_knowledge-single_choice_en', 'perf_4'],
], ],
summary_groups=sum( summary_groups=sum(
[v for k, v in locals().items() if k.endswith("_summary_groups")], []) [v for k, v in locals().items() if k.endswith("_summary_groups")], [])

View File

@ -0,0 +1,30 @@
from mmengine.config import read_base
with read_base():
from .groups.mmlu import mmlu_summary_groups
from .groups.ceval import ceval_summary_groups
from .groups.bbh import bbh_summary_groups
from .groups.GaokaoBench import GaokaoBench_summary_groups
from .groups.cmmlu import cmmlu_summary_groups
summarizer = dict(
dataset_abbrs=[
['mmlu', 'naive_average'],
['cmmlu', 'naive_average'],
['ceval-test', 'naive_average'],
['GaokaoBench', 'weighted_average'],
['triviaqa_wiki_1shot', 'score'],
['nq_open_1shot', 'score'],
['race-high', 'accuracy'],
['winogrande', 'accuracy'],
['hellaswag', 'accuracy'],
['bbh', 'naive_average'],
['gsm8k', 'accuracy'],
['math', 'accuracy'],
['TheoremQA', 'accuracy'],
['openai_humaneval', 'humaneval_pass@1'],
['sanitized_mbpp', 'score'],
],
summary_groups=sum(
[v for k, v in locals().items() if k.endswith("_summary_groups")], []),
)

View File

@ -1,4 +1,3 @@
import copy
import csv import csv
import os import os
@ -17,7 +16,6 @@ class GPQADataset(BaseDataset):
def load(path: str, name: str): def load(path: str, name: str):
cnt = 0 cnt = 0
data = [] data = []
data_new = []
with open(os.path.join(path, name), 'r', encoding='utf-8') as f: with open(os.path.join(path, name), 'r', encoding='utf-8') as f:
reader = csv.reader(f, delimiter=',') reader = csv.reader(f, delimiter=',')
for row in reader: for row in reader:
@ -25,38 +23,20 @@ class GPQADataset(BaseDataset):
continue continue
cnt = cnt + 1 cnt = cnt + 1
question = row[7] question = row[7]
A = row[8] # 第一个是正确选项
B = row[9]
C = row[10]
D = row[11]
options = [row[8], row[9], row[10], row[11]] options = [row[8], row[9], row[10], row[11]]
answer = 'A' shuffle_patterns = ['ABCD', 'BCDA', 'CDAB', 'DABC'] # 更新选项顺序
c = shuffle_patterns[cnt % 4]
data.append({ line = {'question': question}
'question': question, ground_truth = options[0]
'A': A,
'B': B,
'C': C,
'D': D,
'options': options,
'answer': answer
})
circular_patterns = ['ABCD', 'BCDA', 'CDAB', 'DABC'] # 更新选项顺序
c = circular_patterns[cnt % 4]
line = copy.deepcopy(data[cnt - 1])
tmp = line['A']
for i in range(4): for i in range(4):
line['ABCD'[i]] = line['options'][ord(c[i]) - ord('A')] line['ABCD'[i]] = options[ord(c[i]) - ord('A')]
for i in range(4): for i in range(4):
if line['ABCD'[i]] == tmp: if line['ABCD'[i]] == ground_truth:
line['answer'] = 'ABCD'[i] line['answer'] = 'ABCD'[i]
break break
data_new.append(line) data.append(line)
dataset = Dataset.from_list(data)
dataset = Dataset.from_list(data_new)
return dataset return dataset
@ -64,9 +44,7 @@ class GPQAEvaluator(BaseEvaluator):
def score(self, predictions, references): def score(self, predictions, references):
if len(predictions) != len(references): if len(predictions) != len(references):
return { return {'error': 'preds and refrs have different length'}
'error': 'predictions and references have different length'
}
correct = 0 correct = 0
count = 0 count = 0
details = [] details = []

View File

@ -213,15 +213,15 @@ class MBPPEvaluator(BaseEvaluator):
programs = self._process_test(refer, pred) programs = self._process_test(refer, pred)
future = executor.submit(execution, programs, i, 3) future = executor.submit(execution, programs, i, 3)
futures.append(future) futures.append(future)
details[str(i)] = {}
details[str(i)]['origin'] = predictions[i]
details[str(i)]['programs'] = programs
from tqdm import tqdm from tqdm import tqdm
for future in tqdm(as_completed(futures), total=len(futures)): for future in tqdm(as_completed(futures), total=len(futures)):
index, key = future.result() index, key = future.result()
result[key] += 1 result[key] += 1
details[str(index)] = { details[str(index)]['result'] = key
'programs': predictions[index],
'result': key
}
result['score'] = result['pass'] / len(predictions) * 100 result['score'] = result['pass'] / len(predictions) * 100
result['details'] = details result['details'] = details

View File

@ -239,6 +239,7 @@ class OpenAI(BaseAPIModel):
if 'error' in response: if 'error' in response:
if response['error']['code'] == 'rate_limit_exceeded': if response['error']['code'] == 'rate_limit_exceeded':
time.sleep(1) time.sleep(1)
self.logger.warn('Rate limit exceeded, retrying...')
continue continue
elif response['error']['code'] == 'insufficient_quota': elif response['error']['code'] == 'insufficient_quota':
self.invalid_keys.add(key) self.invalid_keys.add(key)