brwac / brwac-clean.py
nskwal's picture
Update brwac-clean.py
2b28d41
raw
history blame
2.25 kB
# coding=utf-8
import collections
import gzip
import datasets
logger = datasets.logging.get_logger(__name__)
_FILES = ['10CGDFvfMddPmbkXiM4ntGZ75UyLAEX9N','1-uv2ALG5C7P02tAnOrRVoAyHsykWOTpg','10NUJo7Uf-Y1K1HS_Rj1wXPjEK6BsCnsR','1-xMQDKAssrgPs21plEI3wbn5sNmd5j_U','102iMMbfkInQwvIz8sLpz6AVgOhJFLcqo','10kZHAmyTpSWWVznqyWeSTYVJXq76cxmq','1-v2yDhV_f-eUSokNaNuy-iqLlXb2aQk-','108F-u0xgjGckwaprGidkP_PFUaiStEro','10taj31jPdDCBdla-2obITSn9LlllNC7D','111_rEBLm0V3yLZjBiAazUd25qDbwVE-O','10K1KGWjKeEOvvxjY5SHDBxOQNWWGCKmm','10YelrSn-sjGptw2ns5uZUEMSa58VNmF1']
_BASE_DATA_URL = "https://drive.google.com/file/d/"
class BrwacCleanConfig(datasets.BuilderConfig):
"""BRWAC-clean corpus."""
def __init__(self, **kwargs):
# Initialize the base class.
name = "brwac-clean"
description = "brwac-clean dataset"
super(BrwacCleanConfig, self).__init__(name=name, description=description, **kwargs)
# Additional attributes
self.base_data_url = _BASE_DATA_URL
class BrwacClean(datasets.GeneratorBasedBuilder):
"""BRWAC corpus."""
BUILDER_CONFIGS = [
BrwacCleanConfig(
version=datasets.Version("1.0.0"),
)
]
BUILDER_CONFIG_CLASS = BrwacCleanConfig
def _info(self):
return datasets.DatasetInfo(
features=datasets.Features({"id": datasets.Value("int64"), "text": datasets.Value("string")}),
supervised_keys=None,
)
def _split_generators(self, dl_manager):
data_urls = [self.config.base_data_url + data_filename for data_filename in _FILES]
downloaded_files = dl_manager.download(data_urls)
return [
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepaths": 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:
with gzip.open(open(filepath, "rb"), "rt", encoding="utf-8") as f:
for line in f:
feature = id_, {"id": id_, "text": line.replace("<END>", "\n").rstrip()}
yield feature
id_ += 1