Datasets:

License:
germeval2014 / germeval2014.py
stefan-it's picture
dataset: fix span processing
f3647c5
# coding=utf-8
# Copyright 2023 HuggingFace Datasets Authors.
#
# 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.
"""GermEval 2014 NER Shared Task"""
import json
import datasets
_CITATION = """\
@inproceedings{benikova14:_germev_named_entit_recog_shared_task,
added-at = {2017-04-03T19:29:52.000+0000},
address = {Hildesheim, Germany},
author = {Benikova, Darina and Biemann, Chris and Kisselew, Max and Pad\'o, Sebastian},
biburl = {https://puma.ub.uni-stuttgart.de/bibtex/2132d938a7afe8639e78156fb9d756b20/sp},
booktitle = {Proceedings of the KONVENS GermEval workshop},
interhash = {6cad5d4fdd6a07dbefad4221ba7d8d44},
intrahash = {132d938a7afe8639e78156fb9d756b20},
keywords = {myown workshop},
pages = {104--112},
timestamp = {2017-04-03T17:30:49.000+0000},
title = {{GermEval 2014 Named Entity Recognition Shared Task: Companion Paper}},
year = 2014
}
"""
_LICENSE = """\
By exercising the Licensed Rights (defined below), You accept and agree to be bound by the terms and conditions of this Creative Commons Attribution 4.0 International Public License ("Public License"). To the extent this Public License may be interpreted as a contract, You are granted the Licensed Rights in consideration of Your acceptance of these terms and conditions, and the Licensor grants You such rights in consideration of benefits the Licensor receives from making the Licensed Material available under these terms and conditions.
"""
_DESCRIPTION = """\
# Introduction
The GermEval 2014 NER Shared Task is an event that makes available CC-licensed German data with NER annotation with the
goal of significantly advancing the state of the art in German NER and to push the field of NER towards nested
representations of named entities.
The GermEval 2014 NER Shared Task builds on a new dataset with German Named Entity annotation with the following
properties: The data was sampled from German Wikipedia and News Corpora as a collection of citations. The dataset
covers over 31,000 sentences corresponding to over 590,000 tokens. The NER annotation uses the NoSta-D guidelines,
which extend the Tübingen Treebank guidelines, using four main NER categories with sub-structure, and annotating
embeddings among NEs such as [ORG FC Kickers [LOC Darmstadt]].
# Dataset
## Labels
### Fine-grained labels indicating NER subtypes
German morphology is comparatively productive (at least when compared to
English). There is a considerable amount of word formation through both overt (non-zero) derivation and compounding, in
particular for nouns. This gives rise to morphologically complex words that are not identical to, but stand in a direct
relation to, Named Entities. The Shared Task corpus treats these as NE instances but marks them as special subtypes by
introducing two fine-grained labels: -deriv marks derivations from NEs such as the previously mentioned englisch
(“English”), and -part marks compounds including a NE as a subsequence deutschlandweit (“Germany-wide”).
### Embedded markables
Almost all extant corpora with Named Entity annotation assume that NE annotation is “flat”, that is, each word in the
text can form part of at most one NE chunk. Clearly, this is an oversimplification. Consider the noun phase Technische
Universitat Darmstadt ¨ (“Technical University (of) Darmstadt”). It denotes an organization (label ORG), but also holds
another NE, Darmstadt, which is a location (label LOC). To account for such cases, the Shared Task corpus is annotated
with two levels of Named Entities. It captures at least one level of smaller NEs being embedded in larger NEs.
## Statistics
The data used for the GermEval 2014 NER Shared Task builds on the dataset annotated by (Benikova et al., 2014).
In
this dataset, sentences taken from German Wikipedia articles and online news were used as a collection of citations,
then annotated according to extended NoSta-D guidelines and eventually distributed under the CC-BY license. As already
described above, those guidelines use four main categories with sub-structure and nesting.
The dataset is distributed contains overall more than 31,000 sentences with over 590,000 tokens. Those were divided in
the following way: the training set consists of 24,000 sentences, the development set of 2,200 sentences and the test
set of 5,100 sentences. The test set labels were not available to the participants until after the deadline. The
distribution of the categories over the whole dataset is shown in Table 1. Care was taken to ensure the even dispersion
of the categories in the subsets. The entire dataset contains over 41,000 NEs, about 7.8% of them embedded in other NEs
(nested NEs), about 11.8% are derivations (deriv) and about 5.6% are parts of NEs concatenated with other words (part).
## Format
The tab-separated format used in this dataset is similar to the CoNLL-Format. As illustrated in Table 2, the format
used in the dataset additionally contains token numbers per sentence in the first column and a comment line indicating
source and data before each sentence. The second column contains the tokens. The third column encodes the outer NE
spans, the fourth column the inner ones. The BIO-scheme was used in order to encode the NE spans. In our challenge,
further nested columns were not considered.
## Summary
In summary, we distinguish between 12 classes of NEs: four main classes PERson, LOCation, ORGanisation, and OTHer and
their subclasses, annotated at two levels (“inner” and “outer” chunks). The challenge of this setup is that while it
technically still allows a simple classification approach it introduces a recursive structure that calls for the
application of more general machine learning or other automatically classifying methods that go beyond plain sequence
tagging.
"""
_VERSION = "1.0.0"
_HOMEPAGE_URL = "https://sites.google.com/site/germeval2014ner/"
class GermEval2014Config(datasets.BuilderConfig):
"""BuilderConfig for GermEval 2014."""
def __init__(self, **kwargs):
"""BuilderConfig for GermEval 2014.
Args:
**kwargs: keyword arguments forwarded to super.
"""
super(GermEval2014Config, self).__init__(**kwargs)
class GermEval2014(datasets.GeneratorBasedBuilder):
"""GermEval 2014 NER Shared Task."""
BUILDER_CONFIGS = [
GermEval2014Config(
name="germeval2014", version=datasets.Version("1.0.0"), description="GermEval 2014 NER Shared Task "
),
]
def _info(self):
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features(
{
"tokens": datasets.Sequence(datasets.Value("string")),
"ner_tags": datasets.Sequence(
datasets.features.ClassLabel(
names=[
"O",
"B-LOC",
"I-LOC",
"B-LOCderiv",
"I-LOCderiv",
"B-LOCpart",
"I-LOCpart",
"B-ORG",
"I-ORG",
"B-ORGderiv",
"I-ORGderiv",
"B-ORGpart",
"I-ORGpart",
"B-OTH",
"I-OTH",
"B-OTHderiv",
"I-OTHderiv",
"B-OTHpart",
"I-OTHpart",
"B-PER",
"I-PER",
"B-PERderiv",
"I-PERderiv",
"B-PERpart",
"I-PERpart",
]
)
),
"ner_t5_output": datasets.Value("string"),
"ner_own_output": datasets.Value("string"),
}
),
supervised_keys=None,
license=_LICENSE,
homepage=_HOMEPAGE_URL,
citation=_CITATION,
)
def _split_generators(self, dl_manager):
import flair
from flair.datasets import NER_GERMAN_GERMEVAL
corpus = NER_GERMAN_GERMEVAL()
return [
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"sentences": corpus.train}),
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"sentences": corpus.dev}),
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"sentences": corpus.test}),
]
def _generate_examples(self, sentences):
for counter, sentence in enumerate(sentences):
original_spans = sentence.get_spans("ner")
original_tokens = []
original_tags = []
t5_spans = []
own_spans = []
for index, token in enumerate(sentence.tokens):
original_tag = "O"
for span in original_spans:
if token in span:
original_tag = "B-" + span.tag if token == span[0] else "I-" + span.tag
original_tokens.append(sentence[index].text)
original_tags.append(original_tag)
for span in original_spans:
span_text = " ".join(token.text for token in span.tokens)
t5_span = f"{span.tag} : {span_text}"
own_span = f"{span.tag} = {span_text}"
t5_spans.append(t5_span)
own_spans.append(own_span)
ner_t5_output = " || ".join(t5_spans)
ner_own_output = " || ".join(own_spans)
yield counter, {
"tokens": original_tokens,
"ner_tags": original_tags,
"ner_t5_output": ner_t5_output,
"ner_own_output": ner_own_output,
}