File size: 4,324 Bytes
86edf25
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5ab665d
 
 
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
"""The IndicCorpV2 benchmark."""

import textwrap
import datasets

_INDIC_CORPV2_CITATION = """\
    @article{Doddapaneni2022towards,
  title={Towards Leaving No Indic Language Behind: Building Monolingual Corpora, Benchmark and Models for Indic Languages},
  author={Sumanth Doddapaneni and Rahul Aralikatte and Gowtham Ramesh and Shreyansh Goyal and Mitesh M. Khapra and Anoop Kunchukuttan and Pratyush Kumar},
  journal={ArXiv},
  year={2022},
  volume={abs/2212.05409}
}
"""

_INDIC_CORPV2_DESCRIPTION = """\
    IndicCORPV2 is the largest collection of texts for Indic langauges consisting of 20.9 Billion tokens of which 14.4B tokens correspond to 23 Indic languages and 6.B tokens of Indian English content curated from Indian websites.
"""

_DESCRIPTIONS = {
    "as": textwrap.dedent(
        """
        Assamese
        """
    ),
    "bd": textwrap.dedent(
        """
        Bodo
        """
    ),
    "bn": textwrap.dedent(
        """
        Bengali
        """
    ),
    "dg": textwrap.dedent(
        """
        Dogri
        """
    ),
    "en": textwrap.dedent(
        """
        English
        """
    ),
    "gom": textwrap.dedent(
        """
        Konkani
        """
    ),
    "gu": textwrap.dedent(
        """
        Gujrati
        """
    ),
    "hi": textwrap.dedent(
        """
       Hindi
        """
    ),
    "kha": textwrap.dedent(
        """
        Khasi
        """
    ),
    "kn": textwrap.dedent(
        """
        Kannada
        """
    ),
    "ks": textwrap.dedent(
        """
        Kashmiri
        """
    ),
    "mai": textwrap.dedent(
        """
        Maithili
        """
    ),
    "ml": textwrap.dedent(
        """
        Malayalam
        """
    ),
    "mni": textwrap.dedent(
        """
        Manipuri
        """
    ),
    "mr": textwrap.dedent(
        """
        Marathi
        """
    ),
    "ne": textwrap.dedent(
        """
        Nepali
        """
    ),
    "or": textwrap.dedent(
        """
        Odia
        """
    ),
    "pa": textwrap.dedent(
        """
        Punjabi
        """
    ),
    "sa": textwrap.dedent(
        """
        Sanskrit
        """
    ),
    "sat": textwrap.dedent(
        """
        Santali
        """
    ),
    "sd": textwrap.dedent(
        """
        Sindhi
        """
    ),
    "ta": textwrap.dedent(
        """
        Tamil
        """
    ),
    "te": textwrap.dedent(
        """
        Telugu
        """
    ),
    "ur": textwrap.dedent(
        """
        Urdu
        """
    ),
}

_URL = "https://objectstore.e2enetworks.net/ai4b-public-nlu-nlg/indic-corp-frozen-for-the-paper-oct-2022/{language}.txt"

_VERSION = datasets.Version("2.0.0", "Second version of IndicCorp")

class IndicCorpv2(datasets.GeneratorBasedBuilder):
    """IndicCorpV2 dataset."""
    BUILDER_CONFIGS = [
        datasets.BuilderConfig(
            name=f"{lang}",
            description=f"IndicCorpv2 for {lang}",
            version=_VERSION,
        )
        for lang in _DESCRIPTIONS.keys()
    ]

    def _info(self):
        features = datasets.Features(
            {
                "text": datasets.Value("string"),
            }
        )
        return datasets.DatasetInfo(
            description=_INDIC_CORPV2_DESCRIPTION,
            features=features,
            supervised_keys=None,
            homepage="https://github.com/AI4Bharat/IndicBERT/tree/main#indiccorp-v2",
            citation=_INDIC_CORPV2_CITATION,
        )
    
    def _split_generators(self, dl_manager):
        """Returns SplitGenerators."""
        langauge = self.config.name
        splits = {datasets.Split.TRAIN: "train"}
        data_urls = {
            split: _URL.format(language=langauge) for split in splits.values()
        }
        download_paths = dl_manager.download(data_urls)
        return [
            datasets.SplitGenerator(
                name=datasets.Split.TRAIN,
                gen_kwargs={"filepath": download_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):
                stripped_row = row.strip()
                if stripped_row:
                    yield idx, {"text": stripped_row}