lhoestq HF staff commited on
Commit
320d96e
1 Parent(s): f3a282e

Delete loading script

Browse files
Files changed (1) hide show
  1. amazon_counterfactual.py +0 -111
amazon_counterfactual.py DELETED
@@ -1,111 +0,0 @@
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": "DE", "en": "EN", "en-ext": "EN-ext", "ja": "JP"}
40
- _DATA_DIR = "data/{lang}_{split}.tsv"
41
- _VERSION = "1.0.0"
42
-
43
- id2label = {"0": "not-counterfactual", "1": "counterfactual"}
44
-
45
-
46
- class AmazonCounterfactualConfig(datasets.BuilderConfig):
47
- """BuilderConfig for AmazonCounterfactualConfig."""
48
-
49
- def __init__(self, languages=None, **kwargs):
50
- super(AmazonCounterfactualConfig, self).__init__(version=datasets.Version(_VERSION, ""), **kwargs),
51
- self.languages = languages
52
-
53
-
54
- class AmazonCounterfactual(datasets.GeneratorBasedBuilder):
55
- """The Amazon Multilingual Counterfactual Dataset"""
56
-
57
- BUILDER_CONFIGS = [
58
- AmazonCounterfactualConfig(
59
- name=lang,
60
- languages=[lang],
61
- description=f"{_LANGUAGES[lang]} sentences from Amazon customer reviews annotated for counterfactual detection binary classification.",
62
- )
63
- for lang in _LANGUAGES
64
- ]
65
- BUILDER_CONFIG_CLASS = AmazonCounterfactualConfig
66
- DEFAULT_CONFIG_NAME = "en"
67
-
68
- def _info(self):
69
- return datasets.DatasetInfo(
70
- description=_DESCRIPTION,
71
- features=datasets.Features(
72
- {
73
- "text": datasets.Value("string"),
74
- "label": datasets.Value("int32"),
75
- "label_text": datasets.Value("string"),
76
- }
77
- ),
78
- supervised_keys=None,
79
- license=_LICENSE,
80
- homepage=_HOMEPAGE_URL,
81
- citation=_CITATION,
82
- )
83
-
84
- def _split_generators(self, dl_manager):
85
- train_urls = [_DATA_DIR.format(split="train", lang=_LANGUAGES[lang]) for lang in self.config.languages]
86
- dev_urls = [_DATA_DIR.format(split="valid", lang=_LANGUAGES[lang]) for lang in self.config.languages]
87
- test_urls = [_DATA_DIR.format(split="test", lang=_LANGUAGES[lang]) for lang in self.config.languages]
88
-
89
- train_paths = dl_manager.download_and_extract(train_urls)
90
- dev_paths = dl_manager.download_and_extract(dev_urls)
91
- test_paths = dl_manager.download_and_extract(test_urls)
92
-
93
- return [
94
- datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"file_paths": train_paths}),
95
- datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"file_paths": dev_paths}),
96
- datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"file_paths": test_paths}),
97
- ]
98
-
99
- def _generate_examples(self, file_paths):
100
- row_count = 0
101
- for file_path in file_paths:
102
- with open(file_path, "r", encoding="utf-8") as f:
103
- csv_reader = csv.reader(
104
- f,
105
- delimiter="\t",
106
- )
107
- # skip header
108
- next(csv_reader)
109
- for row in csv_reader:
110
- yield row_count, {"text": row[0], "label": row[1], "label_text": id2label[row[1]]}
111
- row_count += 1