Datasets:
Delete dataset_loader.py
Browse files- dataset_loader.py +0 -78
dataset_loader.py
DELETED
|
@@ -1,78 +0,0 @@
|
|
| 1 |
-
import json
|
| 2 |
-
import datasets
|
| 3 |
-
from datasets.download.download_manager import DownloadManager
|
| 4 |
-
|
| 5 |
-
class AquaLLMDatasetConfig(datasets.BuilderConfig):
|
| 6 |
-
"""AquaLLM Dataset configuration."""
|
| 7 |
-
def __init__(self, **kwargs):
|
| 8 |
-
super(AquaLLMDatasetConfig, self).__init__(version=datasets.Version("1.0.0"), **kwargs)
|
| 9 |
-
|
| 10 |
-
class AquaLLMDataset(datasets.GeneratorBasedBuilder):
|
| 11 |
-
"""AquaLLM Dataset generator."""
|
| 12 |
-
BUILDER_CONFIGS = [AquaLLMDatasetConfig(name="default", description="Default config for AquaLLM")]
|
| 13 |
-
|
| 14 |
-
def _info(self):
|
| 15 |
-
# Bu özellikler, _generate_examples'ın çıktısıyla TAM olarak eşleşmelidir.
|
| 16 |
-
return datasets.DatasetInfo(
|
| 17 |
-
features=datasets.Features({
|
| 18 |
-
"text": datasets.Value("string"),
|
| 19 |
-
}),
|
| 20 |
-
description="""
|
| 21 |
-
AquaLLM is a dataset for training a language model on various topics related to aquariums.
|
| 22 |
-
The dataset is structured with nested categories. This loader script flattens the nested JSON
|
| 23 |
-
and converts each entry into a single text string for training.
|
| 24 |
-
""",
|
| 25 |
-
homepage="https://huggingface.co/datasets/oytunistrator/AquaLLM-Dataset",
|
| 26 |
-
license="MIT",
|
| 27 |
-
citation="""
|
| 28 |
-
@misc{AquaLLMDataset,
|
| 29 |
-
title = {AquaLLM Dataset},
|
| 30 |
-
author = {Oytunistrator},
|
| 31 |
-
year = {2024},
|
| 32 |
-
howpublished = {Hugging Face Datasets Hub},
|
| 33 |
-
url = {https://huggingface.co/datasets/oytunistrator/AquaLLM-Dataset}
|
| 34 |
-
}
|
| 35 |
-
"""
|
| 36 |
-
)
|
| 37 |
-
|
| 38 |
-
def _split_generators(self, dl_manager: DownloadManager):
|
| 39 |
-
"""Returns SplitGenerators."""
|
| 40 |
-
data_file_path = dl_manager.download_and_extract(self.config.data_files["train"])
|
| 41 |
-
return [
|
| 42 |
-
datasets.SplitGenerator(
|
| 43 |
-
name=datasets.Split.TRAIN,
|
| 44 |
-
gen_kwargs={"data_file": data_file_path},
|
| 45 |
-
)
|
| 46 |
-
]
|
| 47 |
-
|
| 48 |
-
def _generate_examples(self, data_file):
|
| 49 |
-
"""Yields examples as dicts."""
|
| 50 |
-
with open(data_file, encoding="utf-8") as f:
|
| 51 |
-
data = json.load(f)
|
| 52 |
-
|
| 53 |
-
data_count = 0
|
| 54 |
-
|
| 55 |
-
# Helper function to create text from a dictionary
|
| 56 |
-
def create_text_from_dict(item_dict):
|
| 57 |
-
text = ""
|
| 58 |
-
for key, value in item_dict.items():
|
| 59 |
-
if isinstance(value, dict):
|
| 60 |
-
# Handle nested dictionaries like "sicaklik_c"
|
| 61 |
-
nested_text = ", ".join([f"{k}: {v}" for k, v in value.items()])
|
| 62 |
-
text += f"{key.replace('_', ' ').capitalize()}: {nested_text}. "
|
| 63 |
-
elif isinstance(value, list):
|
| 64 |
-
# Handle lists like "uyumlu_turler"
|
| 65 |
-
list_text = ", ".join(value)
|
| 66 |
-
text += f"{key.replace('_', ' ').capitalize()}: {list_text}. "
|
| 67 |
-
else:
|
| 68 |
-
text += f"{key.replace('_', ' ').capitalize()}: {value}. "
|
| 69 |
-
return text.strip()
|
| 70 |
-
|
| 71 |
-
# Iterate through categories and their data
|
| 72 |
-
for category, item_list in data.items():
|
| 73 |
-
# Doğrudan listenin üzerinde döngüye girerek her bir öğeyi işle
|
| 74 |
-
if isinstance(item_list, list):
|
| 75 |
-
for item in item_list:
|
| 76 |
-
text_data = create_text_from_dict(item)
|
| 77 |
-
yield data_count, {"text": text_data}
|
| 78 |
-
data_count += 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|