|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""\ |
|
MobIE is a German-language dataset which is human-annotated with 20 coarse- and fine-grained entity types and entity linking information for geographically linkable entities. The dataset consists of 3,232 social media texts and traffic reports with 91K tokens, and contains 20.5K annotated entities, 13.1K of which are linked to a knowledge base. A subset of the dataset is human-annotated with seven mobility-related, n-ary relation types, while the remaining documents are annotated using a weakly-supervised labeling approach implemented with the Snorkel framework. The dataset combines annotations for NER, EL and RE, and thus can be used for joint and multi-task learning of these fundamental information extraction tasks.""" |
|
|
|
import re |
|
from json import JSONDecodeError, JSONDecoder |
|
|
|
import datasets |
|
|
|
|
|
_CITATION = """\ |
|
@inproceedings{hennig-etal-2021-mobie, |
|
title = "{M}ob{IE}: A {G}erman Dataset for Named Entity Recognition, Entity Linking and Relation Extraction in the Mobility Domain", |
|
author = "Hennig, Leonhard and |
|
Truong, Phuc Tran and |
|
Gabryszak, Aleksandra", |
|
booktitle = "Proceedings of the 17th Conference on Natural Language Processing (KONVENS 2021)", |
|
month = "6--9 " # sep, |
|
year = "2021", |
|
address = {D{\"u}sseldorf, Germany}, |
|
publisher = "KONVENS 2021 Organizers", |
|
url = "https://aclanthology.org/2021.konvens-1.22", |
|
pages = "223--227", |
|
} |
|
""" |
|
|
|
_DESCRIPTION = """\ |
|
MobIE is a German-language dataset which is human-annotated with 20 coarse- and fine-grained entity types and entity linking information for geographically linkable entities. The dataset consists of 3,232 social media texts and traffic reports with 91K tokens, and contains 20.5K annotated entities, 13.1K of which are linked to a knowledge base. A subset of the dataset is human-annotated with seven mobility-related, n-ary relation types, while the remaining documents are annotated using a weakly-supervised labeling approach implemented with the Snorkel framework. The dataset combines annotations for NER, EL and RE, and thus can be used for joint and multi-task learning of these fundamental information extraction tasks.""" |
|
|
|
_HOMEPAGE = "https://github.com/dfki-nlp/mobie" |
|
|
|
_LICENSE = "CC-BY 4.0" |
|
|
|
_URLs = { |
|
"train": "https://github.com/DFKI-NLP/MobIE/raw/master/v1_20210811/train.jsonl.gz", |
|
"dev": "https://github.com/DFKI-NLP/MobIE/raw/master/v1_20210811/dev.jsonl.gz", |
|
"test": "https://github.com/DFKI-NLP/MobIE/raw/master/v1_20210811/test.jsonl.gz", |
|
} |
|
|
|
|
|
class Mobie(datasets.GeneratorBasedBuilder): |
|
"""MobIE is a German-language dataset which is human-annotated with 20 coarse- and fine-grained entity types and entity linking information for geographically linkable entities""" |
|
|
|
VERSION = datasets.Version("1.0.0") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BUILDER_CONFIGS = [ |
|
datasets.BuilderConfig(name="mobie-v1_20210811", version=VERSION, description="MobIE V1"), |
|
] |
|
|
|
def _info(self): |
|
features = datasets.Features( |
|
{ |
|
"id": datasets.Value("string"), |
|
"tokens": datasets.Sequence(datasets.Value("string")), |
|
"ner_tags": datasets.Sequence( |
|
datasets.features.ClassLabel( |
|
names=[ |
|
"O", |
|
"B-date", |
|
"I-date", |
|
"B-disaster-type", |
|
"I-disaster-type", |
|
"B-distance", |
|
"I-distance", |
|
"B-duration", |
|
"I-duration", |
|
"B-event-cause", |
|
"I-event-cause", |
|
"B-location", |
|
"I-location", |
|
"B-location-city", |
|
"I-location-city", |
|
"B-location-route", |
|
"I-location-route", |
|
"B-location-stop", |
|
"I-location-stop", |
|
"B-location-street", |
|
"I-location-street", |
|
"B-money", |
|
"I-money", |
|
"B-number", |
|
"I-number", |
|
"B-organization", |
|
"I-organization", |
|
"B-organization-company", |
|
"I-organization-company", |
|
"B-org-position", |
|
"I-org-position", |
|
"B-percent", |
|
"I-percent", |
|
"B-person", |
|
"I-person", |
|
"B-set", |
|
"I-set", |
|
"B-time", |
|
"I-time", |
|
"B-trigger", |
|
"I-trigger", |
|
] |
|
) |
|
), |
|
} |
|
) |
|
|
|
return datasets.DatasetInfo( |
|
|
|
description=_DESCRIPTION, |
|
|
|
features=features, |
|
|
|
|
|
|
|
supervised_keys=None, |
|
|
|
homepage=_HOMEPAGE, |
|
|
|
license=_LICENSE, |
|
|
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
"""Returns SplitGenerators.""" |
|
|
|
|
|
|
|
|
|
data_dir = dl_manager.download_and_extract(_URLs) |
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
|
|
gen_kwargs={"filepath": data_dir["train"], "split": "train"}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TEST, |
|
|
|
gen_kwargs={"filepath": data_dir["test"], "split": "test"}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.VALIDATION, |
|
|
|
gen_kwargs={"filepath": data_dir["dev"], "split": "dev"}, |
|
), |
|
] |
|
|
|
def _generate_examples(self, filepath, split): |
|
"""Yields examples.""" |
|
|
|
NOT_WHITESPACE = re.compile(r"[^\s]") |
|
|
|
def decode_stacked(document, pos=0, decoder=JSONDecoder()): |
|
while True: |
|
match = NOT_WHITESPACE.search(document, pos) |
|
if not match: |
|
return |
|
pos = match.start() |
|
try: |
|
obj, pos = decoder.raw_decode(document, pos) |
|
except JSONDecodeError: |
|
raise |
|
yield obj |
|
|
|
with open(filepath, encoding="utf-8") as f: |
|
raw = f.read() |
|
|
|
for doc in decode_stacked(raw): |
|
text = doc["text"]["string"] |
|
|
|
|
|
entity_starts = [] |
|
for m in doc["conceptMentions"]["array"]: |
|
entity_starts.append(m["span"]["start"]) |
|
for s in doc["sentences"]["array"]: |
|
toks = [] |
|
lbls = [] |
|
sid = s["id"] |
|
for x in s["tokens"]["array"]: |
|
toks.append(text[x["span"]["start"] : x["span"]["end"]]) |
|
|
|
if x["ner"]["string"] != 'O': |
|
lbls.append("B-" + x["ner"]["string"] if x["span"]["start"] in entity_starts else "I-" + x["ner"]["string"]) |
|
else: |
|
lbls.append(x["ner"]["string"]) |
|
|
|
yield sid, { |
|
"id": sid, |
|
"tokens": toks, |
|
"ner_tags": lbls, |
|
} |
|
|
|
|