File size: 2,514 Bytes
c11ebe8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ccb4725
c11ebe8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
"""TODO(IndicSentiment): Add a description here."""


import json

import datasets


_HOMEPAGE = ""

_CITATION = """\

"""

_DESCRIPTION = """\

"""

_LANG = ["as", "bn", "bd", "gu", "hi", "kn", "ml", "mr", "or", "pa", "ta", "te", "ur"]
_URL = "https://huggingface.co/datasets/ai4bharat/IndicSentiment/resolve/main/data/{split}/{language}.json"
_VERSION = datasets.Version("1.0.0", "First version of IndicSentiment")


class HAIndicSentiment(datasets.GeneratorBasedBuilder):
    """TODO(IndicSentiment): Short description of my dataset."""
    BUILDER_CONFIGS = [
        datasets.BuilderConfig(
            name=f"translation-{lang}",
            description=f"translated sentiment data for {lang}",
            version=_VERSION,
        )
        for lang in _LANG
    ]

    def _info(self):
        return datasets.DatasetInfo(
            description=_DESCRIPTION + self.config.description,
            features=datasets.Features(
                {
                    "GENERIC CATEGORIES": datasets.Value("string"),
                    "CATEGORY": datasets.Value("string"),
                    "SUB-CATEGORY": datasets.Value("string"),
                    "PRODUCT": datasets.Value("string"),
                    "BRAND": datasets.Value("string"),
                    "ASPECTS": datasets.Value("string"),
                    "ASPECT COMBO": datasets.Value("string"),
                    "ENGLISH REVIEW": datasets.Value("string"),
                    "LABEL": datasets.Value("string"),
                    "INDIC REVIEW": datasets.Value("string"),
                }
            ),
            homepage=_HOMEPAGE,
            citation=_CITATION,
        )

    def _split_generators(self, dl_manager):
        """Returns SplitGenerators."""
        *translation_prefix, language = self.config.name.split("-")
        splits = {datasets.Split.VALIDATION: "validation", datasets.Split.TEST: "test"}

        data_urls = {
            split: _URL.format(language=language, split=splits[split]) for split in splits
        }
        dl_paths = dl_manager.download(data_urls)
        return [
            datasets.SplitGenerator(
                name=split,
                gen_kwargs={"filepath": dl_paths[split]},
            )
            for split in splits
        ]

    def _generate_examples(self, filepath):
        """Yields examples."""

        with open(filepath, encoding="utf-8") as f:
            for idx, row in enumerate(f):
                data = json.loads(row)
                yield idx, data