Datasets:
File size: 1,301 Bytes
e01b20e 0807d8d 6e7c86a e01b20e e9cb8eb e01b20e |
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 43 44 45 |
import gzip
import json
import os
import datasets
_BASE_URL = "https://huggingface.co/datasets/neuclir/hc4/resolve/main/data/"
_URLS = {
"fas": _BASE_URL + "fas-00000-of-00001.jsonl.gz",
"rus": _BASE_URL + "rus-00000-of-00001.jsonl.gz",
"zho": _BASE_URL + "zho-00000-of-00001.jsonl.gz",
}
class Hc4(datasets.GeneratorBasedBuilder):
VERSION = datasets.Version("1.0.2")
def _info(self):
return datasets.DatasetInfo(
features=datasets.Features({
"id": datasets.Value("string"),
"cc_file": datasets.Value("string"),
"time": datasets.Value("string"),
"title": datasets.Value("string"),
"text": datasets.Value("string"),
"url": datasets.Value("string"),
}),
)
def _split_generators(self, dl_manager):
paths = dl_manager.download(_URLS)
return [
datasets.SplitGenerator(
name=lang,
gen_kwargs={
"filepath": paths[lang]
})
for lang in _URLS
]
def _generate_examples(self, filepath):
with gzip.open(filepath) as f:
for key, row in enumerate(f):
data = json.loads(row)
yield key, data
|