File size: 5,517 Bytes
8472566
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# coding=utf-8
# Copyright 2022 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.

"""
"""

from typing import List, Tuple, Dict
from pathlib import Path

import datasets

_CITATION = """\
@inproceedings{reiss-etal-2020-identifying,
    title = "Identifying Incorrect Labels in the {C}o{NLL}-2003 Corpus",
    author = "Reiss, Frederick  and
      Xu, Hong  and
      Cutler, Bryan  and
      Muthuraman, Karthik  and
      Eichenberger, Zachary",
    booktitle = "Proceedings of the 24th Conference on Computational Natural Language Learning",
    month = nov,
    year = "2020",
    address = "Online",
    publisher = "Association for Computational Linguistics",
    url = "https://aclanthology.org/2020.conll-1.16",
    doi = "10.18653/v1/2020.conll-1.16",
    pages = "215--226",
    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.",
}
"""

_DATASETNAME = "aed_conll"

_DESCRIPTION = """\
This dataset is designed for Annotation Error Detection.
"""

_HOMEPAGE = ""

_LICENSE = ""

_URLS = {
    _DATASETNAME: "https://drive.google.com/uc?export=download&id=1jiheAs0fa8jCJVr6wGyhPVLnZyes0LCD",
}

_SOURCE_VERSION = "1.0.0"


_SCHEMA = datasets.Features({
    "id": datasets.Value("string"),
    "tokens":  datasets.Sequence(datasets.Value("string")),
    "tags_gold": datasets.Sequence(datasets.Value("string")),
    "tags": datasets.Sequence(datasets.Value("string")),
})


class AED_GUM(datasets.GeneratorBasedBuilder):
    _VERSION = datasets.Version(_SOURCE_VERSION)

    def _info(self) -> datasets.DatasetInfo:
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=_SCHEMA,
            supervised_keys=None,
            homepage=_HOMEPAGE,
            citation=_CITATION,
            license=_LICENSE,
        )


    def _split_generators(self, dl_manager) -> List[datasets.SplitGenerator]:
        """Returns SplitGenerators."""
        urls = _URLS[_DATASETNAME]
        data_path = dl_manager.download_and_extract(urls)

        return [
            datasets.SplitGenerator(
                name=datasets.Split.TRAIN,
                # Whatever you put in gen_kwargs will be passed to _generate_examples
                gen_kwargs={
                    "data_path": Path(data_path),
                },
            ),
        ]


    def read_conll(self, path):
        tokens_to_tags = {}

        tokens = []
        tags = []

        with path.open() as f:
            for line in f:
                line = line.strip()
                if line.startswith("-DOCSTART-"):
                    continue

                if not line:
                    tokens_to_tags[tuple(tokens)] = tuple(tags)
                    tokens = []
                    tags = []
                    continue

                fields = line.split()
                tokens.append(fields[0])
                tags.append(fields[-1])

            if tokens:
                tokens_to_tags[tuple(tokens)] = tuple(tags)

        return tokens_to_tags


    def _generate_examples(self, data_path: Path) -> Tuple[int, Dict]:
        """Yields examples as (key, example) tuples."""

        data_path = data_path / "aed_conll"
        original = {}
        corrected = {}

        original.update(self.read_conll(data_path / "original_corpus" / "eng.train"))
        original.update(self.read_conll(data_path / "original_corpus" / "eng.testa"))
        original.update(self.read_conll(data_path / "original_corpus" / "eng.testb"))

        corrected.update(self.read_conll(data_path / "corrected_corpus" / "eng.train"))
        corrected.update(self.read_conll(data_path / "corrected_corpus" / "eng.testa"))
        corrected.update(self.read_conll(data_path / "corrected_corpus" / "eng.testb"))

        for i, tokens in enumerate(original):
            if not tokens or tokens not in corrected:
                continue
            yield (i, {
                "id": str(i),
                "tokens": tokens,
                "tags": original[tokens],
                "tags_gold": corrected[tokens]
            })