ukrainian-stackexchange / ukrainian-stackexchange.py
zeusfsx's picture
Create ukrainian-stackexchange.py
915dba1
raw
history blame
1.84 kB
from datasets import DatasetBuilder, SplitGenerator, DownloadConfig
from pathlib import Path
import json
URL = "ukrainian-stackexchange.json"
class UkrainianStackExchange(DatasetBuilder):
VERSION = "1.0.0"
BUILDER_CONFIGS = [
{
"name": "ukrainian-stackexchange",
"version": VERSION,
"description": "Ukrainian StackExchange Dataset collected from https://ukrainian.stackexchange.com/"
}
]
def _info(self):
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features({
"question": {
"id": datasets.Value("string"),
"title": datasets.Value("string"),
"text": datasets.Value("string"),
"upvoteCount": datasets.Value("int32"),
"tags": datasets.Sequence(datasets.Value("string")),
},
"answers": datasets.Sequence({
"id": datasets.Value("string"),
"text": datasets.Value("string"),
"upvoteCount": datasets.Value("int32"),
"isAccepted": datasets.Value("bool"),
}),
"url": datasets.Value("string"),
}),
supervised_keys=None,
)
def _split_generators(self, dl_manager):
path_to_file = Path(URL)
return [
SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"filepath": path_to_file,
},
),
]
def _generate_examples(self, filepath):
with open(filepath, "r", encoding="utf-8") as f:
json_data = json.load(f)
for idx, data in enumerate(json_data):
yield idx, data