|
|
|
""" |
|
""" |
|
try: |
|
import ir_datasets |
|
except ImportError as e: |
|
raise ImportError('ir-datasets package missing; `pip install ir-datasets`') |
|
import datasets |
|
|
|
IRDS_ID = 'dpr-w100' |
|
IRDS_ENTITY_TYPES = {'docs': {'doc_id': 'string', 'text': 'string', 'title': 'string'}} |
|
|
|
_CITATION = '@misc{Karpukhin2020Dpr,\n title={Dense Passage Retrieval for Open-Domain Question Answering},\n author={Vladimir Karpukhin and Barlas Oğuz and Sewon Min and Patrick Lewis and Ledell Wu and Sergey Edunov and Danqi Chen and Wen-tau Yih},\n year={2020},\n eprint={2004.04906},\n archivePrefix={arXiv},\n primaryClass={cs.CL}\n}' |
|
|
|
_DESCRIPTION = "" |
|
|
|
class dpr_w100(datasets.GeneratorBasedBuilder): |
|
BUILDER_CONFIGS = [datasets.BuilderConfig(name=e) for e in IRDS_ENTITY_TYPES] |
|
|
|
def _info(self): |
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=datasets.Features({k: datasets.Value(v) for k, v in IRDS_ENTITY_TYPES[self.config.name].items()}), |
|
homepage=f"https://ir-datasets.com/dpr-w100#dpr-w100", |
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
return [datasets.SplitGenerator(name=self.config.name)] |
|
|
|
def _generate_examples(self): |
|
dataset = ir_datasets.load(IRDS_ID) |
|
for i, item in enumerate(getattr(dataset, self.config.name)): |
|
key = i |
|
if self.config.name == 'docs': |
|
key = item.doc_id |
|
elif self.config.name == 'queries': |
|
key = item.query_id |
|
yield key, item._asdict() |
|
|
|
def as_dataset(self, split=None, *args, **kwargs): |
|
split = self.config.name |
|
return super().as_dataset(split, *args, **kwargs) |
|
|