Skip to content

Commit

Permalink
[SIG] add LogiQA dataset
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinNuNu committed Oct 27, 2023
1 parent 46e7ede commit 60335f7
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 0 deletions.
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 @@ -43,6 +43,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

0 comments on commit 60335f7

Please sign in to comment.