|
import json |
|
import datasets |
|
import gzip |
|
|
|
logger = datasets.logging.get_logger(__name__) |
|
_DESCRIPTION = """\\nRomanian diacritic dataset""" |
|
_CITATION = """n/a""" |
|
|
|
_URL = "https://github.com/dumitrescustefan/diacritic" |
|
_DATA_URL = "https://huggingface.co/datasets/dumitrescustefan/diacritic/resolve/main/data/{split_suffix}-{index:03d}.json.gz" |
|
_N_SHARDS_PER_SPLIT = { |
|
"train": 78, "validation": 1 |
|
} |
|
|
|
class RLM(datasets.GeneratorBasedBuilder): |
|
BUILDER_CONFIGS = [ |
|
datasets.BuilderConfig(name="v1", version="1.0.0", description="v1.0 of romanian diacritic corpus"), |
|
] |
|
|
|
DEFAULT_CONFIG_NAME = "v1" |
|
|
|
def _info(self): |
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=datasets.Features( |
|
{ |
|
"id": datasets.Value("int64"), |
|
"text": datasets.Value("string"), |
|
} |
|
), |
|
supervised_keys=None, |
|
homepage=_URL, |
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
data_urls = {} |
|
for split in ["train", "validation"]: |
|
data_urls[split] = [ |
|
_DATA_URL.format(split_suffix=split, index=iindex) for iindex in range(_N_SHARDS_PER_SPLIT[split]) |
|
] |
|
|
|
train_downloaded_files = dl_manager.download(data_urls["train"]) |
|
validation_downloaded_files = dl_manager.download(data_urls["validation"]) |
|
|
|
return [ |
|
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepaths": train_downloaded_files}), |
|
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepaths": validation_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 |