shu / shu.py
shjwudp's picture
fix: Fix split generators
66cc7f1
raw
history blame
1.55 kB
import json
import gzip
import datasets
logger = datasets.logging.get_logger(__name__)
_DESCRIPTION = """\
shu is a chinese book dataset.
"""
class ShuConfig(datasets.BuilderConfig):
"""BuilderConfig for shu."""
def __init__(self, **kwargs) -> None:
"""BuilderConfig for shu.
Args:
**kwargs: keyword arguments forwarded to super.
"""
super(ShuConfig, self).__init__(**kwargs)
class Shu(datasets.GeneratorBasedBuilder):
"""shu: Chinese book dataset."""
BUILDER_CONFIGS = [
ShuConfig(
name="plain_text",
version=datasets.Version("0.1.0", ""),
description="Plain text",
)
]
def _info(self):
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features({
"name": datasets.Value("string"),
"text": datasets.Value("string"),
}),
homepage="https://github.com/shjwudp/shu",
)
def _split_generators(self, dl_manager):
train_text = dl_manager.download("books.jsonl.gz")
return [
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": train_text}),
]
def _generate_examples(self, filepath):
logger.info(f"generating examples from = {filepath}")
key = 0
print("filepath", filepath)
for line in gzip.open(filepath, "rt", encoding="utf-8"):
j = json.loads(line)
yield key, j
key += 1