Datasets:
ToluClassics
commited on
Commit
·
59e27f6
1
Parent(s):
d7ae74a
Update africlirmatrix.py
Browse files- africlirmatrix.py +101 -0
africlirmatrix.py
CHANGED
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# coding=utf-8
|
2 |
+
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
|
3 |
+
#
|
4 |
+
# Licensed under the Apache License, Version 2.0 (the 'License');
|
5 |
+
# you may not use this file except in compliance with the License.
|
6 |
+
# You may obtain a copy of the License at
|
7 |
+
#
|
8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9 |
+
#
|
10 |
+
# Unless required by applicable law or agreed to in writing, software
|
11 |
+
# distributed under the License is distributed on an 'AS IS' BASIS,
|
12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 |
+
# See the License for the specific language governing permissions and
|
14 |
+
# limitations under the License.
|
15 |
+
|
16 |
+
# Lint as: python3
|
17 |
+
|
18 |
+
import json
|
19 |
+
|
20 |
+
import datasets
|
21 |
+
from dataclasses import dataclass
|
22 |
+
|
23 |
+
_CITATION = '''
|
24 |
+
'''
|
25 |
+
|
26 |
+
languages = [
|
27 |
+
'afrikaans',
|
28 |
+
'amharic',
|
29 |
+
'egyptian_arabic',
|
30 |
+
'hausa',
|
31 |
+
'igbo',
|
32 |
+
'moroccan_arabic',
|
33 |
+
'northern_sotho',
|
34 |
+
'shona',
|
35 |
+
'somali',
|
36 |
+
'swahili',
|
37 |
+
'tigrinya',
|
38 |
+
'twi',
|
39 |
+
'wolof',
|
40 |
+
'yoruba',
|
41 |
+
'zulu'
|
42 |
+
]
|
43 |
+
|
44 |
+
_DESCRIPTION = 'dataset load script for AfriClirMatrix'
|
45 |
+
|
46 |
+
_DATASET_URLS = {
|
47 |
+
lang: {
|
48 |
+
'train': f'https://huggingface.co/datasets/ToluClassics/africlirmatrix/resolve/main/africlirmatrix-v1.0-{lang}/corpus.jsonl',
|
49 |
+
} for lang in languages
|
50 |
+
}
|
51 |
+
|
52 |
+
|
53 |
+
class MrTyDiCorpus(datasets.GeneratorBasedBuilder):
|
54 |
+
BUILDER_CONFIGS = [
|
55 |
+
datasets.BuilderConfig(
|
56 |
+
version=datasets.Version('1.1.0'),
|
57 |
+
name=lang,
|
58 |
+
description=f'AfriCLIRMatrix dataset in language {lang}.'
|
59 |
+
) for lang in languages
|
60 |
+
]
|
61 |
+
|
62 |
+
def _info(self):
|
63 |
+
features = datasets.Features({
|
64 |
+
'docid': datasets.Value('string'),
|
65 |
+
'title': datasets.Value('string'),
|
66 |
+
'text': datasets.Value('string'),
|
67 |
+
})
|
68 |
+
|
69 |
+
return datasets.DatasetInfo(
|
70 |
+
# This is the description that will appear on the datasets page.
|
71 |
+
description=_DESCRIPTION,
|
72 |
+
# This defines the different columns of the dataset and their types
|
73 |
+
features=features, # Here we define them above because they are different between the two configurations
|
74 |
+
supervised_keys=None,
|
75 |
+
# Homepage of the dataset for documentation
|
76 |
+
homepage='https://github.com/castorini/africlirmatrix',
|
77 |
+
# License for the dataset if available
|
78 |
+
license='',
|
79 |
+
# Citation for the dataset
|
80 |
+
citation=_CITATION,
|
81 |
+
)
|
82 |
+
|
83 |
+
def _split_generators(self, dl_manager):
|
84 |
+
lang = self.config.name
|
85 |
+
downloaded_files = dl_manager.download_and_extract(_DATASET_URLS[lang])
|
86 |
+
|
87 |
+
splits = [
|
88 |
+
datasets.SplitGenerator(
|
89 |
+
name='train',
|
90 |
+
gen_kwargs={
|
91 |
+
'filepath': downloaded_files['train'],
|
92 |
+
},
|
93 |
+
),
|
94 |
+
]
|
95 |
+
return splits
|
96 |
+
|
97 |
+
def _generate_examples(self, filepath):
|
98 |
+
with open(filepath, encoding="utf-8") as f:
|
99 |
+
for line in f:
|
100 |
+
data = json.loads(line)
|
101 |
+
yield data['id'], data
|