Deehan1866 commited on
Commit
435ab00
·
verified ·
1 Parent(s): e0c376b

Create data.py

Browse files
Files changed (1) hide show
  1. data.py +170 -0
data.py ADDED
@@ -0,0 +1,170 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ """This is humorous headline dataset called Humicroedit introduced in the Task-7 of SemEval 2020."""
16
+
17
+
18
+ import csv
19
+ import os
20
+
21
+ import datasets
22
+
23
+
24
+ _CITATION = """\
25
+ @article{hossain2019president,
26
+ title={" President Vows to Cut< Taxes> Hair": Dataset and Analysis of Creative Text Editing for Humorous Headlines},
27
+ author={Hossain, Nabil and Krumm, John and Gamon, Michael},
28
+ journal={arXiv preprint arXiv:1906.00274},
29
+ year={2019}
30
+ }
31
+ """
32
+
33
+ _DESCRIPTION = """\
34
+ This new dataset is designed to assess the funniness of edited news headlines.
35
+ """
36
+
37
+ _HOMEPAGE = "https://www.cs.rochester.edu/u/nhossain/humicroedit.html"
38
+ _LICENSE = ""
39
+
40
+ _URL = "https://cs.rochester.edu/u/nhossain/semeval-2020-task-7-dataset.zip"
41
+
42
+
43
+ class Humicroedit(datasets.GeneratorBasedBuilder):
44
+ """This is humorous headline dataset called Humicroedit introduced in the Task-7 of SemEval 2020."""
45
+
46
+ VERSION = datasets.Version("1.1.0")
47
+
48
+ # This is an example of a dataset with multiple configurations.
49
+ # If you don't want/need to define several sub-sets in your dataset,
50
+ # just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.
51
+
52
+ # If you need to make complex sub-parts in the datasets with configurable options
53
+ # You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
54
+ # BUILDER_CONFIG_CLASS = MyBuilderConfig
55
+
56
+ # You will be able to load one or the other configurations in the following list with
57
+ # data = datasets.load_dataset('my_dataset', 'first_domain')
58
+ # data = datasets.load_dataset('my_dataset', 'second_domain')
59
+ BUILDER_CONFIGS = [
60
+ datasets.BuilderConfig(name="subtask-1", description="This part of the dataset covers the data for subtask-1"),
61
+ datasets.BuilderConfig(name="subtask-2", description="This part of the dataset covers the data for subtask-2"),
62
+ ]
63
+
64
+ def _info(self):
65
+ if self.config.name == "subtask-1":
66
+ features = datasets.Features(
67
+ {
68
+ "id": datasets.Value("string"),
69
+ "original": datasets.Value("string"),
70
+ "edit": datasets.Value("string"),
71
+ "grades": datasets.Value("string"),
72
+ "meanGrade": datasets.Value("float"),
73
+ # These are the features of your dataset like images, labels ...
74
+ }
75
+ )
76
+ else:
77
+ features = datasets.Features(
78
+ {
79
+ "id": datasets.Value("string"),
80
+ "original1": datasets.Value("string"),
81
+ "edit1": datasets.Value("string"),
82
+ "grades1": datasets.Value("string"),
83
+ "meanGrade1": datasets.Value("float"),
84
+ "original2": datasets.Value("string"),
85
+ "edit2": datasets.Value("string"),
86
+ "grades2": datasets.Value("string"),
87
+ "meanGrade2": datasets.Value("float"),
88
+ "label": datasets.ClassLabel(names=["equal", "sentence1", "sentence2"]),
89
+ }
90
+ )
91
+ return datasets.DatasetInfo(
92
+ description=_DESCRIPTION,
93
+ features=features,
94
+ supervised_keys=None,
95
+ homepage=_HOMEPAGE,
96
+ license=_LICENSE,
97
+ citation=_CITATION,
98
+ )
99
+
100
+ def _split_generators(self, dl_manager):
101
+ """Returns SplitGenerators."""
102
+ data_dir = dl_manager.download_and_extract(_URL)
103
+ ROOT = "semeval-2020-task-7-dataset"
104
+
105
+ return [
106
+ datasets.SplitGenerator(
107
+ name=datasets.Split.TRAIN,
108
+ # These kwargs will be passed to _generate_examples
109
+ gen_kwargs={
110
+ "filepath": os.path.join(data_dir, ROOT, self.config.name, "train.csv"),
111
+ "split": "train",
112
+ },
113
+ ),
114
+ datasets.SplitGenerator(
115
+ name=datasets.Split.TEST,
116
+ # These kwargs will be passed to _generate_examples
117
+ gen_kwargs={"filepath": os.path.join(data_dir, ROOT, self.config.name, "test.csv"), "split": "test"},
118
+ ),
119
+ datasets.SplitGenerator(
120
+ name=datasets.Split.VALIDATION,
121
+ # These kwargs will be passed to _generate_examples
122
+ gen_kwargs={
123
+ "filepath": os.path.join(data_dir, ROOT, self.config.name, "dev.csv"),
124
+ "split": "dev",
125
+ },
126
+ ),
127
+ datasets.SplitGenerator(
128
+ name=datasets.Split("funlines"),
129
+ # These kwargs will be passed to _generate_examples
130
+ gen_kwargs={
131
+ "filepath": os.path.join(data_dir, ROOT, self.config.name, "train_funlines.csv"),
132
+ "split": "funlines",
133
+ },
134
+ ),
135
+ ]
136
+
137
+ def _generate_examples(self, filepath, split):
138
+ """Yields examples."""
139
+ label_names = ["equal", "sentence1", "sentence2"]
140
+
141
+ with open(filepath, encoding="utf-8") as csv_file:
142
+ csv_reader = csv.reader(
143
+ csv_file, quotechar='"', delimiter=",", quoting=csv.QUOTE_ALL, skipinitialspace=True
144
+ )
145
+ next(csv_reader)
146
+
147
+ for id_, row in enumerate(csv_reader):
148
+ if self.config.name == "subtask-1":
149
+ row_id, original, edit, grades, meanGrade = row
150
+ yield id_, {
151
+ "id": row_id,
152
+ "original": original,
153
+ "edit": edit,
154
+ "grades": grades,
155
+ "meanGrade": meanGrade,
156
+ }
157
+ else:
158
+ row_id, original1, edit1, grades1, meanGrade1, original2, edit2, grades2, meanGrade2, label = row
159
+ yield id_, {
160
+ "id": row_id,
161
+ "original1": original1,
162
+ "edit1": edit1,
163
+ "grades1": grades1,
164
+ "meanGrade1": meanGrade1,
165
+ "original2": original2,
166
+ "edit2": edit2,
167
+ "grades2": grades2,
168
+ "meanGrade2": meanGrade2,
169
+ "label": label_names[int(label)],
170
+ }