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