Datasets:
Sean MacAvaney
commited on
Commit
•
e01b20e
1
Parent(s):
b032c48
add data loader
Browse files
hc4.py
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gzip
|
2 |
+
import json
|
3 |
+
import os
|
4 |
+
import datasets
|
5 |
+
|
6 |
+
_BASE_URL = "https://huggingface.co/datasets/neuclir/hc4/resolve/main/data/"
|
7 |
+
_URLS = {
|
8 |
+
"fas": _BASE_URL + "fas-00000-of-00001.jsonl.gz",
|
9 |
+
"rus": _BASE_URL + "rus-00000-of-00001.jsonl.gz",
|
10 |
+
"zho": _BASE_URL + "zho-00000-of-00001.jsonl.gz",
|
11 |
+
}
|
12 |
+
|
13 |
+
|
14 |
+
class Neuclir1(datasets.GeneratorBasedBuilder):
|
15 |
+
VERSION = datasets.Version("1.0.1")
|
16 |
+
|
17 |
+
def _info(self):
|
18 |
+
return datasets.DatasetInfo(
|
19 |
+
features=datasets.Features({
|
20 |
+
"id": datasets.Value("string"),
|
21 |
+
"cc_file": datasets.Value("string"),
|
22 |
+
"time": datasets.Value("string"),
|
23 |
+
"title": datasets.Value("string"),
|
24 |
+
"text": datasets.Value("string"),
|
25 |
+
"url": datasets.Value("string"),
|
26 |
+
}),
|
27 |
+
)
|
28 |
+
|
29 |
+
def _split_generators(self, dl_manager):
|
30 |
+
paths = dl_manager.download(_URLS)
|
31 |
+
return [
|
32 |
+
datasets.SplitGenerator(
|
33 |
+
name=lang,
|
34 |
+
gen_kwargs={
|
35 |
+
"filepath": paths[lang]
|
36 |
+
})
|
37 |
+
for lang in _URLS
|
38 |
+
]
|
39 |
+
|
40 |
+
def _generate_examples(self, filepath):
|
41 |
+
with gzip.open(filepath, encoding="utf-8") as f:
|
42 |
+
for key, row in enumerate(f):
|
43 |
+
data = json.loads(row)
|
44 |
+
yield key, data
|