sadrasabouri commited on
Commit
8cbc537
1 Parent(s): 2195e98

Update naab.py

Browse files
Files changed (1) hide show
  1. naab.py +128 -0
naab.py CHANGED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ """naab: A ready-to-use plug-and-play corpus in Farsi"""
15
+
16
+
17
+ import csv
18
+ import json
19
+ import os
20
+
21
+ import datasets
22
+
23
+
24
+ # TODO: Add BibTeX citation
25
+ # Find for instance the citation on arxiv or on the dataset repo/website
26
+ _CITATION = """\
27
+ """
28
+
29
+ # You can copy an official description
30
+ _DESCRIPTION = """\
31
+ Huge corpora of textual data are always known to be a crucial need for training deep models such as transformer-based ones. This issue is emerging more in lower resource languages - like Farsi. We propose naab, the biggest cleaned and ready-to-use open-source textual corpus in Farsi. It contains about 130GB of data, 250 million paragraphs, and 15 billion words. The project name is derived from the Farsi word ناب which means pure and high-grade.
32
+ """
33
+
34
+ _HOMEPAGE = "https://huggingface.co/datasets/SLPL/naab"
35
+
36
+ # TODO: ?
37
+ _LICENSE = "mit"
38
+
39
+ N_FILES = {
40
+ "train": 126,
41
+ "test": 3
42
+ }
43
+ _BASE_URL = "https://huggingface.co/datasets/SLPL/naab/tree/main/data/"
44
+ _URLS = {
45
+ "train": [_BASE_URL + "train-{:05d}-{:05d}.txt".format(x, N_FILES["train"]) for x in range(N_FILES["train"])],
46
+ "test": [_BASE_URL + "test-{:05d}-{:05d}.txt".format(x, N_FILES["test"]) for x in range(N_FILES["test"])],
47
+ }
48
+
49
+
50
+ class NaabConfig(datasets.BuilderConfig):
51
+ """BuilderConfig for naab."""
52
+
53
+ def __init__(self, *args, **kwargs):
54
+ """BuilderConfig for naab.
55
+ Args:
56
+ **kwargs: keyword arguments forwarded to super.
57
+ """
58
+ super().__init__(
59
+ *args,
60
+ **kwargs,
61
+ )
62
+
63
+
64
+ class Naab(datasets.GeneratorBasedBuilder):
65
+ """naab: A ready-to-use plug-and-play corpus in Farsi."""
66
+
67
+ VERSION = datasets.Version("1.0.0")
68
+
69
+ BUILDER_CONFIGS = [
70
+ NaabConfig(
71
+ name="train",
72
+ version=VERSION,
73
+ description=_DESCRIPTION),
74
+ NaabConfig(
75
+ name="test",
76
+ version=VERSION,
77
+ description=_DESCRIPTION),
78
+ ]
79
+ BUILDER_CONFIG_CLASS = NaabConfig
80
+
81
+ DEFAULT_CONFIG_NAME = "train"
82
+
83
+ def _info(self):
84
+ features = datasets.Features(
85
+ {
86
+ "id": datasets.Value("int"),
87
+ "paragraph": datasets.Value("string")
88
+ }
89
+ )
90
+ return datasets.DatasetInfo(
91
+ description=_DESCRIPTION,
92
+ features=features,
93
+ homepage=_HOMEPAGE,
94
+ license=_LICENSE,
95
+ citation=_CITATION,
96
+ )
97
+
98
+ def _split_generators(self, dl_manager):
99
+ urls = _URLS[self.config.name]
100
+ data_dir = dl_manager.download_and_extract(urls)
101
+ return [
102
+ datasets.SplitGenerator(
103
+ name=datasets.Split.TRAIN,
104
+ # These kwargs will be passed to _generate_examples
105
+ gen_kwargs={
106
+ "filepath": os.path.join(data_dir, "train.jsonl"),
107
+ "split": "train",
108
+ },
109
+ ),
110
+ datasets.SplitGenerator(
111
+ name=datasets.Split.TEST,
112
+ # These kwargs will be passed to _generate_examples
113
+ gen_kwargs={
114
+ "filepath": os.path.join(data_dir, "test.jsonl"),
115
+ "split": "test"
116
+ },
117
+ ),
118
+ ]
119
+
120
+ def _generate_examples(self, filepath, split):
121
+ # The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
122
+ with open(filepath, encoding="utf-8") as f:
123
+ for key, row in enumerate(f):
124
+ data = json.loads(row)
125
+ yield key, {
126
+ "paragraph": data["paragraph"]
127
+ }
128
+