Datasets:
Size:
10K - 100K
License:
import datasets as ds | |
import pandas as pd | |
_CITATION = """\ | |
@article{yanaka-mineshima-2022-compositional, | |
title = "Compositional Evaluation on {J}apanese Textual Entailment and Similarity", | |
author = "Yanaka, Hitomi and Mineshima, Koji", | |
journal = "Transactions of the Association for Computational Linguistics", | |
volume = "10", | |
year = "2022", | |
address = "Cambridge, MA", | |
publisher = "MIT Press", | |
url = "https://aclanthology.org/2022.tacl-1.73", | |
doi = "10.1162/tacl_a_00518", | |
pages = "1266--1284", | |
} | |
""" | |
_DESCRIPTION = """\ | |
Japanese Sentences Involving Compositional Knowledge (JSICK) Dataset. | |
JSICK is the Japanese NLI and STS dataset by manually translating the English dataset SICK (Marelli et al., 2014) into Japanese. | |
We hope that our dataset will be useful in research for realizing more advanced models that are capable of appropriately performing multilingual compositional inference. | |
(from official website) | |
""" | |
_HOMEPAGE = "https://github.com/verypluming/JSICK" | |
_LICENSE = "CC BY-SA 4.0" | |
_URLS = { | |
"base": "https://raw.githubusercontent.com/verypluming/JSICK/main/jsick/jsick.tsv", | |
"stress": "https://raw.githubusercontent.com/verypluming/JSICK/main/jsick-stress/jsick-stress-all-annotations.tsv", | |
} | |
class JSICKDataset(ds.GeneratorBasedBuilder): | |
VERSION = ds.Version("1.0.0") | |
DEFAULT_CONFIG_NAME = "base" | |
BUILDER_CONFIGS = [ | |
ds.BuilderConfig( | |
name="base", | |
version=VERSION, | |
description="A version adopting the column names of a typical NLI dataset.", | |
), | |
ds.BuilderConfig( | |
name="original", | |
version=VERSION, | |
description="The original version retaining the unaltered column names.", | |
), | |
ds.BuilderConfig( | |
name="stress", | |
version=VERSION, | |
description="The dataset to investigate whether models capture word order and case particles in Japanese.", | |
), | |
ds.BuilderConfig( | |
name="stress-original", | |
version=VERSION, | |
description="The original version of JSICK-stress Test set retaining the unaltered column names.", | |
), | |
] | |
def _info(self) -> ds.DatasetInfo: | |
labels = ds.ClassLabel(names=["entailment", "neutral", "contradiction"]) | |
if self.config.name == "base": | |
features = ds.Features( | |
{ | |
"id": ds.Value("int32"), | |
"premise": ds.Value("string"), | |
"hypothesis": ds.Value("string"), | |
"label": labels, | |
"score": ds.Value("float32"), | |
"premise_en": ds.Value("string"), | |
"hypothesis_en": ds.Value("string"), | |
"label_en": labels, | |
"score_en": ds.Value("float32"), | |
"corr_entailment_labelAB_En": ds.Value("string"), | |
"corr_entailment_labelBA_En": ds.Value("string"), | |
"image_ID": ds.Value("string"), | |
"original_caption": ds.Value("string"), | |
"semtag_short": ds.Value("string"), | |
"semtag_long": ds.Value("string"), | |
} | |
) | |
elif self.config.name == "original": | |
features = ds.Features( | |
{ | |
"pair_ID": ds.Value("int32"), | |
"sentence_A_Ja": ds.Value("string"), | |
"sentence_B_Ja": ds.Value("string"), | |
"entailment_label_Ja": labels, | |
"relatedness_score_Ja": ds.Value("float32"), | |
"sentence_A_En": ds.Value("string"), | |
"sentence_B_En": ds.Value("string"), | |
"entailment_label_En": labels, | |
"relatedness_score_En": ds.Value("float32"), | |
"corr_entailment_labelAB_En": ds.Value("string"), | |
"corr_entailment_labelBA_En": ds.Value("string"), | |
"image_ID": ds.Value("string"), | |
"original_caption": ds.Value("string"), | |
"semtag_short": ds.Value("string"), | |
"semtag_long": ds.Value("string"), | |
} | |
) | |
elif self.config.name == "stress": | |
features = ds.Features( | |
{ | |
"id": ds.Value("string"), | |
"premise": ds.Value("string"), | |
"hypothesis": ds.Value("string"), | |
"label": labels, | |
"score": ds.Value("float32"), | |
"sentence_A_Ja_origin": ds.Value("string"), | |
"entailment_label_origin": labels, | |
"relatedness_score_Ja_origin": ds.Value("float32"), | |
"rephrase_type": ds.Value("string"), | |
"case_particles": ds.Value("string"), | |
} | |
) | |
elif self.config.name == "stress-original": | |
features = ds.Features( | |
{ | |
"pair_ID": ds.Value("string"), | |
"sentence_A_Ja": ds.Value("string"), | |
"sentence_B_Ja": ds.Value("string"), | |
"entailment_label_Ja": labels, | |
"relatedness_score_Ja": ds.Value("float32"), | |
"sentence_A_Ja_origin": ds.Value("string"), | |
"entailment_label_origin": labels, | |
"relatedness_score_Ja_origin": ds.Value("float32"), | |
"rephrase_type": ds.Value("string"), | |
"case_particles": ds.Value("string"), | |
} | |
) | |
return ds.DatasetInfo( | |
description=_DESCRIPTION, | |
citation=_CITATION, | |
homepage=_HOMEPAGE, | |
license=_LICENSE, | |
features=features, | |
) | |
def _split_generators(self, dl_manager: ds.DownloadManager): | |
if self.config.name in ["base", "original"]: | |
url = _URLS["base"] | |
elif self.config.name in ["stress", "stress-original"]: | |
url = _URLS["stress"] | |
data_path = dl_manager.download_and_extract(url) | |
df: pd.DataFrame = pd.read_table(data_path, sep="\t", header=0) | |
if self.config.name in ["stress", "stress-original"]: | |
df = df[ | |
[ | |
"pair_ID", | |
"sentence_A_Ja", | |
"sentence_B_Ja", | |
"entailment_label_Ja", | |
"relatedness_score_Ja", | |
"sentence_A_Ja_origin", | |
"entailment_label_origin", | |
"relatedness_score_Ja_origin", | |
"rephrase_type", | |
"case_particles", | |
] | |
] | |
if self.config.name in ["base", "stress"]: | |
df = df.rename( | |
columns={ | |
"pair_ID": "id", | |
"sentence_A_Ja": "premise", | |
"sentence_B_Ja": "hypothesis", | |
"entailment_label_Ja": "label", | |
"relatedness_score_Ja": "score", | |
"sentence_A_En": "premise_en", | |
"sentence_B_En": "hypothesis_en", | |
"entailment_label_En": "label_en", | |
"relatedness_score_En": "score_en", | |
} | |
) | |
if self.config.name in ["base", "original"]: | |
return [ | |
ds.SplitGenerator( | |
name=ds.Split.TRAIN, | |
gen_kwargs={"df": df[df["data"] == "train"].drop("data", axis=1)}, | |
), | |
ds.SplitGenerator( | |
name=ds.Split.TEST, | |
gen_kwargs={"df": df[df["data"] == "test"].drop("data", axis=1)}, | |
), | |
] | |
elif self.config.name in ["stress", "stress-original"]: | |
return [ | |
ds.SplitGenerator( | |
name=ds.Split.TEST, | |
gen_kwargs={"df": df}, | |
), | |
] | |
def _generate_examples(self, df: pd.DataFrame): | |
for i, row in enumerate(df.to_dict("records")): | |
yield i, row | |