File size: 2,046 Bytes
c0c3c21 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
import datasets
import os
import logging
import lm_dataformat
_DESC = """
BinhVQ news corpus version 2021 (~20M records)
https://github.com/binhvq/news-corpus
Preprocessed:
- Read mongo dump and export to jsonl
- Clean content with Beautifulsoup
- Concatenate title, sapo and content
- Remove exact match sha256
- Shuffle and split train / val (0.01)
**IMPORTANT**: Please run `pip install lm_dataformat` before load this dataset
"""
_REPO_URL = "https://huggingface.co/datasets/imthanhlv/binhvq_dedup/tree/main/"
_URLS = {
"val": "val.jsonl.zst",
}
try:
import lm_dataformat
except ImportError:
print(
"Can't import lm_dataformat, please run pip install lm_dataformat and try again"
)
exit()
class BinhvqConfig(datasets.BuilderConfig):
def __init__(self, **kwargs):
super(BinhvqConfig, self).__init__(**kwargs)
class Binhvq(datasets.GeneratorBasedBuilder):
BUILDER_CONFIGS = [
BinhvqConfig(
name="plain_text",
version=datasets.Version("1.0.0", ""),
description="Plain text",
),
]
def _info(self):
return datasets.DatasetInfo(
description=_DESC,
features=datasets.Features({"text": datasets.Value("string")}),
homepage="https://github.com/binhvq/news-corpus",
)
def _split_generators(self, dl_manager):
downloaded_files = dl_manager.download_and_extract(_URLS)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={"filepath": downloaded_files["val"]},
),
datasets.SplitGenerator(
name=datasets.Split.VALIDATION,
gen_kwargs={"filepath": downloaded_files["val"]},
),
]
def _generate_examples(self, filepath):
logging.info(f"Generating examples from {filepath}")
reader = lm_dataformat.Reader(filepath)
for doc in reader.stream_data():
yield {"text": doc}
|