Upload aed_conll.py
Browse files- aed_conll.py +150 -0
aed_conll.py
ADDED
@@ -0,0 +1,150 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# coding=utf-8
|
2 |
+
# Copyright 2022 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 |
+
|
16 |
+
"""
|
17 |
+
"""
|
18 |
+
|
19 |
+
from typing import List, Tuple, Dict
|
20 |
+
from pathlib import Path
|
21 |
+
|
22 |
+
import datasets
|
23 |
+
|
24 |
+
_CITATION = """\
|
25 |
+
@inproceedings{reiss-etal-2020-identifying,
|
26 |
+
title = "Identifying Incorrect Labels in the {C}o{NLL}-2003 Corpus",
|
27 |
+
author = "Reiss, Frederick and
|
28 |
+
Xu, Hong and
|
29 |
+
Cutler, Bryan and
|
30 |
+
Muthuraman, Karthik and
|
31 |
+
Eichenberger, Zachary",
|
32 |
+
booktitle = "Proceedings of the 24th Conference on Computational Natural Language Learning",
|
33 |
+
month = nov,
|
34 |
+
year = "2020",
|
35 |
+
address = "Online",
|
36 |
+
publisher = "Association for Computational Linguistics",
|
37 |
+
url = "https://aclanthology.org/2020.conll-1.16",
|
38 |
+
doi = "10.18653/v1/2020.conll-1.16",
|
39 |
+
pages = "215--226",
|
40 |
+
abstract = "The CoNLL-2003 corpus for English-language named entity recognition (NER) is one of the most influential corpora for NER model research. A large number of publications, including many landmark works, have used this corpus as a source of ground truth for NER tasks. In this paper, we examine this corpus and identify over 1300 incorrect labels (out of 35089 in the corpus). In particular, the number of incorrect labels in the test fold is comparable to the number of errors that state-of-the-art models make when running inference over this corpus. We describe the process by which we identified these incorrect labels, using novel variants of techniques from semi-supervised learning. We also summarize the types of errors that we found, and we revisit several recent results in NER in light of the corrected data. Finally, we show experimentally that our corrections to the corpus have a positive impact on three state-of-the-art models.",
|
41 |
+
}
|
42 |
+
"""
|
43 |
+
|
44 |
+
_DATASETNAME = "aed_conll"
|
45 |
+
|
46 |
+
_DESCRIPTION = """\
|
47 |
+
This dataset is designed for Annotation Error Detection.
|
48 |
+
"""
|
49 |
+
|
50 |
+
_HOMEPAGE = ""
|
51 |
+
|
52 |
+
_LICENSE = ""
|
53 |
+
|
54 |
+
_URLS = {
|
55 |
+
_DATASETNAME: "https://drive.google.com/uc?export=download&id=1jiheAs0fa8jCJVr6wGyhPVLnZyes0LCD",
|
56 |
+
}
|
57 |
+
|
58 |
+
_SOURCE_VERSION = "1.0.0"
|
59 |
+
|
60 |
+
|
61 |
+
_SCHEMA = datasets.Features({
|
62 |
+
"id": datasets.Value("string"),
|
63 |
+
"tokens": datasets.Sequence(datasets.Value("string")),
|
64 |
+
"tags_gold": datasets.Sequence(datasets.Value("string")),
|
65 |
+
"tags": datasets.Sequence(datasets.Value("string")),
|
66 |
+
})
|
67 |
+
|
68 |
+
|
69 |
+
class AED_GUM(datasets.GeneratorBasedBuilder):
|
70 |
+
_VERSION = datasets.Version(_SOURCE_VERSION)
|
71 |
+
|
72 |
+
def _info(self) -> datasets.DatasetInfo:
|
73 |
+
return datasets.DatasetInfo(
|
74 |
+
description=_DESCRIPTION,
|
75 |
+
features=_SCHEMA,
|
76 |
+
supervised_keys=None,
|
77 |
+
homepage=_HOMEPAGE,
|
78 |
+
citation=_CITATION,
|
79 |
+
license=_LICENSE,
|
80 |
+
)
|
81 |
+
|
82 |
+
|
83 |
+
def _split_generators(self, dl_manager) -> List[datasets.SplitGenerator]:
|
84 |
+
"""Returns SplitGenerators."""
|
85 |
+
urls = _URLS[_DATASETNAME]
|
86 |
+
data_path = dl_manager.download_and_extract(urls)
|
87 |
+
|
88 |
+
return [
|
89 |
+
datasets.SplitGenerator(
|
90 |
+
name=datasets.Split.TRAIN,
|
91 |
+
# Whatever you put in gen_kwargs will be passed to _generate_examples
|
92 |
+
gen_kwargs={
|
93 |
+
"data_path": Path(data_path),
|
94 |
+
},
|
95 |
+
),
|
96 |
+
]
|
97 |
+
|
98 |
+
|
99 |
+
def read_conll(self, path):
|
100 |
+
tokens_to_tags = {}
|
101 |
+
|
102 |
+
tokens = []
|
103 |
+
tags = []
|
104 |
+
|
105 |
+
with path.open() as f:
|
106 |
+
for line in f:
|
107 |
+
line = line.strip()
|
108 |
+
if line.startswith("-DOCSTART-"):
|
109 |
+
continue
|
110 |
+
|
111 |
+
if not line:
|
112 |
+
tokens_to_tags[tuple(tokens)] = tuple(tags)
|
113 |
+
tokens = []
|
114 |
+
tags = []
|
115 |
+
continue
|
116 |
+
|
117 |
+
fields = line.split()
|
118 |
+
tokens.append(fields[0])
|
119 |
+
tags.append(fields[-1])
|
120 |
+
|
121 |
+
if tokens:
|
122 |
+
tokens_to_tags[tuple(tokens)] = tuple(tags)
|
123 |
+
|
124 |
+
return tokens_to_tags
|
125 |
+
|
126 |
+
|
127 |
+
def _generate_examples(self, data_path: Path) -> Tuple[int, Dict]:
|
128 |
+
"""Yields examples as (key, example) tuples."""
|
129 |
+
|
130 |
+
data_path = data_path / "aed_conll"
|
131 |
+
original = {}
|
132 |
+
corrected = {}
|
133 |
+
|
134 |
+
original.update(self.read_conll(data_path / "original_corpus" / "eng.train"))
|
135 |
+
original.update(self.read_conll(data_path / "original_corpus" / "eng.testa"))
|
136 |
+
original.update(self.read_conll(data_path / "original_corpus" / "eng.testb"))
|
137 |
+
|
138 |
+
corrected.update(self.read_conll(data_path / "corrected_corpus" / "eng.train"))
|
139 |
+
corrected.update(self.read_conll(data_path / "corrected_corpus" / "eng.testa"))
|
140 |
+
corrected.update(self.read_conll(data_path / "corrected_corpus" / "eng.testb"))
|
141 |
+
|
142 |
+
for i, tokens in enumerate(original):
|
143 |
+
if not tokens or tokens not in corrected:
|
144 |
+
continue
|
145 |
+
yield (i, {
|
146 |
+
"id": str(i),
|
147 |
+
"tokens": tokens,
|
148 |
+
"tags": original[tokens],
|
149 |
+
"tags_gold": corrected[tokens]
|
150 |
+
})
|