Datasets:
File size: 1,350 Bytes
afd48cc |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
import tarfile
import os
import datasets
_URL = "https://huggingface.co/datasets/neuclir/neumarco/resolve/main/data/neumarco.tar.gz"
class Neumarco(datasets.GeneratorBasedBuilder):
VERSION = datasets.Version("1.0.0")
def _info(self):
return datasets.DatasetInfo(
features=datasets.Features({
"doc_id": datasets.Value("string"),
"text": datasets.Value("string"),
}),
)
def _split_generators(self, dl_manager):
path = dl_manager.download(_URL)
return [
datasets.SplitGenerator(
name=lang,
gen_kwargs={
"filepath": path,
"tarpath": f'eng-{lang}/msmarco.collection.20210731-scale21-sockeye2-tm1.tsv'
})
for lang in ['fas', 'rus', 'zho']
]
def _generate_examples(self, filepath, tarpath):
with tarfile.open(filepath, 'r|gz') as tarf:
for fileinfo in tarf:
if fileinfo.name != tarpath:
continue
with tarf.extractfile(fileinfo) as f:
for key, line in enumerate(f):
doc_id, text = line.decode('utf8').rstrip('\n').split('\t')
yield key, {'doc_id': doc_id, 'text': text}
break
|