update HuMatchingFIB

This commit is contained in:
wujiang 2025-02-02 14:46:39 +08:00 committed by jxd
parent 273e609b53
commit 2abf6ca795
4 changed files with 86 additions and 65 deletions

View File

@ -0,0 +1,13 @@
from mmengine.config import read_base
with read_base():
from opencompass.configs.datasets.OpenHuEval.HuStandardFIB.HuStandardFIB import hu_standard_fib_datasets
from opencompass.configs.models.openai.gpt_4o_mini_20240718 import models as gpt_4o_mini_20240718_model
from opencompass.configs.models.qwen2_5.lmdeploy_qwen2_5_7b_instruct import models as lmdeploy_qwen2_5_7b_instruct_model
from opencompass.configs.models.hf_internlm.lmdeploy_internlm3_8b_instruct import models as lmdeploy_internlm3_8b_instruct_model
# from opencompass.configs.models.qwq.lmdeploy_qwq_32b_preview import models as lmdeploy_qwq_32b_preview_model
datasets = hu_standard_fib_datasets
models = sum([v for k, v in locals().items() if k.endswith('_model')], [])
work_dir = './outputs/' + __file__.split('/')[-1].split('.')[0] + '/' # do NOT modify this line, yapf: disable, pylint: disable

View File

@ -3,48 +3,42 @@ from mmengine.config import read_base
from opencompass.openicl.icl_prompt_template import PromptTemplate from opencompass.openicl.icl_prompt_template import PromptTemplate
from opencompass.openicl.icl_retriever import ZeroRetriever from opencompass.openicl.icl_retriever import ZeroRetriever
from opencompass.openicl.icl_inferencer import GenInferencer from opencompass.openicl.icl_inferencer import GenInferencer
from opencompass.datasets.OpenHuEval.HuStandardFIB import HuStandardFIBDataset, HuStandardFIBEvaluator from opencompass.datasets.OpenHuEval.HuStandardFIB import HuStandardFIBDataset, HuStandardFIBEvaluator
with read_base(): with read_base():
from .HuStandardFIB_setting import INSTRUCTIONS, DATASET_PATH from .HuStandardFIB_setting import INSTRUCTION, DATA_PATH, DATA_VERSION
ALL_LANGUAGES = ['hu'] instruction = INSTRUCTION['prompt_template']
PROMPT_VERSION = INSTRUCTIONS['version'] prompt_version = INSTRUCTION['version']
FIB2_reader_cfg = dict(input_columns=['question', 'subject'], hu_standard_fib_reader_cfg = dict(input_columns=['question', 'subject'],
output_column='reference') output_column='reference')
FIB2_datasets = [] hu_standard_fib_datasets = []
for lan in ALL_LANGUAGES:
instruction = INSTRUCTIONS[lan] hu_standard_fib_infer_cfg = dict(
FIB2_infer_cfg = dict( prompt_template=dict(
prompt_template=dict( type=PromptTemplate,
type=PromptTemplate, template=dict(
template=dict( begin='</E>',
begin='</E>', round=[
round=[ dict(role='HUMAN', prompt=instruction),
dict( ],
role='HUMAN',
prompt=instruction
),
],
),
ice_token='</E>',
), ),
retriever=dict(type=ZeroRetriever), ice_token='</E>',
inferencer=dict(type=GenInferencer), ),
) retriever=dict(type=ZeroRetriever),
inferencer=dict(type=GenInferencer),
)
FIB2_eval_cfg = dict(evaluator=dict(type=HuStandardFIBEvaluator)) hu_standard_fib_eval_cfg = dict(evaluator=dict(type=HuStandardFIBEvaluator))
FIB2_datasets.append( hu_standard_fib_datasets.append(
dict( dict(
abbr=f'HuStandardFIB-{lan}-1shot-{PROMPT_VERSION}', abbr=f'hu_standard_fib_{DATA_VERSION}-prompt_{prompt_version}',
type=HuStandardFIBDataset, type=HuStandardFIBDataset,
path=DATASET_PATH, filepath=DATA_PATH,
lan=lan, reader_cfg=hu_standard_fib_reader_cfg,
reader_cfg=FIB2_reader_cfg, infer_cfg=hu_standard_fib_infer_cfg,
infer_cfg=FIB2_infer_cfg, eval_cfg=hu_standard_fib_eval_cfg,
eval_cfg=FIB2_eval_cfg, ))
)
)

View File

