processed-newstext / processed-newstext.py
Sieun Park
Rename newstext.py to processed-newstext.py
261175f
raw
history blame
1.16 kB
import json
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 = "./new_format_data_trn.jsonl"
val_path = "./new_format_data_val.jsonl"
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_, json.loads(line)