rajeshradhakrishnan
commited on
Commit
·
77bcbc4
1
Parent(s):
a29e26b
Updated for streaming dataset
Browse files- malayalam_wiki.py +20 -43
malayalam_wiki.py
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
-
import random
|
2 |
import os
|
3 |
import re
|
4 |
|
5 |
import datasets
|
6 |
|
7 |
-
|
|
|
8 |
|
9 |
_DESCRIPTION = """\
|
10 |
Common Crawl - Malayalam.
|
@@ -20,8 +20,9 @@ _CITATION = """\
|
|
20 |
"""
|
21 |
|
22 |
_URLs = {
|
23 |
-
|
24 |
-
|
|
|
25 |
}
|
26 |
|
27 |
|
@@ -43,15 +44,11 @@ class MalayalamWiki(datasets.GeneratorBasedBuilder):
|
|
43 |
|
44 |
BUILDER_CONFIGS = [
|
45 |
MalayalamWikiConfig(
|
46 |
-
name="
|
47 |
),
|
48 |
]
|
49 |
|
50 |
|
51 |
-
def partition (self, list_in, n):
|
52 |
-
random.shuffle(list_in)
|
53 |
-
return [list_in[i::n] for i in range(n)]
|
54 |
-
|
55 |
def remove_special_characters(self, txt):
|
56 |
chars_to_ignore_regex = '[\,\?\.\!\-\;\:\"\“\%\‘\”\�Utrnle\_]'
|
57 |
unicode_ignore_regex = r'[\u200e\u200c\u200d]'
|
@@ -78,40 +75,20 @@ class MalayalamWiki(datasets.GeneratorBasedBuilder):
|
|
78 |
|
79 |
def _split_generators(self, dl_manager):
|
80 |
"""Returns SplitGenerators."""
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
file_paths.extend(wiki_2)
|
88 |
-
filepaths_splice = self.partition(file_paths,3)
|
89 |
return [
|
90 |
-
datasets.SplitGenerator(
|
91 |
-
name=datasets.Split.TRAIN,
|
92 |
-
gen_kwargs={
|
93 |
-
"filepath": filepaths_splice[0],
|
94 |
-
"split": "train",
|
95 |
-
},
|
96 |
-
),
|
97 |
-
datasets.SplitGenerator(
|
98 |
-
name=datasets.Split.VALIDATION,
|
99 |
-
gen_kwargs={
|
100 |
-
"filepath": filepaths_splice[1],
|
101 |
-
"split": "validation",
|
102 |
-
},
|
103 |
-
),
|
104 |
-
datasets.SplitGenerator(
|
105 |
-
name=datasets.Split.TEST,
|
106 |
-
gen_kwargs={
|
107 |
-
"filepath": filepaths_splice[2],
|
108 |
-
"split": "test",
|
109 |
-
},
|
110 |
-
)
|
111 |
]
|
112 |
|
113 |
-
def _generate_examples(self,
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
|
|
|
|
|
|
|
1 |
import os
|
2 |
import re
|
3 |
|
4 |
import datasets
|
5 |
|
6 |
+
|
7 |
+
logger = datasets.logging.get_logger(__name__)
|
8 |
|
9 |
_DESCRIPTION = """\
|
10 |
Common Crawl - Malayalam.
|
|
|
20 |
"""
|
21 |
|
22 |
_URLs = {
|
23 |
+
"malayalam_wiki_2020": "https://huggingface.co/datasets/rajeshradhakrishnan/malayalam_2020_wiki/resolve/main/",
|
24 |
+
"checksum_url": "https://huggingface.co/datasets/rajeshradhakrishnan/malayalam_2020_wiki/resolve/main/ml_sha256.txt"
|
25 |
+
|
26 |
}
|
27 |
|
28 |
|
|
|
44 |
|
45 |
BUILDER_CONFIGS = [
|
46 |
MalayalamWikiConfig(
|
47 |
+
name="malayalam_wiki_2020", version=VERSION, description="Common Crawl - Malayalam."
|
48 |
),
|
49 |
]
|
50 |
|
51 |
|
|
|
|
|
|
|
|
|
52 |
def remove_special_characters(self, txt):
|
53 |
chars_to_ignore_regex = '[\,\?\.\!\-\;\:\"\“\%\‘\”\�Utrnle\_]'
|
54 |
unicode_ignore_regex = r'[\u200e\u200c\u200d]'
|
|
|
75 |
|
76 |
def _split_generators(self, dl_manager):
|
77 |
"""Returns SplitGenerators."""
|
78 |
+
checksum_url = _URLs["checksum_url"]
|
79 |
+
checksum_file = dl_manager.download(checksum_url)
|
80 |
+
with open(checksum_file, encoding="utf-8") as f:
|
81 |
+
data_filenames = [line.strip() for line in f if line]
|
82 |
+
data_urls = [_URLs["malayalam_wiki_2020"] + data_filename for data_filename in data_filenames[1:2]]
|
83 |
+
downloaded_files = dl_manager.download(data_urls)
|
|
|
|
|
84 |
return [
|
85 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepaths": downloaded_files}),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
]
|
87 |
|
88 |
+
def _generate_examples(self, filepaths):
|
89 |
+
"""This function returns the examples in the raw (text) form by iterating on all the files."""
|
90 |
+
for file_id,filepath in enumerate(filepaths):
|
91 |
+
logger.info("generating examples from = %s", filepath)
|
92 |
+
with open(filepath, encoding="utf-8") as f:
|
93 |
+
for row_id, row in enumerate(f):
|
94 |
+
yield f"{file_id}_{row_id}", {"text": self.remove_special_characters(row).strip()}
|