|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""LogiQA dataset.""" |
|
|
|
import datasets |
|
import json |
|
import ast |
|
import csv |
|
|
|
_CITATION = """\ |
|
@ARTICLE{10174688, |
|
author={Liu, Hanmeng and Liu, Jian and Cui, Leyang and Teng, Zhiyang and Duan, Nan and Zhou, Ming and Zhang, Yue}, |
|
journal={IEEE/ACM Transactions on Audio, Speech, and Language Processing}, |
|
title={LogiQA 2.0 — An Improved Dataset for Logical Reasoning in Natural Language Understanding}, |
|
year={2023}, |
|
volume={}, |
|
number={}, |
|
pages={1-16}, |
|
doi={10.1109/TASLP.2023.3293046}} |
|
""" |
|
|
|
_DESCRIPTION = """\ |
|
The dataset is an amendment and re-annotation of LogiQA in 2020, a large-scale logical reasoning reading comprehension dataset adapted from the Chinese Civil Service Examination. We increase the data size, refine the texts with manual translation by professionals, and improve the quality by removing items with distinctive cultural features like Chinese idioms. Furthermore, we conduct a fine-grained annotation on the dataset and turn it into a two-way natural language inference (NLI) task, resulting in 35k premise-hypothesis pairs with gold labels, making it the first large-scale NLI dataset for complex logical reasoning |
|
""" |
|
|
|
_HOMEPAGE = "https://github.com/csitfun/LogiQA2.0/tree/main" |
|
|
|
_LICENSE = ( |
|
"Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License" |
|
) |
|
HEAD= 'https://raw.githubusercontent.com/microsoft/AGIEval/main/data/v1/' |
|
|
|
_URLS = { |
|
"sat_en": { |
|
"test": HEAD+'sat-en.jsonl', |
|
}, |
|
"sat_math": { |
|
"test": HEAD+'sat-math.jsonl' |
|
}, |
|
"lsat_ar": { |
|
"test": HEAD+'lsat-ar.jsonl' |
|
}, |
|
"lsat_lr": { |
|
"test": HEAD+'lsat-lr.jsonl' |
|
}, |
|
"lsat_rc": { |
|
"test": HEAD+'lsat-rc.jsonl' |
|
}, |
|
"logiqa": { |
|
"test": HEAD+'logiqa-en.jsonl' |
|
}, |
|
"aqua_rat": { |
|
"test": HEAD+'aqua-rat.jsonl' |
|
}, |
|
'math_agieval': { |
|
"test": HEAD+'math.jsonl' |
|
}, |
|
'few_shot': { |
|
'few_shot': HEAD+'https://raw.githubusercontent.com/microsoft/AGIEval/main/data/few_shot_prompts.csv' |
|
} |
|
|
|
} |
|
|
|
|
|
class AgiEval(datasets.GeneratorBasedBuilder): |
|
"""TODO: Short description of my dataset.""" |
|
|
|
VERSION = datasets.Version("2.0.0") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BUILDER_CONFIGS = [ |
|
datasets.BuilderConfig( |
|
name="aqua_rat", |
|
version=VERSION, |
|
description="", |
|
), |
|
datasets.BuilderConfig( |
|
name="sat_en", |
|
version=VERSION, |
|
description="", |
|
), |
|
datasets.BuilderConfig( |
|
name="sat_math", |
|
version=VERSION, |
|
description="", |
|
), |
|
datasets.BuilderConfig( |
|
name="lsat_ar", |
|
version=VERSION, |
|
description="", |
|
), |
|
datasets.BuilderConfig( |
|
name="lsat_lr", |
|
version=VERSION, |
|
description="", |
|
), |
|
datasets.BuilderConfig( |
|
name="lsat_rc", |
|
version=VERSION, |
|
description="", |
|
), |
|
datasets.BuilderConfig( |
|
name="logiqa", |
|
version=VERSION, |
|
description="", |
|
), |
|
datasets.BuilderConfig( |
|
name="math_agieval", |
|
version=VERSION, |
|
description="", |
|
), |
|
] |
|
DEFAULT_CONFIG_NAME = "aqua_rat" |
|
|
|
def _info(self): |
|
|
|
if self.config.name == "aqua_rat": |
|
features = datasets.Features( |
|
{ |
|
"question": datasets.Value("string"), |
|
"options": datasets.features.Sequence(datasets.Value("string")), |
|
"label": datasets.ClassLabel(num_classes=5, names=["A", "B", "C", "D", "E"]), |
|
"solution": datasets.Value("string"), |
|
} |
|
) |
|
elif self.config.name == "sat_en": |
|
features = datasets.Features( |
|
{"passage": datasets.Value("string"), |
|
"question": datasets.Value("string"), |
|
"options": datasets.features.Sequence(datasets.Value("string")), |
|
"label": datasets.ClassLabel(num_classes=4, names=["A", "B", "C", "D"]), |
|
"solution": datasets.Value("string"), |
|
} |
|
) |
|
elif self.config.name == "sat_math": |
|
|
|
features = datasets.Features( |
|
{"question": datasets.Value("string"), |
|
"options": datasets.features.Sequence(datasets.Value("string")), |
|
"label": datasets.ClassLabel(num_classes=4, names=["A", "B", "C", "D"]), |
|
"solution": datasets.Value("string"), |
|
} |
|
) |
|
elif self.config.name == "logiqa": |
|
|
|
features = datasets.Features( |
|
{"passage": datasets.Value("string"), |
|
"question": datasets.Value("string"), |
|
"options": datasets.features.Sequence(datasets.Value("string")), |
|
"label": datasets.ClassLabel(num_classes=4, names=["A", "B", "C", "D"]), |
|
} |
|
) |
|
elif self.config.name == "math_agieval": |
|
features = datasets.Features( |
|
{"question": datasets.Value("string"), |
|
"answer": datasets.Value("string"), |
|
"solution": datasets.Value("string"), |
|
"level": datasets.Value("int32"), |
|
"type": datasets.Value("string"), |
|
} |
|
) |
|
elif self.config.name in ['lsat_lr', 'lsat_rc', 'lsat_ar']: |
|
features = datasets.Features( |
|
{"question": datasets.Value("string"), |
|
"options": datasets.features.Sequence(datasets.Value("string")), |
|
"label": datasets.ClassLabel(num_classes=5, names=["A", "B", "C", "D", "E"]), |
|
} |
|
) |
|
|
|
|
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=features, |
|
homepage=_HOMEPAGE, |
|
license=_LICENSE, |
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
_urls = _URLS[self.config.name] |
|
urls = { |
|
"test": _urls["test"], |
|
"few_shot": _URLS["few_shot"]["few_shot"], |
|
} |
|
data_dir = dl_manager.download_and_extract(urls) |
|
splits = [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TEST, |
|
gen_kwargs={"filepath": data_dir["test"], "split": "test"}, |
|
), |
|
] |
|
splits.append(datasets.SplitGenerator( |
|
name="few_shot", |
|
gen_kwargs={"filepath": data_dir["few_shot"], "split": "few_shot"}, |
|
)) |
|
|
|
return splits |
|
|
|
def _generate_examples(self, filepath, split): |
|
if split == "few_shot": |
|
with open(filepath, mode="r", encoding="utf-8") as csv_file: |
|
reader = csv.DictReader(csv_file) |
|
|
|
|
|
for key, row in enumerate(reader): |
|
data_str = row[self.config.name] |
|
|
|
|
|
if pd.isnull(data_str): |
|
continue |
|
|
|
|
|
data = json.loads(data_str.replace("'", "\"")) |
|
|
|
|
|
if self.config.name in ["aqua_rat", "sat_math", "sat_en"]: |
|
yield key, { |
|
"question": data["question"], |
|
"options": data["options"], |
|
"label": data.get("label", None), |
|
"solution": data.get("solution", None) |
|
} |
|
else: |
|
with open(filepath, encoding="utf-8") as f: |
|
for key, row in enumerate(f): |
|
data = json.loads(row) |
|
|
|
if self.config.name in ["aqua_rat","sat_math"]: |
|
yield key, { |
|
"question": data["question"], |
|
"options": data["options"], |
|
"label": data["label"], |
|
"solution": data["other"]["solution"], |
|
} |
|
elif self.config.name == "logiqa": |
|
yield key, { |
|
"passage": data["passage"], |
|
"question": data["question"], |
|
"options": data["options"], |
|
"label": data["label"], |
|
} |
|
elif self.config.name == "math_agieval": |
|
if not data.get("level"): |
|
data["level"] = data['other']['level'] |
|
if not data.get("type"): |
|
data["type"] = data['other']['type'] |
|
yield key, { |
|
"question": data["question"], |
|
"answer": data["answer"], |
|
"solution": data["other"]["solution"], |
|
"level": data["level"], |
|
"type": data["type"] |
|
} |
|
|
|
elif self.config.name == "sat_en": |
|
yield key, { |
|
"passage": data["passage"], |
|
"question": data["question"], |
|
"options": data["options"], |
|
"label": data["label"], |
|
"solution": data["other"]["solution"], |
|
} |
|
elif self.config.name in ['lsat_lr', 'lsat_rc', 'lsat_ar']: |
|
yield key, { |
|
"question": data["question"], |
|
"options": data["options"], |
|
"label": data["label"], |
|
} |
|
|
|
|