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 = """\ """ _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="hoge", ), ds.BuilderConfig( name="original", version=VERSION, description="hoge", ), ds.BuilderConfig( name="stress", version=VERSION, description="fuga", ), ds.BuilderConfig( name="stress_original", version=VERSION, description="fuga", ), ] 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"), "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 == "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): data_path = dl_manager.download_and_extract(_URLS[self.config.name]) df: pd.DataFrame = pd.read_table(data_path, sep="\t", header=0) 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", } ) 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 == "stress": 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", ] ] 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