ukrainian-news / ukrainian-news.py
zeusfsx's picture
Added script to load data
d0e003e
raw
history blame
1.8 kB
import json
import datasets
logger = datasets.logging.get_logger(__name__)
_DESCRIPTION = """\
Ukrainian News Dataset
This is a dataset of news articles downloaded from various Ukrainian websites. The dataset contains approximately 10 569 428 JSON objects (news)
"""
_URLS = [
"ukrainian-news-1.json",
"ukrainian-news-2.json",
"ukrainian-news-3.json",
"ukrainian-news-4.json",
"ukrainian-news-5.json"
]
class UkrainianNews(datasets.GeneratorBasedBuilder):
"""Ukrainian News Dataset"""
VERSION = datasets.Version("0.0.1")
DEFAULT_CONFIG_NAME = "default"
BUILDER_CONFIGS = [
datasets.BuilderConfig(name="default", version=VERSION, description=""),
]
def _info(self):
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features(
{
"url": datasets.Value("string"),
"title": datasets.Value("string"),
"text": datasets.Value("string"),
"owner": datasets.Value("string"),
"datetime": datasets.Value("string"),
}
)
)
def _split_generators(self, dl_manager):
downloaded_files = dl_manager.download_and_extract(_URLS)
return [
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files})
]
def _generate_examples(self, filepath):
"""This function returns the examples in the raw (text) form."""
logger.info("generating examples from = %s", filepath)
key = 0
with open(filepath, encoding="utf-8") as f:
news = json.load(f)
for article in news:
yield key, article
key += 1