Upload dataset loading script
Browse files- yandex-q.py +61 -0
yandex-q.py
ADDED
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""Yandex.Q questions and answers dataset"""
|
2 |
+
|
3 |
+
|
4 |
+
import json
|
5 |
+
import gzip
|
6 |
+
|
7 |
+
import datasets
|
8 |
+
|
9 |
+
_DESCRIPTION = """\
|
10 |
+
This is a dataset of questions and answers scraped from Yandex.Q.
|
11 |
+
"""
|
12 |
+
|
13 |
+
_HOMEPAGE = "https://huggingface.co/datasets/its5Q/yandex-q"
|
14 |
+
|
15 |
+
_LICENSE = "cc0-1.0"
|
16 |
+
|
17 |
+
# TODO: Add link to the official dataset URLs here
|
18 |
+
# The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
|
19 |
+
# This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
|
20 |
+
_URLS = [
|
21 |
+
"https://huggingface.co/great-new-dataset-first_domain.zip"
|
22 |
+
]
|
23 |
+
|
24 |
+
|
25 |
+
class YandexQ(datasets.GeneratorBasedBuilder):
|
26 |
+
VERSION = datasets.Version("0.1.0")
|
27 |
+
|
28 |
+
def _info(self):
|
29 |
+
return datasets.DatasetInfo(
|
30 |
+
description=_DESCRIPTION,
|
31 |
+
features=datasets.Features(
|
32 |
+
{
|
33 |
+
"description": datasets.Value("string"),
|
34 |
+
"question": datasets.Value("string"),
|
35 |
+
"answer": datasets.Value("string")
|
36 |
+
}
|
37 |
+
),
|
38 |
+
homepage=_HOMEPAGE,
|
39 |
+
license=_LICENSE
|
40 |
+
)
|
41 |
+
|
42 |
+
def _split_generators(self, dl_manager):
|
43 |
+
data_dir = dl_manager.download_and_extract(_URLS)
|
44 |
+
return [
|
45 |
+
datasets.SplitGenerator(
|
46 |
+
name=datasets.Split.TRAIN,
|
47 |
+
gen_kwargs={
|
48 |
+
"filepath": data_dir[0],
|
49 |
+
"split": "train",
|
50 |
+
},
|
51 |
+
)
|
52 |
+
]
|
53 |
+
|
54 |
+
def _generate_examples(self, filepath, split):
|
55 |
+
with gzip.open(filepath, mode='rt', encoding="utf-8") as f:
|
56 |
+
for i, line in enumerate(f):
|
57 |
+
data = json.loads(line)
|
58 |
+
if data['description'] is None:
|
59 |
+
data['description'] = ''
|
60 |
+
yield i, data
|
61 |
+
|