-
Notifications
You must be signed in to change notification settings - Fork 435
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature] Add multi-prompt generation demo (#568)
* [Feature] Add multi-prompt generation demo * [Fix] change form in winogrande_gen_XXX.py * [Fix] make multi prompt demo more directly * [Fix] fix bug * [Fix] minor fix --------- Co-authored-by: yingfhu <[email protected]>
- Loading branch information
1 parent
91fba2c
commit 5e75e29
Showing
3 changed files
with
115 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
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 AccEvaluator | ||
from opencompass.datasets import winograndeDataset_V2 | ||
from opencompass.utils.text_postprocessors import first_option_postprocess | ||
|
||
winogrande_reader_cfg = dict( | ||
input_columns=["opt1", "opt2"], | ||
output_column="answer", | ||
) | ||
|
||
winogrande_eval_cfg = dict( | ||
evaluator=dict(type=AccEvaluator), | ||
pred_role="BOT", | ||
pred_postprocessor=dict(type=first_option_postprocess, options='AB'), | ||
) | ||
|
||
_winogrande_prompt = dict( | ||
prompt_1="Which of the following is a good sentence:\nA. {opt1}\nB. {opt2}\nAnswer:", | ||
prompt_2="Which is a good sentence out of the following:\nA. {opt1}\nB. {opt2}\nAnswer:", | ||
prompt_3="Can you identify a good sentence from the following:\nA. {opt1}\nB. {opt2}\nAnswer:", | ||
) | ||
|
||
winogrande_datasets = [] | ||
for _choice in _winogrande_prompt: | ||
winogrande_datasets.append( | ||
dict( | ||
abbr='winogrande_'+_choice, | ||
type=winograndeDataset_V2, | ||
path="./data/winogrande", | ||
reader_cfg=winogrande_reader_cfg, | ||
infer_cfg=dict( | ||
prompt_template=dict( | ||
type=PromptTemplate, | ||
template=dict(round=[ | ||
dict( | ||
role="HUMAN", | ||
prompt=_winogrande_prompt[_choice] | ||
), | ||
]), | ||
), | ||
retriever=dict(type=ZeroRetriever), | ||
inferencer=dict(type=GenInferencer), | ||
), | ||
eval_cfg=winogrande_eval_cfg), | ||
) | ||
|
||
del _choice |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from mmengine.config import read_base | ||
from opencompass.models import HuggingFaceCausalLM | ||
|
||
|
||
with read_base(): | ||
from .datasets.winogrande.winogrande_gen_a027b6 import winogrande_datasets | ||
|
||
datasets = [*winogrande_datasets] | ||
|
||
_meta_template = dict( | ||
round=[ | ||
dict(role='HUMAN', begin='<|User|>:', end='<eoh>\n'), | ||
dict(role='BOT', begin='<|Bot|>:', end='<eoa>\n', generate=True), | ||
], | ||
) | ||
|
||
models=[ | ||
dict( | ||
type=HuggingFaceCausalLM, | ||
abbr='internlm-chat-7b-hf', | ||
path="internlm/internlm-chat-7b", | ||
tokenizer_path='internlm/internlm-chat-7b', | ||
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, | ||
model_kwargs=dict( | ||
trust_remote_code=True, | ||
device_map='auto', | ||
), | ||
run_cfg=dict(num_gpus=1, num_procs=1), | ||
) | ||
] | ||
|
||
_winogrande_all = [d['abbr'] for d in winogrande_datasets] | ||
|
||
summarizer = dict( | ||
summary_groups=[ | ||
{'name': 'winogrande', 'subsets': _winogrande_all}, | ||
{'name': 'winogrande_std', 'subsets': _winogrande_all, 'std': True}, | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters