Datasets:

Modalities:
Text
Languages:
Estonian
ArXiv:
Libraries:
Datasets
License:
File size: 9,315 Bytes
43aa529
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import datasets


logger = datasets.logging.get_logger(__name__)

# Find for instance the citation on arxiv or on the dataset repo/website
_CITATION = """\
@inproceedings{hedderich2021analysing,
  title={Analysing the Noise Model Error for Realistic Noisy Label Data},
  author={Hedderich, Michael A and Zhu, Dawei and Klakow, Dietrich},
  booktitle={Proceedings of the AAAI Conference on Artificial Intelligence},
  volume={35},
  number={9},
  pages={7675--7684},
  year={2021}
}
@inproceedings{tkachenko-etal-2013-named,
    title = "Named Entity Recognition in {E}stonian",
    author = "Tkachenko, Alexander  and  Petmanson, Timo  and  Laur, Sven",
    booktitle = "Proceedings of the 4th Biennial International Workshop on {B}alto-{S}lavic Natural Language Processing",
    year = "2013",
    publisher = "Association for Computational Linguistics",
    url = "https://www.aclweb.org/anthology/W13-2412",
}
"""

# You can copy an official description
_DESCRIPTION = """\
NoisyNER is a dataset for the evaluation of methods to handle noisy labels when training machine learning models. 
It is from the NLP/Information Extraction domain and was created through a realistic distant supervision technique. 
Some highlights and interesting aspects of the data are:
- Seven sets of labels with differing noise patterns to evaluate different noise levels on the same instances
- Full parallel clean labels available to compute upper performance bounds or study scenarios where a small amount of 
gold-standard data can be leveraged
- Skewed label distribution (typical for Named Entity Recognition tasks)
- For some label sets: noise level higher than the true label probability
- Sequential dependencies between the labels

For more details on the dataset and its creation process, please refer to our publication 
https://ojs.aaai.org/index.php/AAAI/article/view/16938 (published at AAAI'21).
"""

_HOMEPAGE = "https://github.com/uds-lsv/NoisyNER"

_LICENSE = "The original dataset is licensed under CC-BY-NC. We provide our noisy labels under CC-BY 4.0."

_URL = "https://huggingface.co/datasets/phuctrg/noisyner/raw/main/data"


