import json from typing import List import datasets _VERSION = "1.0.0" # _URLS = {'ACE2004': {'test': 'http://dl.fbaipublicfiles.com/GENRE/ace2004-test-kilt.jsonl'}, # 'AIDA': { # 'train': 'http://dl.fbaipublicfiles.com/GENRE/aida-train-kilt.jsonl', # 'dev': 'http://dl.fbaipublicfiles.com/GENRE/aida-dev-kilt.jsonl', # 'test': 'http://dl.fbaipublicfiles.com/GENRE/aida-test-kilt.jsonl' # }, # 'BLINK': { # 'train': 'http://dl.fbaipublicfiles.com/GENRE/blink-train-kilt.jsonl', # 'dev': 'http://dl.fbaipublicfiles.com/GENRE/blink-dev-kilt.jsonl', # }, # 'AQUAINT': {'test': 'http://dl.fbaipublicfiles.com/GENRE/aquaint-test-kilt.jsonl'}, # 'CWEB': {'test': 'http://dl.fbaipublicfiles.com/GENRE/clueweb-test-kilt.jsonl'}, # 'MSNBC': {'test': 'http://dl.fbaipublicfiles.com/GENRE/msnbc-test-kilt.jsonl'}, # 'WIKI': {'test': 'http://dl.fbaipublicfiles.com/GENRE/wikipedia-test-kilt.jsonl'} # } class EntityDisambiguationConfig(datasets.BuilderConfig): """BuilderConfig for EntityDisambiguation.""" def __init__(self, **kwargs): """BuilderConfig for EntityDisambiguation. Args: **kwargs: keyword arguments forwarded to super. """ super(EntityDisambiguationConfig, self).__init__(**kwargs) self.features = datasets.Features( { "id": datasets.Value("int32"), "input": datasets.Value("string"), "meta": { "left_context": datasets.Value("string"), "mention": datasets.Value("string"), "right_context": datasets.Value("string"), }, "candidates": datasets.features.Sequence(datasets.Value("string")), "answer": datasets.Value("string") } ) class EntityDisambiguation(datasets.GeneratorBasedBuilder): """Entity Disambiguation dataset.""" VERSION = datasets.Version(_VERSION) BUILDER_CONFIGS = [ EntityDisambiguationConfig(name="ace2004", version=VERSION, description="ACE2004 dataset"), EntityDisambiguationConfig(name="aida", version=VERSION, description="AIDA dataset"), EntityDisambiguationConfig(name="aquaint", version=VERSION, description="AQUAINT dataset"), EntityDisambiguationConfig(name="blink", version=VERSION, description="BLINK dataset"), EntityDisambiguationConfig(name="clueweb", version=VERSION, description="CWEB dataset"), EntityDisambiguationConfig(name="msnbc", version=VERSION, description="MSNBC dataset"), EntityDisambiguationConfig(name="wiki", version=VERSION, description="WIKI dataset"), ] def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]: """Returns SplitGenerators.""" if self.config.name == "blink": available_splits = ["train", "dev"] elif self.config.name == "aida": available_splits = ["train", "dev", "test"] else: available_splits = ["test"] return [ datasets.SplitGenerator( name=split, gen_kwargs={ "filepath": dl_manager.download_and_extract( f"http://dl.fbaipublicfiles.com/GENRE/{self.config.name.lower()}-{split}-kilt.jsonl"), "split": split, }, ) for split in available_splits ] def _info(self) -> datasets.DatasetInfo: return datasets.DatasetInfo(description="Entity Disambiguation dataset", features=self.config.features) def _generate_examples(self, filepath: str, split: str): with open(filepath, encoding="utf-8") as f: for line in f: row = json.loads(line) row["answer"] = row["output"][0]["answer"] del row["output"] yield row["id"], row