albertvillanova HF staff commited on
Commit
e87ccdd
1 Parent(s): 657e12a

Delete loading script

Browse files
Files changed (1) hide show
  1. irc_disentangle.py +0 -272
irc_disentangle.py DELETED
@@ -1,272 +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
- """Dataset of disentangled IRC"""
16
-
17
-
18
- import glob
19
- import os
20
- from pathlib import Path
21
-
22
- import datasets
23
-
24
-
25
- _CITATION = """\
26
- @inproceedings{kummerfeld-etal-2019-large,
27
- title = "A Large-Scale Corpus for Conversation Disentanglement",
28
- author = "Kummerfeld, Jonathan K. and
29
- Gouravajhala, Sai R. and
30
- Peper, Joseph J. and
31
- Athreya, Vignesh and
32
- Gunasekara, Chulaka and
33
- Ganhotra, Jatin and
34
- Patel, Siva Sankalp and
35
- Polymenakos, Lazaros C and
36
- Lasecki, Walter",
37
- booktitle = "Proceedings of the 57th Annual Meeting of the Association for Computational Linguistics",
38
- month = jul,
39
- year = "2019",
40
- address = "Florence, Italy",
41
- publisher = "Association for Computational Linguistics",
42
- url = "https://aclanthology.org/P19-1374",
43
- doi = "10.18653/v1/P19-1374",
44
- pages = "3846--3856",
45
- arxiv = "https://arxiv.org/abs/1810.11118",
46
- software = "https://jkk.name/irc-disentanglement",
47
- data = "https://jkk.name/irc-disentanglement",
48
- abstract = "Disentangling conversations mixed together in a single stream of messages is a difficult task, made harder by the lack of large manually annotated datasets. We created a new dataset of 77,563 messages manually annotated with reply-structure graphs that both disentangle conversations and define internal conversation structure. Our data is 16 times larger than all previously released datasets combined, the first to include adjudication of annotation disagreements, and the first to include context. We use our data to re-examine prior work, in particular, finding that 89% of conversations in a widely used dialogue corpus are either missing messages or contain extra messages. Our manually-annotated data presents an opportunity to develop robust data-driven methods for conversation disentanglement, which will help advance dialogue research.",
49
- }
50
- """
51
-
52
- _DESCRIPTION = """\
53
- Disentangling conversations mixed together in a single stream of messages is
54
- a difficult task, made harder by the lack of large manually annotated
55
- datasets. This new dataset of 77,563 messages manually annotated with
56
- reply-structure graphs that both disentangle conversations and define
57
- internal conversation structure. The dataset is 16 times larger than all
58
- previously released datasets combined, the first to include adjudication of
59
- annotation disagreements, and the first to include context.
60
- """
61
-
62
- _HOMEPAGE = "https://jkk.name/irc-disentanglement/"
63
-
64
- _LICENSE = "Creative Commons Attribution 4.0 International Public License"
65
-
66
- _URL = "https://github.com/jkkummerfeld/irc-disentanglement/archive/refs/heads/master.zip"
67
-
68
-
69
- class IRCDisentangle(datasets.GeneratorBasedBuilder):
70
- """IRCDisentangle dataset"""
71
-
72
- VERSION = datasets.Version("1.0.0")
73
-
74
- BUILDER_CONFIGS = [
75
- datasets.BuilderConfig(
76
- name="ubuntu",
77
- version=VERSION,
78
- description="This part of the dataset is the annotated conversations from the Ubuntu channel",
79
- ),
80
- datasets.BuilderConfig(
81
- name="channel_two",
82
- version=VERSION,
83
- description="This part of the dataset is the annotated conversations from the Channel Two",
84
- ),
85
- ]
86
-
87
- DEFAULT_CONFIG_NAME = "ubuntu"
88
-
89
- def _info(self):
90
- if self.config.name == "ubuntu":
91
- features = datasets.Features(
92
- {
93
- "id": datasets.Value("int32"),
94
- "raw": datasets.Value("string"),
95
- "ascii": datasets.Value("string"),
96
- "tokenized": datasets.Value("string"),
97
- "date": datasets.Value("string"),
98
- "connections": datasets.features.Sequence(datasets.Value("int32")),
99
- }
100
- )
101
- elif self.config.name == "channel_two":
102
- features = datasets.Features(
103
- {
104
- "id": datasets.Value("int32"),
105
- "raw": datasets.Value("string"),
106
- "ascii": datasets.Value("string"),
107
- "tokenized": datasets.Value("string"),
108
- "connections": datasets.features.Sequence(datasets.Value("int32")),
109
- }
110
- )
111
- return datasets.DatasetInfo(
112
- description=_DESCRIPTION,
113
- features=features,
114
- supervised_keys=None,
115
- homepage=_HOMEPAGE,
116
- license=_LICENSE,
117
- citation=_CITATION,
118
- )
119
-
120
- def _split_generators(self, dl_manager):
121
- """Returns SplitGenerators."""
122
- dl_dir = dl_manager.download_and_extract(_URL)
123
- filepath = os.path.join(dl_dir, "irc-disentanglement-master", "data")
124
- split_names = {datasets.Split.TRAIN: "train", datasets.Split.VALIDATION: "dev", datasets.Split.TEST: "test"}
125
- if self.config.name == "ubuntu":
126
- return [
127
- datasets.SplitGenerator(
128
- name=split,
129
- gen_kwargs={
130
- "filepath": os.path.join(filepath, split_name),
131
- "split": split_name,
132
- },
133
- )
134
- for split, split_name in split_names.items()
135
- ]
136
- elif self.config.name == "channel_two":
137
- filepath = os.path.join(filepath, "channel-two")
138
- return [
139
- datasets.SplitGenerator(
140
- name="dev",
141
- gen_kwargs={
142
- "filepath": filepath,
143
- "split": "dev",
144
- },
145
- ),
146
- datasets.SplitGenerator(
147
- name="pilot",
148
- gen_kwargs={
149
- "filepath": filepath,
150
- "split": "pilot",
151
- },
152
- ),
153
- datasets.SplitGenerator(
154
- name="test",
155
- gen_kwargs={
156
- "filepath": filepath,
157
- "split": "test",
158
- },
159
- ),
160
- datasets.SplitGenerator(
161
- name="pilot_dev",
162
- gen_kwargs={
163
- "filepath": filepath,
164
- "split": "pilot-dev",
165
- },
166
- ),
167
- datasets.SplitGenerator(
168
- name="all_",
169
- gen_kwargs={
170
- "filepath": filepath,
171
- "split": "all",
172
- },
173
- ),
174
- ]
175
-
176
- def _generate_examples(self, filepath, split):
177
- """Yields examples."""
178
-
179
- if self.config.name == "ubuntu":
180
- # run loop for each date
181
- all_files = sorted(glob.glob(os.path.join(filepath, "*.annotation.txt")))
182
- all_dates = [Path(filename).name[:10] for filename in all_files]
183
- all_info = [Path(filename).name[10:-15] for filename in all_files]
184
-
185
- elif self.config.name == "channel_two":
186
- # run loop once (there are no dates for this config)
187
- all_dates = ["_"]
188
- all_info = ["_"]
189
-
190
- last_id = 0
191
- id_ = 0
192
-
193
- for date, info in zip(all_dates, all_info):
194
-
195
- if self.config.name == "ubuntu":
196
- # load file of given date and additional info for each split
197
- raw_path = os.path.join(filepath, f"{date}{info}.raw.txt")
198
- ascii_path = os.path.join(filepath, f"{date}{info}.ascii.txt")
199
- tok_path = os.path.join(filepath, f"{date}{info}.tok.txt")
200
- annot_path = os.path.join(filepath, f"{date}{info}.annotation.txt")
201
-
202
- elif self.config.name == "channel_two":
203
- # load files of different splits
204
- raw_path = os.path.join(filepath, f"channel-two.{split}.raw.txt")
205
- ascii_path = os.path.join(filepath, f"channel-two.{split}.ascii.txt")
206
- tok_path = os.path.join(filepath, f"channel-two.{split}.tok.txt")
207
- annot_path = os.path.join(filepath, f"channel-two.{split}.annotation.txt")
208
-
209
- with open(raw_path, encoding="utf-8") as f_raw, open(ascii_path, encoding="utf-8") as f_ascii, open(
210
- tok_path, encoding="utf-8"
211
- ) as f_tok, open(annot_path, encoding="utf-8") as f_annot:
212
-
213
- # tokenize txt file
214
- raw_sentences = f_raw.read().split("\n")
215
- ascii_sentences = f_ascii.read().split("\n")
216
- tok_sentences = f_tok.read().split("\n")
217
- annot_lines = f_annot.read().split("\n")
218
-
219
- assert (
220
- len(raw_sentences) == len(ascii_sentences) == len(tok_sentences)
221
- ), "Sizes do not match: %d vs %d vs %d for Raw Sentences vs Ascii Sentences vs Tokenized Sentences." % (
222
- len(raw_sentences),
223
- len(ascii_sentences),
224
- len(tok_sentences),
225
- )
226
-
227
- annotation_pairs = []
228
-
229
- # for annotation lines, make annotation pairs
230
- for annot in annot_lines:
231
- line = annot.split(" ")
232
- if len(line) > 1:
233
- annotation_pairs.append((int(line[0]), int(line[1])))
234
-
235
- annotations = dict()
236
- for row in range(last_id, last_id + len(raw_sentences)):
237
- annotations[row] = set()
238
-
239
- for (a, b) in annotation_pairs:
240
- # required for dummy data creation
241
- if last_id + a not in annotations:
242
- annotations[last_id + a] = set()
243
- if last_id + b not in annotations:
244
- annotations[last_id + b] = set()
245
-
246
- # add annotation 'b' to a's annotation set, and vice versa
247
- annotations[last_id + a].add(last_id + b)
248
- annotations[last_id + b].add(last_id + a)
249
-
250
- for i in range(len(raw_sentences)):
251
- # return all 3 kinds of chat messages, the date (if applicable), and the annotation set for that sentece
252
- if self.config.name == "ubuntu":
253
- yield id_, {
254
- "id": id_,
255
- "raw": raw_sentences[i],
256
- "ascii": ascii_sentences[i],
257
- "tokenized": tok_sentences[i],
258
- "date": date,
259
- "connections": sorted(annotations[id_]),
260
- }
261
- elif self.config.name == "channel_two":
262
- yield id_, {
263
- "id": id_,
264
- "raw": raw_sentences[i],
265
- "ascii": ascii_sentences[i],
266
- "tokenized": tok_sentences[i],
267
- "connections": sorted(annotations[i]),
268
- }
269
- id_ += 1
270
-
271
- # continue counting from position last left off
272
- last_id = id_