File size: 1,856 Bytes
d0e003e
 
 
 
 
 
 
 
 
 
 
 
 
 
153ed5d
d0e003e
324dec7
 
 
 
 
d0e003e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32237b2
d0e003e
 
 
 
 
 
 
 
 
 
88cb7d4
d0e003e
 
88cb7d4
d0e003e
 
88cb7d4
d0e003e
88cb7d4
 
858f2b4
324dec7
3271122
a4e9cb5
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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-news1.jsonl",
    "ukrainian-news2.jsonl",
    "ukrainian-news3.jsonl",
    "ukrainian-news4.jsonl",
    "ukrainian-news5.jsonl"
]


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(
                {
                    "id": datasets.Value("int32"),
                    "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(_URLS)

        return [
            datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepaths": downloaded_files})
        ]

    def _generate_examples(self, filepaths):
        """This function returns the examples in the raw (text) form."""
        logger.info("generating examples from = %s", filepaths)
        for path in filepaths:
            with open(path, encoding="utf-8") as f:
                for news_str in f:
                    news = json.loads(news_str)
                    yield news['id'], news