Finalized the script.
Browse files- bertic_data.py +28 -48
bertic_data.py
CHANGED
|
@@ -1,26 +1,26 @@
|
|
| 1 |
import datasets
|
| 2 |
import gzip
|
| 3 |
-
import
|
| 4 |
from typing import List
|
| 5 |
|
| 6 |
|
| 7 |
_URL = "http://nl.ijs.si/nikola/dedup_hbs/"
|
| 8 |
-
_URLS =
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
"
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
_HOMEPAGE = _URL
|
| 25 |
|
| 26 |
_DESCRIPTION = """\
|
|
@@ -54,18 +54,6 @@ _CITATION = r"""
|
|
| 54 |
}"""
|
| 55 |
|
| 56 |
|
| 57 |
-
class BerticDataConfig(datasets.BuilderConfig):
|
| 58 |
-
"""BuilderConfig for Bertic data sample."""
|
| 59 |
-
|
| 60 |
-
def __init__(self, *args, subsets, **kwargs):
|
| 61 |
-
"""BuilderConfig for BerticData.
|
| 62 |
-
Args:
|
| 63 |
-
**kwargs: keyword arguments forwarded to super.
|
| 64 |
-
"""
|
| 65 |
-
super(BerticDataConfig, self).__init__(**kwargs)
|
| 66 |
-
self.subsets = subsets
|
| 67 |
-
|
| 68 |
-
|
| 69 |
class BerticData(datasets.GeneratorBasedBuilder):
|
| 70 |
"""Bertic dataset, used for training Bertic model."""
|
| 71 |
|
|
@@ -82,14 +70,6 @@ class BerticData(datasets.GeneratorBasedBuilder):
|
|
| 82 |
# You will be able to load one or the other configurations in the following list with
|
| 83 |
# data = datasets.load_dataset('my_dataset', 'first_domain')
|
| 84 |
# data = datasets.load_dataset('my_dataset', 'second_domain')
|
| 85 |
-
BUILDER_CONFIGS = [
|
| 86 |
-
BerticDataConfig(
|
| 87 |
-
name="bertic",
|
| 88 |
-
subsets=["bertic"],
|
| 89 |
-
version=VERSION,
|
| 90 |
-
description="All subsets",
|
| 91 |
-
)
|
| 92 |
-
]
|
| 93 |
|
| 94 |
def _info(self):
|
| 95 |
features = datasets.Features(
|
|
@@ -104,23 +84,23 @@ class BerticData(datasets.GeneratorBasedBuilder):
|
|
| 104 |
citation=_CITATION,
|
| 105 |
)
|
| 106 |
|
| 107 |
-
def _split_generators(
|
| 108 |
-
|
| 109 |
-
) -> List[datasets.SplitGenerator]:
|
| 110 |
-
urls_to_download = {i: url for i, url in enumerate(_URLS)}
|
| 111 |
-
downloaded_files = dl_manager.download_and_extract(urls_to_download)
|
| 112 |
|
| 113 |
return [
|
| 114 |
datasets.SplitGenerator(
|
| 115 |
-
name=
|
|
|
|
| 116 |
)
|
| 117 |
-
for
|
| 118 |
]
|
| 119 |
|
| 120 |
-
|
|
|
|
| 121 |
key = 0
|
| 122 |
-
for name in
|
| 123 |
-
with gzip.open(name, "rb") as f:
|
|
|
|
| 124 |
for line in f.readlines():
|
| 125 |
-
yield key, {"text": line.
|
| 126 |
key += 1
|
|
|
|
| 1 |
import datasets
|
| 2 |
import gzip
|
| 3 |
+
import os
|
| 4 |
from typing import List
|
| 5 |
|
| 6 |
|
| 7 |
_URL = "http://nl.ijs.si/nikola/dedup_hbs/"
|
| 8 |
+
_URLS = {
|
| 9 |
+
"macocu_hbs": _URL + "macocu.hbs.translit.dedup.lines.gz",
|
| 10 |
+
"hr_news": _URL + "hr_news.translit.dedup.lines.gz",
|
| 11 |
+
"bswac": _URL + "bswac.translit.dedup.lines.gz",
|
| 12 |
+
"cc100-hr": _URL + "cc100-hr.translit.dedup.lines.gz",
|
| 13 |
+
"cc100-sr": _URL + "cc100-sr.translit.dedup.lines.gz",
|
| 14 |
+
"classla-sr": _URL + "classla-sr.translit.dedup.lines.gz",
|
| 15 |
+
"classla-hr": _URL + "classla-hr.translit.dedup.lines.gz",
|
| 16 |
+
"classla-bs": _URL + "classla-bs.translit.dedup.lines.gz",
|
| 17 |
+
"cnrwac": _URL + "cnrwac.translit.dedup.lines.gz",
|
| 18 |
+
"hrwac": _URL + "hrwac.translit.dedup.lines.gz",
|
| 19 |
+
"mC4": _URL + "mC4.sr.translit.dedup.lines.gz",
|
| 20 |
+
"riznica": _URL + "riznica.translit.dedup.lines.gz",
|
| 21 |
+
"srwac": _URL + "srwac.translit.dedup.lines.gz",
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
_HOMEPAGE = _URL
|
| 25 |
|
| 26 |
_DESCRIPTION = """\
|
|
|
|
| 54 |
}"""
|
| 55 |
|
| 56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
class BerticData(datasets.GeneratorBasedBuilder):
|
| 58 |
"""Bertic dataset, used for training Bertic model."""
|
| 59 |
|
|
|
|
| 70 |
# You will be able to load one or the other configurations in the following list with
|
| 71 |
# data = datasets.load_dataset('my_dataset', 'first_domain')
|
| 72 |
# data = datasets.load_dataset('my_dataset', 'second_domain')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
def _info(self):
|
| 75 |
features = datasets.Features(
|
|
|
|
| 84 |
citation=_CITATION,
|
| 85 |
)
|
| 86 |
|
| 87 |
+
def _split_generators(self, dl_manager):
|
| 88 |
+
downloaded_files = dl_manager.download_and_extract(_URLS)
|
|
|
|
|
|
|
|
|
|
| 89 |
|
| 90 |
return [
|
| 91 |
datasets.SplitGenerator(
|
| 92 |
+
name=url,
|
| 93 |
+
gen_kwargs={"filepath": downloaded_files[url]},
|
| 94 |
)
|
| 95 |
+
for url in _URLS
|
| 96 |
]
|
| 97 |
|
| 98 |
+
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
|
| 99 |
+
def _generate_examples(self, filepath):
|
| 100 |
key = 0
|
| 101 |
+
for name in [filepath]:
|
| 102 |
+
# with gzip.open(name, "rb") as f:
|
| 103 |
+
with open(name, "r") as f:
|
| 104 |
for line in f.readlines():
|
| 105 |
+
yield key, {"text": line.rstrip()}
|
| 106 |
key += 1
|