File size: 1,383 Bytes
afd48cc
 
 
 
9355249
 
 
afd48cc
 
 
 
 
 
 
 
 
 
 
 
 
9355249
afd48cc
 
 
 
9355249
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
42
import tarfile
import os
import datasets

_URLS = {
  "neumarco": "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):
        paths = dl_manager.download(_URLS)
        return [
            datasets.SplitGenerator(
                name=lang,
                gen_kwargs={
                    "filepath": paths['neumarco'],
                    "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