File size: 1,162 Bytes
ced6b99 |
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 |
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)
|