@ -1,15 +1,27 @@
INSTRUCTIONS = { INSTRUCTION = {
'hu': """The following question is in hungarian language on {subject}, please read the question, and try to fill in the blank in the sub question list. Please organize the answer in a list. An example: 'prompt_template':
{ """The following questions are in Hungarian language on {hu_specific_dim}, please read the questions, and try to fill in the blanks in the question list. Please organize the answer in a list. An example:
"q_main": "Írd be a megfelelő meghatározás mellé a fogalmat!", {
"q_sub": ["A.A szerzetesi közösségek szabályzatának elnevezése latinul: #0#", "B.Az első ún. kolduló rend: #1#", "C.A szerzetesek által kézzel másolt mű: #2#", "D.Papi nőtlenség: #3#", "E.A pápát megválasztó egyházi méltóságok: #4#", "F.A bencés rend megújítása ebben a kolostorban kezdődött a 10. században: #5#"], "instruction": "Írd be a megfelelő meghatározás mellé a fogalmat!",
"formatted_std_ans": ["#0#regula", "#1#ferencesrend;ferences", "#2#kódex", "#3#cölibátus", "#4#bíborosok;bíboros", "#5#Cluny"] "questions": ["A.A szerzetesi közösségek szabályzatának elnevezése latinul: #0#", "B.Az első ún. kolduló rend: #1#", "C.A szerzetesek által kézzel másolt mű: #2#", "D.Papi nőtlenség: #3#", "E.A pápát megválasztó egyházi méltóságok: #4#", "F.A bencés rend megújítása ebben a kolostorban kezdődött a 10. században: #5#"],
} }
Now try to answer the following question, your response should be in a JSON format. Contain the std_ans like the case given above. The answers are:
The question is: {question}. {
""", "answers": ["#0#regula", "#1#ferencesrend", "#2#kódex", "#3#cölibátus", "#4#bíborosok", "#5#Cluny"]
'version':'V1', }
'description': 'Initial version, using 1shot, incontext, #0# as place holder, output in JSON format', Now try to answer the following questions, your response should be in a JSON format. Contain the "answers" like the case given above.
The questions are:
{
"instruction": {instruction},
"questions": {questions},
}
""",
'version':
'V1',
'description':
'Initial version, using 1shot, incontext, #0# as place holder, output in JSON format',
} }
DATASET_PATH = "/mnt/hwfile/opendatalab/weixingjian/test/test2/" OpenHuEval_Path = '/mnt/hwfile/opendatalab/wj/proj/polyglot_24July/OpenHuEval'
DATA_VERSION = '250126'
DATA_PATH = f'{OpenHuEval_Path}/data/HuStandardFIB/HuStandardFIB_{DATA_VERSION}/HuStandardFIB.jsonl'

View File

@ -4,21 +4,20 @@ import re
from datasets import Dataset, DatasetDict from datasets import Dataset, DatasetDict
from fuzzywuzzy import fuzz from fuzzywuzzy import fuzz
from opencompass.openicl.icl_evaluator import BaseEvaluator from opencompass.openicl.icl_evaluator import BaseEvaluator
from ..base import BaseDataset from ..base import BaseDataset
class HuStandardFIBDataset(BaseDataset): class HuStandardFIBDataset(BaseDataset):
@staticmethod @staticmethod
def load(**kwargs): def load(filepath):
path = kwargs.get('path', None) assert os.path.isfile(filepath)
# lan = kwargs.get('lan', None) assert filepath.endswith('.jsonl')
dataset = DatasetDict() dataset = DatasetDict()
file_list = [os.path.join(path, file) for file in os.listdir(path) f = open(filepath, 'r', encoding='utf-8')
] # TODO only work for a single split.
f_path = file_list[0]
f = open(f_path, 'r', encoding='utf-8')
lines = f.readlines() lines = f.readlines()
objs = [] objs = []
@ -29,11 +28,15 @@ class HuStandardFIBDataset(BaseDataset):
out_dict_list = [] out_dict_list = []
for obj in objs: for obj in objs:
question = dict(q_main=obj['q_main'], instruction = obj['question'] # TODO: question -> instruction
q_sub=obj['formatted_q_sub']) # TODO questions = obj[
subject = obj['major'] 'question_sub'] # TODO: update question_sub -> questions
hu_specific_dim = obj['hu_specific_dim']
tmp = obj tmp = obj
new_obj = dict(question=question, subject=subject, reference=tmp) new_obj = dict(instruction=instruction,
questions=questions,
hu_specific_dim=hu_specific_dim,
reference=tmp)
out_dict_list.append(new_obj) out_dict_list.append(new_obj)
dataset = Dataset.from_list(out_dict_list) dataset = Dataset.from_list(out_dict_list)
return dataset return dataset
@ -55,9 +58,8 @@ class HuStandardFIBEvaluator(BaseEvaluator):
zip(predictions, references, origin_prompt)): zip(predictions, references, origin_prompt)):
std_ans = [ std_ans = [
re.sub(r'#\d+#', '', ans).split(';') re.sub(r'#\d+#', '', ans).split(';')
for ans in refer['formatted_std_ans'] for ans in refer['answer'] # TODO: answer -> answers
] # Remove "#0#" and "#1#", then split ] # Remove "#0#" and "#1#", then split refer['formatted_std_ans']
# refer['formatted_std_ans']
model_ans = [] model_ans = []
pred = pred.strip() pred = pred.strip()
match = re.search(r'\{.*?\}', pred, re.DOTALL) match = re.search(r'\{.*?\}', pred, re.DOTALL)
@ -99,7 +101,7 @@ class HuStandardFIBEvaluator(BaseEvaluator):
if to_end_flag: if to_end_flag:
model_ans = [ model_ans = [
re.sub(r'#\d+#', '', ans).split(';') re.sub(r'#\d+#', '', ans).split(';')
for ans in data.get('formatted_std_ans', []) for ans in data.get('answers', [])
] # Preprocess model_ans in the same way as std_ans ] # Preprocess model_ans in the same way as std_ans
is_question_correct = True is_question_correct = True
for idx, ans_list in enumerate(std_ans): for idx, ans_list in enumerate(std_ans):