sadrasabouri
commited on
Commit
•
5703713
1
Parent(s):
da5f92b
Create new file
Browse files- naab-raw.py +109 -0
naab-raw.py
ADDED
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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-raw: raw version of the naab"""
|
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. This corpus contains the raw (uncleaned) version of it.
|
32 |
+
"""
|
33 |
+
|
34 |
+
_HOMEPAGE = "https://huggingface.co/datasets/SLPL/naab"
|
35 |
+
|
36 |
+
# TODO: ?
|
37 |
+
_LICENSE = "mit"
|
38 |
+
|
39 |
+
_BASE_URL = "https://huggingface.co/datasets/SLPL/naab/resolve/main/data/"
|
40 |
+
_CORPUS_URLS = {
|
41 |
+
"CC-fa": "https://storage.googleapis.com/danielk-files/farsi-text/merged_files/commoncrawl_fa_merged.txt",
|
42 |
+
}
|
43 |
+
_URLS = {
|
44 |
+
"train": list(_CORPUS_URLS.values()),
|
45 |
+
}
|
46 |
+
VERSION = datasets.Version("1.0.0")
|
47 |
+
|
48 |
+
|
49 |
+
class NaabRawConfig(datasets.BuilderConfig):
|
50 |
+
"""BuilderConfig for naab-raw."""
|
51 |
+
|
52 |
+
def __init__(self, *args, **kwargs):
|
53 |
+
"""BuilderConfig for naab.
|
54 |
+
Args:
|
55 |
+
**kwargs: keyword arguments forwarded to super.
|
56 |
+
"""
|
57 |
+
super(NaabRawConfig, self).__init__(*args, **kwargs)
|
58 |
+
|
59 |
+
|
60 |
+
class NaabRawConfig(datasets.GeneratorBasedBuilder):
|
61 |
+
"""naab-raw: raw version of the naab"""
|
62 |
+
|
63 |
+
BUILDER_CONFIGS = [
|
64 |
+
NaabConfig(
|
65 |
+
name="all",
|
66 |
+
version=VERSION,
|
67 |
+
description=_DESCRIPTION)
|
68 |
+
]
|
69 |
+
BUILDER_CONFIG_CLASS = NaabRawConfig
|
70 |
+
|
71 |
+
DEFAULT_CONFIG_NAME = "all"
|
72 |
+
|
73 |
+
def _info(self):
|
74 |
+
features = datasets.Features({
|
75 |
+
"text": datasets.Value("string"),
|
76 |
+
})
|
77 |
+
return datasets.DatasetInfo(
|
78 |
+
description=_DESCRIPTION,
|
79 |
+
features=features,
|
80 |
+
supervised_keys=None,
|
81 |
+
homepage=_HOMEPAGE,
|
82 |
+
license=_LICENSE,
|
83 |
+
citation=_CITATION,
|
84 |
+
)
|
85 |
+
|
86 |
+
def _split_generators(self, dl_manager):
|
87 |
+
data_urls = {
|
88 |
+
"train": _URLS["train"]
|
89 |
+
}
|
90 |
+
|
91 |
+
downloaded_files = dl_manager.download(data_urls["train"])
|
92 |
+
return [
|
93 |
+
datasets.SplitGenerator(
|
94 |
+
name=datasets.Split.TRAIN,
|
95 |
+
gen_kwargs={
|
96 |
+
"filepath": downloaded_files,
|
97 |
+
"split": "train"
|
98 |
+
}
|
99 |
+
)
|
100 |
+
]
|
101 |
+
|
102 |
+
|
103 |
+
def _generate_examples(self, filepath, split):
|
104 |
+
with open(filepath, encoding="utf-8") as f:
|
105 |
+
for key, row in enumerate(f):
|
106 |
+
if row.strip():
|
107 |
+
yield idx, {"text": row}
|
108 |
+
else:
|
109 |
+
yield idx, {"text": ""}
|