|
from datasets import DatasetBuilder, DatasetInfo, SplitGenerator, Split |
|
|
|
class CustomJSONLDataset(DatasetBuilder): |
|
VERSION = "1.0.0" |
|
|
|
def _info(self) -> DatasetInfo: |
|
return DatasetInfo( |
|
description="Custom dataset from local JSONL files.", |
|
features={"text": "string"}, |
|
supervised_keys=None, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
urls = [f"output_json_{i}.jsonl" for i in range(2, 3)] |
|
|
|
|
|
|
|
paths = dl_manager.download_and_extract(urls) |
|
|
|
return [ |
|
SplitGenerator( |
|
name=Split.TRAIN, |
|
gen_kwargs={"filepaths": paths}, |
|
), |
|
] |
|
|
|
def _generate_examples(self, filepaths): |
|
"""Yields examples from the dataset.""" |
|
import json |
|
|
|
for filepath in filepaths: |
|
with open(filepath, "r", encoding="utf-8") as f: |
|
for idx, line in enumerate(f): |
|
data = json.loads(line.strip()) |
|
yield idx, {"text": data["text"]} |
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
from datasets import load_dataset |
|
|
|
|
|
dataset = load_dataset("path_to_this_script.py") |
|
print(dataset["train"][0]) |