|
"""South East Asia mC4 dataset.""" |
|
import gzip |
|
import json |
|
import datasets |
|
|
|
logger = datasets.logging.get_logger(__name__) |
|
_DESCRIPTION = """ |
|
South East Asia mC4 dataset.""" |
|
_CITATION = """EMPTY""" |
|
_URL = "EMPTY" |
|
_DATA_URL = "https://huggingface.co/datasets/aisingapore/sea-pile/tree/main/sea-pile-mc4/{language}/mc4-{language}-{index:05d}-of-{n_shards:05d}.json.gz" |
|
|
|
_N_SHARDS_PER_LANGUAGES = { |
|
"zh": 468, |
|
"id": 21, |
|
"ms": 4, |
|
"tl": 6, |
|
"my": 11, |
|
"vi": 329, |
|
"th": 74, |
|
"lo": 2, |
|
"km": 9, |
|
"ta": 29, |
|
} |
|
|
|
|
|
class SEAPileConfig(datasets.BuilderConfig): |
|
"""BuilderConfig for SEAmC4.""" |
|
|
|
def __init__(self, *args, languages, **kwargs): |
|
"""BuilderConfig for SEAmC4. |
|
Args: |
|
languages (:obj:`List[str]`): list of languages to load |
|
**kwargs: keyword arguments forwarded to super. |
|
""" |
|
super().__init__( |
|
*args, |
|
name="+".join(languages), |
|
**kwargs, |
|
) |
|
self.languages = languages |
|
|
|
|
|
class SEAPile(datasets.GeneratorBasedBuilder): |
|
"""South East Asia mC4 dataset.""" |
|
|
|
BUILDER_CONFIGS = [ |
|
SEAPileConfig(languages=[lang]) for lang in _N_SHARDS_PER_LANGUAGES |
|
] |
|
BUILDER_CONFIG_CLASS = SEAPileConfig |
|
|
|
def _info(self): |
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=datasets.Features( |
|
{ |
|
"id": datasets.Value("string"), |
|
"text": datasets.Value("string"), |
|
} |
|
), |
|
supervised_keys=None, |
|
homepage=_URL, |
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
data_urls = {} |
|
for split in ["train"]: |
|
data_urls[split] = [ |
|
_DATA_URL.format( |
|
language=lang, |
|
index=index, |
|
n_shards=_N_SHARDS_PER_LANGUAGES[lang], |
|
) |
|
for lang in self.config.languages |
|
for index in range(0, _N_SHARDS_PER_LANGUAGES[lang]) |
|
] |
|
train_downloaded_files = dl_manager.download(data_urls["train"]) |
|
|
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
gen_kwargs={"filepaths": train_downloaded_files}, |
|
), |
|
] |
|
|
|
def _generate_examples(self, filepaths): |
|
"""This function returns the examples in the raw (text) form by iterating on all the files.""" |
|
id_ = 0 |
|
for filepath in filepaths: |
|
logger.info("generating examples from = %s", filepath) |
|
with gzip.open(open(filepath, "rb"), "rt", encoding="utf-8") as f: |
|
for line in f: |
|
if line: |
|
example = json.loads(line) |
|
yield id_, example |
|
id_ += 1 |
|
|