class NoisyNER(datasets.GeneratorBasedBuilder):
    """
    NoisyNER is a dataset for the evaluation of methods to handle noisy labels when training machine learning models.
    """

    VERSION = datasets.Version("1.0.0")
    BUILDER_CONFIGS = [
        datasets.BuilderConfig(
            name="estner_clean", version=VERSION, description="EstNER dataset with clean labels"
        ),
        datasets.BuilderConfig(
            name="NoisyNER_labelset1", version=VERSION,
            description="NoisyNER dataset label set 1 "
                        "with automatic annotation via distant supervision based ANEA tool with no heuristics"
        ),
        datasets.BuilderConfig(
            name="NoisyNER_labelset2", version=VERSION,
            description="NoisyNER dataset label set 2 "
                        "with automatic annotation via distant supervision based ANEA tool and "
                        "applying Estonian lemmatization to normalize the words"
        ),
        datasets.BuilderConfig(
            name="NoisyNER_labelset3", version=VERSION,
            description="NoisyNER dataset label set 3 "
                        "with automatic annotation via distant supervision based ANEA tool and "
                        "splitting person entity names in the list, i.e. both first and last names can be matched "
                        "separately. Person names must have a minimum length of 4. Also, lemmatization"
        ),
        datasets.BuilderConfig(
            name="NoisyNER_labelset4", version=VERSION,
            description="NoisyNER dataset label set 4 "
                        "with automatic annotation via distant supervision based ANEA tool and if entity names from "
                        "two different lists match the same word, location entities are preferred. "
                        "Also, lemmatization."
        ),
        datasets.BuilderConfig(
            name="NoisyNER_labelset5", version=VERSION,
            description="NoisyNER dataset label set 5 "
                        "with automatic annotation via distant supervision based ANEA tool and "
                        "Locations preferred, lemmatization, splitting names with minimum length 4."
        ),
        datasets.BuilderConfig(
            name="NoisyNER_labelset6", version=VERSION,
            description="NoisyNER dataset label set 6 "
                        "with automatic annotation via distant supervision based ANEA tool and "
                        "removing the entity names 'kohta', 'teine', 'naine' and 'mees' from the list of person names "
                        "(high false positive rate). Also, all of label set 5."
        ),
        datasets.BuilderConfig(
            name="NoisyNER_labelset7", version=VERSION,
            description="NoisyNER dataset label set 7 "
                        "with automatic annotation via distant supervision based ANEA tool and using alternative, "
                        "alias names for organizations. Using additionally the identifiers Q82794, Q3957, Q7930989, "
                        "Q5119 and Q11881845 for locations and Q1572070 and Q7278 for organizations. "
                        "Also, all of label set 6."
        ),
    ]

    DEFAULT_CONFIG_NAME = "estner_clean"

    def _info(self):
        features = datasets.Features(
            {
                "id": datasets.Value("string"),
                "tokens": datasets.Sequence(datasets.Value("string")),
                "lemmas": datasets.Sequence(datasets.Value("string")),
                "grammar": datasets.Sequence(datasets.Value("string")),
                "ner_tags": datasets.Sequence(
                    datasets.features.ClassLabel(
                        names=[
                            "O",
                            "B-PER",
                            "I-PER",
                            "B-ORG",
                            "I-ORG",
                            "B-LOC",
                            "I-LOC"
                        ]
                    )
                ),
            }
        )
        return datasets.DatasetInfo(
            # This is the description that will appear on the datasets page.
            description=_DESCRIPTION,
            # This defines the different columns of the dataset and their types
            features=features,  # Here we define them above because they are different between the two configurations
            # If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and
            # specify them. They'll be used if as_supervised=True in builder.as_dataset.
            # supervised_keys=("sentence", "label"),
            # Homepage of the dataset for documentation
            homepage=_HOMEPAGE,
            # License for the dataset if available
            license=_LICENSE,
            # Citation for the dataset
            citation=_CITATION,
        )

    def _split_generators(self, dl_manager):
        _URLS = {
            str(datasets.Split.TRAIN): f'{_URL}/{self.config.name}_train.tsv',
            str(datasets.Split.VALIDATION): f'{_URL}/{self.config.name}_dev.tsv',
            str(datasets.Split.TEST): f'{_URL}/{self.config.name}_test.tsv',
        }

        downloaded_files = dl_manager.download_and_extract(_URLS)

        return [datasets.SplitGenerator(name=i, gen_kwargs={"filepath": downloaded_files[str(i)]})
                for i in [datasets.Split.TRAIN, datasets.Split.VALIDATION, datasets.Split.TEST]]

    # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
    def _generate_examples(self, filepath):
        logger.info("⏳ Generating examples from = %s", filepath)
        # The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
        with open(filepath, encoding="utf-8") as f:
            guid = 0
            tokens = []
            lemmas = []
            grammar_infos = []
            ner_tags = []
            for line in f:
                if line in ["--", "", "\n", "--\n"]:
                    if tokens:
                        yield guid, {
                            "id": str(guid),
                            "tokens": tokens,
                            "lemmas": lemmas,
                            "grammar": grammar_infos,
                            "ner_tags": ner_tags,
                        }
                        guid += 1
                        tokens = []
                        lemmas = []
                        grammar_infos = []
                        ner_tags = []
                else:
                    splits = line.split("\t")
                    tokens.append(splits[0])
                    lemmas.append(splits[1])
                    grammar_infos.append(splits[2])
                    ner_tags.append(splits[3].rstrip())
            # last example
            if tokens:
                yield guid, {
                    "id": str(guid),
                    "tokens": tokens,
                    "lemmas": lemmas,
                    "grammar": grammar_infos,
                    "ner_tags": ner_tags,
                }