leonweber commited on
Commit
7538632
1 Parent(s): e6b3fc7

Upload aed_gum.py

Browse files
Files changed (1) hide show
  1. aed_gum.py +169 -0
aed_gum.py ADDED
@@ -0,0 +1,169 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ import random
17
+ from typing import List, Tuple, Dict
18
+ from pathlib import Path
19
+ import pyconll
20
+
21
+ import datasets
22
+
23
+ _CITATION = """\
24
+ @article{zeldes2017gum,
25
+ title={The GUM corpus: Creating multilayer resources in the classroom},
26
+ author={Zeldes, Amir},
27
+ journal={Language Resources and Evaluation},
28
+ volume={51},
29
+ number={3},
30
+ pages={581--612},
31
+ year={2017},
32
+ publisher={Springer}
33
+ }
34
+
35
+ @article{10.1162/coli_a_00464,
36
+ author = {Klie, Jan-Christoph and Webber, Bonnie and Gurevych, Iryna},
37
+ title = "{Annotation Error Detection: Analyzing the Past and Present for a More Coherent Future}",
38
+ journal = {Computational Linguistics},
39
+ pages = {1-42},
40
+ year = {2022},
41
+ month = {11},
42
+ abstract = "{Annotated data is an essential ingredient in natural language processing for training and evaluating machine learning models. It is therefore very desirable for the annotations to be of high quality. Recent work, however, has shown that several popular datasets contain a surprising number of annotation errors or inconsistencies. To alleviate this issue, many methods for annotation error detection have been devised over the years. While researchers show that their approaches work well on their newly introduced datasets, they rarely compare their methods to previous work or on the same datasets. This raises strong concerns on methods’ general performance and makes it difficult to asses their strengths and weaknesses. We therefore reimplement 18 methods for detecting potential annotation errors and evaluate them on 9 English datasets for text classification as well as token and span labeling. In addition, we define a uniform evaluation setup including a new formalization of the annotation error detection task, evaluation protocol and general best practices. To facilitate future research and reproducibility, we release our datasets and implementations in an easy-to-use and open source software package.}",
43
+ issn = {0891-2017},
44
+ doi = {10.1162/coli_a_00464},
45
+ url = {https://doi.org/10.1162/coli\_a\_00464},
46
+ eprint = {https://direct.mit.edu/coli/article-pdf/doi/10.1162/coli\_a\_00464/2057485/coli\_a\_00464.pdf},
47
+ }
48
+ """
49
+
50
+ _DATASETNAME = "aed_gum"
51
+
52
+ _DESCRIPTION = """\
53
+ This dataset is designed for Annotation Error Detection.
54
+ """
55
+
56
+ _HOMEPAGE = ""
57
+
58
+ _LICENSE = ""
59
+
60
+ _URLS = {
61
+ "train": "https://github.com/UniversalDependencies/UD_English-GUM/raw/master/en_gum-ud-dev.conllu",
62
+ "dev": "https://github.com/UniversalDependencies/UD_English-GUM/raw/master/en_gum-ud-train.conllu",
63
+ "test": "https://github.com/UniversalDependencies/UD_English-GUM/raw/master/en_gum-ud-test.conllu",
64
+ }
65
+
66
+ _SOURCE_VERSION = "1.0.0"
67
+
68
+
69
+ _SCHEMA = datasets.Features({
70
+ "id": datasets.Value("string"),
71
+ "tokens": datasets.Sequence(datasets.Value("string")),
72
+ "tags_gold": datasets.Sequence(datasets.Value("string")),
73
+ "tags": datasets.Sequence(datasets.Value("string")),
74
+ })
75
+
76
+ _UPOS_TAG_SET = [
77
+ "ADJ",
78
+ "ADP",
79
+ "ADV",
80
+ "AUX",
81
+ "CCONJ",
82
+ "DET",
83
+ "INTJ",
84
+ "NOUN",
85
+ "NUM",
86
+ "PART",
87
+ "PRON",
88
+ "PROPN",
89
+ "PUNCT",
90
+ "SCONJ",
91
+ "SYM",
92
+ "VERB",
93
+ "X",
94
+ ]
95
+
96
+
97
+ class AED_GUM(datasets.GeneratorBasedBuilder):
98
+ _VERSION = datasets.Version(_SOURCE_VERSION)
99
+
100
+ def _info(self) -> datasets.DatasetInfo:
101
+ return datasets.DatasetInfo(
102
+ description=_DESCRIPTION,
103
+ features=_SCHEMA,
104
+ supervised_keys=None,
105
+ homepage=_HOMEPAGE,
106
+ citation=_CITATION,
107
+ license=_LICENSE,
108
+ )
109
+
110
+ def _split_generators(self, dl_manager) -> List[datasets.SplitGenerator]:
111
+ """Returns SplitGenerators."""
112
+ data_paths = dl_manager.download_and_extract(_URLS)
113
+
114
+ return [
115
+ datasets.SplitGenerator(
116
+ name=datasets.Split.TRAIN,
117
+ # Whatever you put in gen_kwargs will be passed to _generate_examples
118
+ gen_kwargs={
119
+ "data_path": Path(data_paths["train"]),
120
+ },
121
+ ),
122
+ datasets.SplitGenerator(
123
+ name=datasets.Split.VALIDATION,
124
+ # Whatever you put in gen_kwargs will be passed to _generate_examples
125
+ gen_kwargs={
126
+ "data_path": Path(data_paths["dev"]),
127
+ },
128
+ ),
129
+ datasets.SplitGenerator(
130
+ name=datasets.Split.TEST,
131
+ # Whatever you put in gen_kwargs will be passed to _generate_examples
132
+ gen_kwargs={
133
+ "data_path": Path(data_paths["test"]),
134
+ },
135
+ ),
136
+ ]
137
+
138
+ # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
139
+
140
+
141
+ def _generate_examples(self, data_path: Path) -> Tuple[int, Dict]:
142
+ """Yields examples as (key, example) tuples."""
143
+
144
+ random.seed(42)
145
+ noise_level = 5 / 100
146
+
147
+ data = pyconll.load_from_file(str(data_path))
148
+ for i, sentence in enumerate(data):
149
+ tokens = []
150
+ tags = []
151
+ tags_gold = []
152
+
153
+ for token in sentence:
154
+ tag_gold = token.upos if token.upos else "NONE"
155
+ if random.uniform(0, 1) < noise_level:
156
+ tags.append(random.choice(_UPOS_TAG_SET))
157
+ else:
158
+ tags.append(tag_gold)
159
+
160
+ tags_gold.append(tag_gold)
161
+ tokens.append(token.form)
162
+
163
+
164
+ yield (i, {
165
+ "id": sentence.id,
166
+ "tokens": tokens,
167
+ "tags": tags,
168
+ "tags_gold": tags_gold
169
+ })