Datasets:
mteb
/

Modalities:
Text
Formats:
parquet
ArXiv:
Libraries:
Datasets
pandas
lewtun HF staff commited on
Commit
f3e7b4b
1 Parent(s): 2a95089

Add dataset loading script and infos

Browse files
Files changed (2) hide show
  1. amazon_counterfactual.py +118 -0
  2. dataset_infos.json +1 -0
amazon_counterfactual.py ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ """Amazon Multilingual Counterfactual Dataset"""
16
+
17
+
18
+ import csv
19
+
20
+ import datasets
21
+
22
+ _CITATION = """\
23
+ @misc{oneill2021i,
24
+ title={I Wish I Would Have Loved This One, But I Didn't -- A Multilingual Dataset for Counterfactual Detection in Product Reviews},
25
+ author={James O'Neill and Polina Rozenshtein and Ryuichi Kiryo and Motoko Kubota and Danushka Bollegala},
26
+ year={2021},
27
+ eprint={2104.06893},
28
+ archivePrefix={arXiv},
29
+ primaryClass={cs.CL}
30
+ }
31
+ """
32
+
33
+ _DESCRIPTION = """\
34
+ The dataset contains sentences from Amazon customer reviews (sampled from Amazon product review dataset) annotated for counterfactual detection (CFD) binary classification. Counterfactual statements describe events that did not or cannot take place. Counterfactual statements may be identified as statements of the form – If p was true, then q would be true (i.e. assertions whose antecedent (p) and consequent (q) are known or assumed to be false).
35
+ """
36
+
37
+ _HOMEPAGE_URL = "https://github.com/amazon-research/amazon-multilingual-counterfactual-dataset"
38
+ _LICENSE = "CC BY-SA 4.0"
39
+ _LANGUAGES = {"de": "German", "en": "English", "jp": "Japanese"}
40
+ _ALL_LANGUAGES = "all_languages"
41
+ _DOWNLOAD_URL = "https://raw.githubusercontent.com/amazon-research/amazon-multilingual-counterfactual-dataset/main/data/{lang}_{split}.tsv"
42
+ _VERSION = "1.0.0"
43
+
44
+ id2label = {"0": "not-counterfactual", "1": "counterfactual"}
45
+
46
+
47
+ class AmazonCounterfactualConfig(datasets.BuilderConfig):
48
+ """BuilderConfig for AmazonCounterfactualConfig."""
49
+
50
+ def __init__(self, languages=None, **kwargs):
51
+ super(AmazonCounterfactualConfig, self).__init__(version=datasets.Version(_VERSION, ""), **kwargs),
52
+ self.languages = languages
53
+
54
+
55
+ class AmazonCounterfactual(datasets.GeneratorBasedBuilder):
56
+ """The Amazon Multilingual Counterfactual Dataset"""
57
+
58
+ BUILDER_CONFIGS = [
59
+ AmazonCounterfactualConfig(
60
+ name=_ALL_LANGUAGES,
61
+ languages=_LANGUAGES,
62
+ description="Sentences from Amazon customer reviews annotated for counterfactual detection binary classification.",
63
+ )
64
+ ] + [
65
+ AmazonCounterfactualConfig(
66
+ name=lang,
67
+ languages=[lang],
68
+ description=f"{_LANGUAGES[lang]} sentences from Amazon customer reviews annotated for counterfactual detection binary classification.",
69
+ )
70
+ for lang in _LANGUAGES
71
+ ]
72
+ BUILDER_CONFIG_CLASS = AmazonCounterfactualConfig
73
+ DEFAULT_CONFIG_NAME = _ALL_LANGUAGES
74
+
75
+ def _info(self):
76
+ return datasets.DatasetInfo(
77
+ description=_DESCRIPTION,
78
+ features=datasets.Features(
79
+ {
80
+ "text": datasets.Value("string"),
81
+ "label": datasets.Value("string"),
82
+ "label_text": datasets.Value("string"),
83
+ }
84
+ ),
85
+ supervised_keys=None,
86
+ license=_LICENSE,
87
+ homepage=_HOMEPAGE_URL,
88
+ citation=_CITATION,
89
+ )
90
+
91
+ def _split_generators(self, dl_manager):
92
+ train_urls = [_DOWNLOAD_URL.format(split="train", lang=lang.upper()) for lang in self.config.languages]
93
+ dev_urls = [_DOWNLOAD_URL.format(split="valid", lang=lang.upper()) for lang in self.config.languages]
94
+ test_urls = [_DOWNLOAD_URL.format(split="test", lang=lang.upper()) for lang in self.config.languages]
95
+
96
+ train_paths = dl_manager.download_and_extract(train_urls)
97
+ dev_paths = dl_manager.download_and_extract(dev_urls)
98
+ test_paths = dl_manager.download_and_extract(test_urls)
99
+
100
+ return [
101
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"file_paths": train_paths}),
102
+ datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"file_paths": dev_paths}),
103
+ datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"file_paths": test_paths}),
104
+ ]
105
+
106
+ def _generate_examples(self, file_paths):
107
+ row_count = 0
108
+ for file_path in file_paths:
109
+ with open(file_path, "r", encoding="utf-8") as f:
110
+ csv_reader = csv.reader(
111
+ f,
112
+ delimiter="\t",
113
+ )
114
+ # skip header
115
+ next(csv_reader)
116
+ for row in csv_reader:
117
+ yield row_count, {"text": row[0], "label": row[1], "label_text": id2label[row[1]]}
118
+ row_count += 1
dataset_infos.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"all_languages": {"description": "The dataset contains sentences from Amazon customer reviews (sampled from Amazon product review dataset) annotated for counterfactual detection (CFD) binary classification. Counterfactual statements describe events that did not or cannot take place. Counterfactual statements may be identified as statements of the form \u2013 If p was true, then q would be true (i.e. assertions whose antecedent (p) and consequent (q) are known or assumed to be false).\n", "citation": "@misc{oneill2021i,\n title={I Wish I Would Have Loved This One, But I Didn't -- A Multilingual Dataset for Counterfactual Detection in Product Reviews},\n author={James O'Neill and Polina Rozenshtein and Ryuichi Kiryo and Motoko Kubota and Danushka Bollegala},\n year={2021},\n eprint={2104.06893},\n archivePrefix={arXiv},\n primaryClass={cs.CL}\n}\n", "homepage": "https://github.com/amazon-research/amazon-multilingual-counterfactual-dataset", "license": "CC BY-SA 4.0", "features": {"text": {"dtype": "string", "id": null, "_type": "Value"}, "label": {"dtype": "string", "id": null, "_type": "Value"}, "label_text": {"dtype": "string", "id": null, "_type": "Value"}}, "post_processed": null, "supervised_keys": null, "task_templates": null, "builder_name": "amazon_counterfactual", "config_name": "all_languages", "version": {"version_str": "1.0.0", "description": "", "major": 1, "minor": 0, "patch": 0}, "splits": {"train": {"name": "train", "num_bytes": 2265888, "num_examples": 15218, "dataset_name": "amazon_counterfactual"}, "validation": {"name": "validation", "num_bytes": 192754, "num_examples": 1267, "dataset_name": "amazon_counterfactual"}, "test": {"name": "test", "num_bytes": 379689, "num_examples": 2538, "dataset_name": "amazon_counterfactual"}}, "download_checksums": {"https://raw.githubusercontent.com/amazon-research/amazon-multilingual-counterfactual-dataset/main/data/DE_train.tsv": {"num_bytes": 705786, "checksum": "52710850d8bef30422421f4ca238a4d3e76d44e1e01e2458320b949cd66fbcd1"}, "https://raw.githubusercontent.com/amazon-research/amazon-multilingual-counterfactual-dataset/main/data/EN_train.tsv": {"num_bytes": 444664, "checksum": "fa1d3db89f133725011f022e1e0bb9ba147b0e9b8b38e15f832ad6192070f7d1"}, "https://raw.githubusercontent.com/amazon-research/amazon-multilingual-counterfactual-dataset/main/data/JP_train.tsv": {"num_bytes": 713547, "checksum": "b836056ff3c13c02f56cd5e8d0841e1de45e50f1cc89da10cf42d8c7c5d910a1"}, "https://raw.githubusercontent.com/amazon-research/amazon-multilingual-counterfactual-dataset/main/data/DE_valid.tsv": {"num_bytes": 60990, "checksum": "677831289a71ebba856dfaecec92dfc9dfade9a954f8e50c923407a1fcda981a"}, "https://raw.githubusercontent.com/amazon-research/amazon-multilingual-counterfactual-dataset/main/data/EN_valid.tsv": {"num_bytes": 37707, "checksum": "47c981cd724394a45c091998ba9fb553ea5c9159aae228b5009ac32a1e51d6be"}, "https://raw.githubusercontent.com/amazon-research/amazon-multilingual-counterfactual-dataset/main/data/JP_valid.tsv": {"num_bytes": 60656, "checksum": "8ab8efeaa2c271b0b96a74e4c2e3f4cd6b2adc3d588e43c76891f6a259890f11"}, "https://raw.githubusercontent.com/amazon-research/amazon-multilingual-counterfactual-dataset/main/data/DE_test.tsv": {"num_bytes": 120712, "checksum": "ccfb853849a85ea747fbb435bad7c50336bd2c28c523be4479535a8872870476"}, "https://raw.githubusercontent.com/amazon-research/amazon-multilingual-counterfactual-dataset/main/data/EN_test.tsv": {"num_bytes": 73457, "checksum": "ca0bbbc8d32e795526b21eba31c6b400e81c192f4d756bafa95c7b71375893d5"}, "https://raw.githubusercontent.com/amazon-research/amazon-multilingual-counterfactual-dataset/main/data/JP_test.tsv": {"num_bytes": 118677, "checksum": "863b45ba88f7e2d3d61f2a7ee1d6b44a11eb13c91653ae563616cc9bee2537a1"}}, "download_size": 2336196, "post_processing_size": null, "dataset_size": 2838331, "size_in_bytes": 5174527}, "de": {"description": "The dataset contains sentences from Amazon customer reviews (sampled from Amazon product review dataset) annotated for counterfactual detection (CFD) binary classification. Counterfactual statements describe events that did not or cannot take place. Counterfactual statements may be identified as statements of the form \u2013 If p was true, then q would be true (i.e. assertions whose antecedent (p) and consequent (q) are known or assumed to be false).\n", "citation": "@misc{oneill2021i,\n title={I Wish I Would Have Loved This One, But I Didn't -- A Multilingual Dataset for Counterfactual Detection in Product Reviews},\n author={James O'Neill and Polina Rozenshtein and Ryuichi Kiryo and Motoko Kubota and Danushka Bollegala},\n year={2021},\n eprint={2104.06893},\n archivePrefix={arXiv},\n primaryClass={cs.CL}\n}\n", "homepage": "https://github.com/amazon-research/amazon-multilingual-counterfactual-dataset", "license": "CC BY-SA 4.0", "features": {"text": {"dtype": "string", "id": null, "_type": "Value"}, "label": {"dtype": "string", "id": null, "_type": "Value"}, "label_text": {"dtype": "string", "id": null, "_type": "Value"}}, "post_processed": null, "supervised_keys": null, "task_templates": null, "builder_name": "amazon_counterfactual", "config_name": "de", "version": {"version_str": "1.0.0", "description": "", "major": 1, "minor": 0, "patch": 0}, "splits": {"train": {"name": "train", "num_bytes": 844967, "num_examples": 5600, "dataset_name": "amazon_counterfactual"}, "validation": {"name": "validation", "num_bytes": 72529, "num_examples": 466, "dataset_name": "amazon_counterfactual"}, "test": {"name": "test", "num_bytes": 143923, "num_examples": 934, "dataset_name": "amazon_counterfactual"}}, "download_checksums": {"https://raw.githubusercontent.com/amazon-research/amazon-multilingual-counterfactual-dataset/main/data/DE_train.tsv": {"num_bytes": 705786, "checksum": "52710850d8bef30422421f4ca238a4d3e76d44e1e01e2458320b949cd66fbcd1"}, "https://raw.githubusercontent.com/amazon-research/amazon-multilingual-counterfactual-dataset/main/data/DE_valid.tsv": {"num_bytes": 60990, "checksum": "677831289a71ebba856dfaecec92dfc9dfade9a954f8e50c923407a1fcda981a"}, "https://raw.githubusercontent.com/amazon-research/amazon-multilingual-counterfactual-dataset/main/data/DE_test.tsv": {"num_bytes": 120712, "checksum": "ccfb853849a85ea747fbb435bad7c50336bd2c28c523be4479535a8872870476"}}, "download_size": 887488, "post_processing_size": null, "dataset_size": 1061419, "size_in_bytes": 1948907}, "en": {"description": "The dataset contains sentences from Amazon customer reviews (sampled from Amazon product review dataset) annotated for counterfactual detection (CFD) binary classification. Counterfactual statements describe events that did not or cannot take place. Counterfactual statements may be identified as statements of the form \u2013 If p was true, then q would be true (i.e. assertions whose antecedent (p) and consequent (q) are known or assumed to be false).\n", "citation": "@misc{oneill2021i,\n title={I Wish I Would Have Loved This One, But I Didn't -- A Multilingual Dataset for Counterfactual Detection in Product Reviews},\n author={James O'Neill and Polina Rozenshtein and Ryuichi Kiryo and Motoko Kubota and Danushka Bollegala},\n year={2021},\n eprint={2104.06893},\n archivePrefix={arXiv},\n primaryClass={cs.CL}\n}\n", "homepage": "https://github.com/amazon-research/amazon-multilingual-counterfactual-dataset", "license": "CC BY-SA 4.0", "features": {"text": {"dtype": "string", "id": null, "_type": "Value"}, "label": {"dtype": "string", "id": null, "_type": "Value"}, "label_text": {"dtype": "string", "id": null, "_type": "Value"}}, "post_processed": null, "supervised_keys": null, "task_templates": null, "builder_name": "amazon_counterfactual", "config_name": "en", "version": {"version_str": "1.0.0", "description": "", "major": 1, "minor": 0, "patch": 0}, "splits": {"train": {"name": "train", "num_bytes": 552773, "num_examples": 4018, "dataset_name": "amazon_counterfactual"}, "validation": {"name": "validation", "num_bytes": 46752, "num_examples": 335, "dataset_name": "amazon_counterfactual"}, "test": {"name": "test", "num_bytes": 91394, "num_examples": 670, "dataset_name": "amazon_counterfactual"}}, "download_checksums": {"https://raw.githubusercontent.com/amazon-research/amazon-multilingual-counterfactual-dataset/main/data/EN_train.tsv": {"num_bytes": 444664, "checksum": "fa1d3db89f133725011f022e1e0bb9ba147b0e9b8b38e15f832ad6192070f7d1"}, "https://raw.githubusercontent.com/amazon-research/amazon-multilingual-counterfactual-dataset/main/data/EN_valid.tsv": {"num_bytes": 37707, "checksum": "47c981cd724394a45c091998ba9fb553ea5c9159aae228b5009ac32a1e51d6be"}, "https://raw.githubusercontent.com/amazon-research/amazon-multilingual-counterfactual-dataset/main/data/EN_test.tsv": {"num_bytes": 73457, "checksum": "ca0bbbc8d32e795526b21eba31c6b400e81c192f4d756bafa95c7b71375893d5"}}, "download_size": 555828, "post_processing_size": null, "dataset_size": 690919, "size_in_bytes": 1246747}, "jp": {"description": "The dataset contains sentences from Amazon customer reviews (sampled from Amazon product review dataset) annotated for counterfactual detection (CFD) binary classification. Counterfactual statements describe events that did not or cannot take place. Counterfactual statements may be identified as statements of the form \u2013 If p was true, then q would be true (i.e. assertions whose antecedent (p) and consequent (q) are known or assumed to be false).\n", "citation": "@misc{oneill2021i,\n title={I Wish I Would Have Loved This One, But I Didn't -- A Multilingual Dataset for Counterfactual Detection in Product Reviews},\n author={James O'Neill and Polina Rozenshtein and Ryuichi Kiryo and Motoko Kubota and Danushka Bollegala},\n year={2021},\n eprint={2104.06893},\n archivePrefix={arXiv},\n primaryClass={cs.CL}\n}\n", "homepage": "https://github.com/amazon-research/amazon-multilingual-counterfactual-dataset", "license": "CC BY-SA 4.0", "features": {"text": {"dtype": "string", "id": null, "_type": "Value"}, "label": {"dtype": "string", "id": null, "_type": "Value"}, "label_text": {"dtype": "string", "id": null, "_type": "Value"}}, "post_processed": null, "supervised_keys": null, "task_templates": null, "builder_name": "amazon_counterfactual", "config_name": "jp", "version": {"version_str": "1.0.0", "description": "", "major": 1, "minor": 0, "patch": 0}, "splits": {"train": {"name": "train", "num_bytes": 868160, "num_examples": 5600, "dataset_name": "amazon_counterfactual"}, "validation": {"name": "validation", "num_bytes": 73497, "num_examples": 466, "dataset_name": "amazon_counterfactual"}, "test": {"name": "test", "num_bytes": 144396, "num_examples": 934, "dataset_name": "amazon_counterfactual"}}, "download_checksums": {"https://raw.githubusercontent.com/amazon-research/amazon-multilingual-counterfactual-dataset/main/data/JP_train.tsv": {"num_bytes": 713547, "checksum": "b836056ff3c13c02f56cd5e8d0841e1de45e50f1cc89da10cf42d8c7c5d910a1"}, "https://raw.githubusercontent.com/amazon-research/amazon-multilingual-counterfactual-dataset/main/data/JP_valid.tsv": {"num_bytes": 60656, "checksum": "8ab8efeaa2c271b0b96a74e4c2e3f4cd6b2adc3d588e43c76891f6a259890f11"}, "https://raw.githubusercontent.com/amazon-research/amazon-multilingual-counterfactual-dataset/main/data/JP_test.tsv": {"num_bytes": 118677, "checksum": "863b45ba88f7e2d3d61f2a7ee1d6b44a11eb13c91653ae563616cc9bee2537a1"}}, "download_size": 892880, "post_processing_size": null, "dataset_size": 1086053, "size_in_bytes": 1978933}}