Skip to content

Commit

Permalink
Update kaoshi
Browse files Browse the repository at this point in the history
  • Loading branch information
liushz committed Sep 12, 2023
1 parent 29efd66 commit 757b24e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
2 changes: 1 addition & 1 deletion configs/datasets/Kaoshi/Kaoshi_gen_6666.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
prompts = {
"单选题" : "请你做一道单项选择题\n请你一步一步思考并将思考过程写在【解析】和<eoe>之间。你将从A,B,C,D中选出正确的答案,并写在【答案】和<eoa>之间,答案应只包含最终结果,不要添加额外词语。\n例如:【答案】: A <eoa>\n完整的题目回答的格式如下:\n【解析】 ... <eoe>\n【答案】 ... <eoa>\n请你严格按照上述格式作答。\n题目如下:",
"多选题" : "请你做一道多项选择题\n请你一步一步思考并将思考过程写在【解析】和<eoe>之间。你将从多个选项中选出正确的答案,答案可能是一个到多个选项,奇怪将其写在【答案】和<eoa>之间,答案应只包含最终结果,不要添加额外词语。\n例如:【答案】: A D <eoa>\n完整的题目回答的格式如下:\n【解析】 ... <eoe>\n【答案】 ... <eoa>\n请你严格按照上述格式作答。\n题目如下:",
"填空题" : "请解答下面的填空题\n仔细阅读题目,解答其中的问题,请你一步步思考并将思考过程写在【解析】和<eoe>之间。请把你的答案写在【答案】和<eoa>之间,答案应只包含最终结果,不要添加额外词语。\n完整的题目回答格式如下:\n【解析】 ...<eoe>\n【答案】...<eoa>\n请你严格按照上述格式作答。\n题目如下:",
"填空题" : "请解答下面的填空题\n仔细阅读题目,解答其中的问题,请你一步步思考并将思考过程写在【解析】和<eoe>之间。请把你的答案写在【答案】和<eoa>之间,答案应只包含最终结果,不要添加额外词语。\n完整的题目回答格式如下:\n【解析】 ... <eoe>\n【答案】... <eoa>\n请你严格按照上述格式作答。\n题目如下:",
"完形填空" : "请你做一道英语完形填空题,其中包含二十个小题。\n请你一步一步思考。每一题你将从A,B,C,D中选出正确的答案,并写在【答案】和<eoa>之间。\n例如:(1)【答案】 A <eoa>\n(2)【答案】 B <eoa>\n请你严格按照上述格式作答。\n",
"七选五": "请回答下面的问题,将符合题意的五个选项的字母写在【答案】和<eoa>之间,例如:【答案】 A B C D E <eoa>\n请严格按照上述格式作答。题目如下:\n",
"判断题" : "请回答下面的判断题,将你的判断结果写在【答案】和<eoa>之间,若给定表述正确时回答:\n【答案】正确 <eoa>\n 表述错误时回答:\n【答案】错误 <eoa>\n请严格按照上述格式作答。题目如下:\n",
Expand Down
22 changes: 9 additions & 13 deletions opencompass/datasets/Kaoshi.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ def load(path: str, name: str):
data_list.append(data)
return Dataset.from_list(data_list)


valid_kaoshi__question_types = [
'single_choice', 'multi_choice', 'multi_question_choice'
valid_kaoshi_question_types = [
'single_choice', 'multi_choice', 'multi_question_choice',
'five_out_of_seven', 'cloze', 'judgment'
]

Expand All @@ -45,7 +44,7 @@ class KaoshiEvaluator(BaseEvaluator):

def __init__(self, question_type) -> None:
super().__init__()
assert question_type in valid_kaoshi__question_types
assert question_type in valid_kaoshi_question_types
self.question_type = question_type

def do_predictions_postprocess(self, model_output, answer_lenth=None):
Expand Down Expand Up @@ -93,7 +92,7 @@ def do_predictions_postprocess(self, model_output, answer_lenth=None):
for k in range(min(5, len(temp))):
model_answer.append(temp[k])

elif self.question_type == 'judgment':
elif self.question_type in ['cloze', 'judgment']:
model_answer = []
temp = re.findall(r'【答案】(.*?) ', model_output)
if len(temp) > 0:
Expand All @@ -107,10 +106,7 @@ def ensure_same_length(self, pred, refr):
return ['Z'] * len(refr)

def score(self, predictions, references):
if self.question_type not in [
'single_choice', 'multi_choice', 'multi_question_choice',
'five_out_of_seven'
]:
if self.question_type not in valid_kaoshi_question_types:
return {'score': 0}
elif self.question_type == 'multi_choice':
correct_score, total_score = 0, 0
Expand All @@ -135,7 +131,7 @@ def score(self, predictions, references):
pred = self.do_predictions_postprocess(pred, len(refr))
else:
pred = self.do_predictions_postprocess(pred)
if self.question_type == 'judgment':
if self.question_type in ['cloze', 'judgment']:
refr = [refr]
pred = self.ensure_same_length(pred, refr)
for p, r in zip(pred, refr):
Expand All @@ -145,12 +141,12 @@ def score(self, predictions, references):
return {'score': correct_score / total_score * 100}


for question_type in valid_kaoshi__question_types:
for question_type in valid_kaoshi_question_types:
# fix classic closure problem
def _kaoshi_register(question_type):
ICL_EVALUATORS.register_module(
name='KaoshiEvaluator' + '_' + question_type,
name='KaoshiEvaluator' + "_" + question_type,
module=lambda *args, **kwargs: KaoshiEvaluator(
question_type=question_type, *args, **kwargs))

_kaoshi_register(question_type)
_kaoshi_register(question_type)

0 comments on commit 757b24e

Please sign in to comment.