korean-newstext-dump / newstext.py
Sieun Park
Upload folder using huggingface_hub
91bf55c
raw
history blame
1.17 kB
import datasets
import os
from datasets import DatasetBuilder, SplitGenerator, DownloadConfig, Split
from datasets import GeneratorBasedBuilder, SplitGenerator, Split
class TextDataset(GeneratorBasedBuilder):
VERSION = "1.0.0"
BUILDER_CONFIGS = [
datasets.BuilderConfig(name="text", version=VERSION, description="Text data"),
]
def _info(self):
return datasets.DatasetInfo(features=datasets.Features({'text': datasets.Value('string')}))
def _split_generators(self, dl_manager):
train_path = "./train/new_format_data.txt"
val_path = "./val/new_format_data_val_removedup.txt"
train_path = dl_manager.download_and_extract(train_path)
val_path = dl_manager.download_and_extract(val_path)
return [
SplitGenerator(name=Split.TRAIN, gen_kwargs={"filepath": train_path}),
SplitGenerator(name=Split.VALIDATION, gen_kwargs={"filepath": val_path}),
]
def _generate_examples(self, filepath):
with open(filepath, encoding="utf-8") as f:
for id_, line in enumerate(f):
yield id_, {"text": line.strip()}