Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SIG] add LogiQA dataset #516

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions configs/datasets/LogiQA/LogiQA_en_ppl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from mmengine.config import read_base

with read_base():
from .LogiQA_en_ppl_20dfb3 import LogiQA_en_datasets # noqa: F401, F403
48 changes: 48 additions & 0 deletions configs/datasets/LogiQA/LogiQA_en_ppl_20dfb3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from opencompass.openicl.icl_prompt_template import PromptTemplate
from opencompass.openicl.icl_retriever import FixKRetriever
from opencompass.openicl.icl_inferencer import PPLInferencer
from opencompass.openicl.icl_evaluator import AccEvaluator
from opencompass.datasets import LogiQADataset


_hint = "The following are logical reasoning questions from the Chinese National " \
"Civil Service Examination. Please choose the correct answer.\n"
LogiQA_en_infer_cfg = dict(
ice_template=dict(
type=PromptTemplate,
template="Context: {context}\nQuery: {query}\nA. {A}\nB. {B}\nC. {C}\nD. {D}\nAnswer: {correct_option}",
),
prompt_template=dict(
type=PromptTemplate,
template={
answer:
f"{_hint}</E>Context: {{context}}\nQuery: {{query}}\nA. {{A}}\nB. {{B}}\nC. {{C}}\nD. {{D}}\nAnswer: {answer}"
for answer in ['A', 'B', 'C', 'D']
},
ice_token='</E>',
),
retriever=dict(type=FixKRetriever, fix_id_list=[0, 1, 2, 3, 4]),
inferencer=dict(type=PPLInferencer))

LogiQA_en_eval_cfg = dict(evaluator=dict(type=AccEvaluator), )


LogiQA_en_datasets = []
for _split in ["validation", "test"]:

LogiQA_en_reader_cfg = dict(
input_columns=['context', 'query', 'A', 'B', 'C', 'D'],
output_column='correct_option',
test_split=_split
)

LogiQA_en_datasets.append(
dict(
abbr=f'LogiQA_en-{_split}',
type=LogiQADataset,
path='lucasmccabe/logiqa',
reader_cfg=LogiQA_en_reader_cfg,
infer_cfg=LogiQA_en_infer_cfg,
eval_cfg=LogiQA_en_eval_cfg
)
)
4 changes: 4 additions & 0 deletions configs/datasets/LogiQA/LogiQA_zh_ppl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from mmengine.config import read_base

with read_base():
from .LogiQA_zh_ppl_19fd62 import LogiQA_zh_datasets # noqa: F401, F403
47 changes: 47 additions & 0 deletions configs/datasets/LogiQA/LogiQA_zh_ppl_19fd62.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from opencompass.openicl.icl_prompt_template import PromptTemplate
from opencompass.openicl.icl_retriever import FixKRetriever
from opencompass.openicl.icl_inferencer import PPLInferencer
from opencompass.openicl.icl_evaluator import AccEvaluator
from opencompass.datasets import LogiQADataset


_hint = "以下是中国国家公务员考试的逻辑推理题,请选出其中的正确答案。\n"
LogiQA_zh_infer_cfg = dict(
ice_template=dict(
type=PromptTemplate,
template="上下文信息: {context}\n提问: {query}\nA. {A}\nB. {B}\nC. {C}\nD. {D}\n答案: {correct_option}",
),
prompt_template=dict(
type=PromptTemplate,
template={
answer:
f"{_hint}</E>上下文信息: {{context}}\n提问: {{query}}\nA. {{A}}\nB. {{B}}\nC. {{C}}\nD. {{D}}\n答案: {answer}"
for answer in ['A', 'B', 'C', 'D']
},
ice_token='</E>',
),
retriever=dict(type=FixKRetriever, fix_id_list=[0, 1, 2, 3, 4]),
inferencer=dict(type=PPLInferencer))

LogiQA_zh_eval_cfg = dict(evaluator=dict(type=AccEvaluator), )


LogiQA_zh_datasets = []
for _split in ["validation", "test"]:

LogiQA_zh_reader_cfg = dict(
input_columns=['context', 'query', 'A', 'B', 'C', 'D'],
output_column='correct_option',
test_split=_split
)

LogiQA_zh_datasets.append(
dict(
abbr=f'LogiQA_zh-{_split}',
type=LogiQADataset,
path='jiacheng-ye/logiqa-zh',
reader_cfg=LogiQA_zh_reader_cfg,
infer_cfg=LogiQA_zh_infer_cfg,
eval_cfg=LogiQA_zh_eval_cfg
)
)
1 change: 1 addition & 0 deletions opencompass/datasets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
from .lawbench import * # noqa: F401, F403
from .lcsts import * # noqa: F401, F403
from .leval import * # noqa: F401, F403
from .logiqa import * # noqa: F401, F403
from .longbench import * # noqa: F401, F403
from .math import * # noqa: F401, F403
from .mathbench import * # noqa: F401, F403
Expand Down
25 changes: 25 additions & 0 deletions opencompass/datasets/logiqa.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from datasets import load_dataset

from opencompass.registry import LOAD_DATASET

from .base import BaseDataset


@LOAD_DATASET.register_module()
class LogiQADataset(BaseDataset):

@staticmethod
def load(path: str):
dataset = load_dataset(path=path)

def preprocess(example):
options = example.pop('options')
example['A'] = options[0]
example['B'] = options[1]
example['C'] = options[2]
example['D'] = options[3]
example['correct_option'] = chr(65 + example['correct_option'])
return example

dataset = dataset.map(preprocess)
return dataset