|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""Wikidata descriptions as triplets for Named Entity Disambiguation""" |
|
|
|
import json |
|
import datasets |
|
import logging |
|
|
|
|
|
logger = logging.getLogger(__name__) |
|
|
|
|
|
_CITATION = """\ |
|
""" |
|
|
|
_DESCRIPTION = """\ |
|
WiDDD stands for WIkiData Disambig with Descriptions. The former dataset comes from [Cetoli & al](https://arxiv.org/pdf/1810.09164.pdf) paper, and is aimed at solving Named Entity Disambiguation. This datasets tries to extract relevant information from entities descriptions only, instead of working with graphs. In order to do so, we mapped every Wikidata id (correct id and wrong id) in the original paper with its WikiData description. If not found, row is discarded for this version. |
|
""" |
|
|
|
_HOMEPAGE = "" |
|
|
|
_LICENSE = "Apache License 2.0" |
|
|
|
_URLs = { |
|
"train": "wikidatadescs_train.jsonl", |
|
"dev": "wikidatadescs_dev.jsonl", |
|
"test": "wikidatadescs_test.jsonl" |
|
} |
|
|
|
|
|
class WidddConfig(datasets.BuilderConfig): |
|
"""BuilderConfig for Widdd.""" |
|
|
|
def __init__(self, **kwargs): |
|
"""BuilderConfig for Widdd. |
|
Args: |
|
**kwargs: keyword arguments forwarded to super. |
|
""" |
|
super(WidddConfig, self).__init__(**kwargs) |
|
|
|
|
|
class Widdd(datasets.GeneratorBasedBuilder): |
|
"""Wikidata Disamb with Descriptions Dataset.""" |
|
|
|
VERSION = datasets.Version("1.0.0") |
|
|
|
BUILDER_CONFIGS = [ |
|
WidddConfig( |
|
name="widdd", version=VERSION, description="Wikidata Disamb with Descriptions Dataset, as triplets." |
|
), |
|
] |
|
|
|
def _info(self): |
|
features = datasets.Features( |
|
{ |
|
"example_id": datasets.Value("int32"), |
|
"string": datasets.Value("string"), |
|
"text": datasets.Value("string"), |
|
"correct_id": datasets.Value("string"), |
|
"wrong_id": datasets.Value("string"), |
|
"correct_description": datasets.Value("string"), |
|
"wrong_description": datasets.Value("string") |
|
} |
|
) |
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=features, |
|
supervised_keys=None, |
|
homepage=_HOMEPAGE, |
|
license=_LICENSE, |
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
"""Returns SplitGenerators.""" |
|
train_path = dl_manager.download_and_extract(_URLs['train']) |
|
test_path = dl_manager.download_and_extract(_URLs['test']) |
|
dev_path = dl_manager.download_and_extract(_URLs['dev']) |
|
|
|
return [ |
|
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath":train_path}), |
|
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath":test_path}), |
|
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath":dev_path}), |
|
] |
|
|
|
def _generate_examples(self, filepath): |
|
"""Yields examples.""" |
|
logging.info(f"Yielding {filepath}") |
|
with open(filepath, encoding = "utf8") as fp: |
|
for id_, l in enumerate(fp): |
|
d = json.loads(l) |
|
yield id_, d |
|
|