ku-te / ku-te.py
hpprc's picture
:sparkles: Add 3way-strict
d3d716b
from typing import Dict
import datasets as ds
import pandas as pd
_CITATION = """\
@inproceedings{,
author = "小谷通隆 and 柴田知秀 and 中田貴之 and 黒橋禎夫",
title = "日本語Textual Entailmentのデータ構築と自動獲得した類義表現に基づく推論関係の認識",
booktitle = "言語処理学会第14回年次大会",
year = "2008",
url = "https://nlp.ist.i.kyoto-u.ac.jp/?Textual+Entailment+%E8%A9%95%E4%BE%A1%E3%83%87%E3%83%BC%E3%82%BF",
pages = "1140-1143"
}
"""
_DESCRIPTION = """\
"""
_HOMEPAGE = "https://nlp.ist.i.kyoto-u.ac.jp/?Textual+Entailment+%E8%A9%95%E4%BE%A1%E3%83%87%E3%83%BC%E3%82%BF"
_LICENSE = "unknown"
_URL = "http://nlp.ist.i.kyoto-u.ac.jp/DLcounter/lime.cgi?down=http://nlp.ist.i.kyoto-u.ac.jp/nl-resource/rte/entail_evaluation_set.txt&name=entail_evaluation_set.txt"
class KUTEDataset(ds.GeneratorBasedBuilder):
VERSION = ds.Version("1.0.0")
DEFAULT_CONFIG_NAME = "3way"
BUILDER_CONFIGS = [
ds.BuilderConfig(
name="original",
version=VERSION,
description="hoge",
),
ds.BuilderConfig(
name="3way",
version=VERSION,
description="fuga",
),
ds.BuilderConfig(
name="3way-strict",
version=VERSION,
description="fuga",
),
ds.BuilderConfig(
name="2way",
version=VERSION,
description="fuga",
),
]
def _info(self) -> ds.DatasetInfo:
if self.config.name == "original":
labels = ds.ClassLabel(names=["◎", "○", "△", "×"])
elif self.config.name in ["3way", "3way-strict"]:
labels = ds.ClassLabel(names=["entailment", "neutral", "contradiction"])
elif self.config.name == "2way":
labels = ds.ClassLabel(names=["entailment", "non-entailment"])
features = ds.Features(
{
"id": ds.Value("int32"),
"premise": ds.Value("string"),
"hypothesis": ds.Value("string"),
"label": labels,
"category_subcategory": ds.Value("string"),
}
)
return ds.DatasetInfo(
description=_DESCRIPTION,
citation=_CITATION,
homepage=_HOMEPAGE,
license=_LICENSE,
features=features,
)
def _split_generators(self, dl_manager: ds.DownloadManager):
data_path = dl_manager.download_and_extract(_URL)
df: pd.DataFrame = pd.read_table(data_path, sep=" ", header=None)
df.columns = ["id", "category_subcategory", "label", "premise", "hypothesis"]
if self.config.name == "original":
mapping = None
elif self.config.name == "3way":
mapping = {
"◎": "entailment",
"○": "entailment",
"△": "neutral",
"×": "contradiction",
}
elif self.config.name == "3way-strict":
mapping = {
"◎": "entailment",
"○": None,
"△": "neutral",
"×": "contradiction",
}
elif self.config.name == "2way":
mapping = {
"◎": "entailment",
"○": "entailment",
"△": "non-entailment",
"×": "non-entailment",
}
return [
ds.SplitGenerator(
name=ds.Split.TEST,
gen_kwargs={"df": df, "mapping": mapping},
),
]
def _generate_examples(self, df: pd.DataFrame, mapping: Dict[str, str] = None):
data = []
for row in df.to_dict("records"):
if mapping is not None:
row["label"] = mapping[row["label"]]
if row["label"] is None:
continue
data.append(row)
for i, row in enumerate(data):
yield i, row