Files
soprano-factory/dataset.py
T
Nighthawk 9b7dd275c7 Refactored training pipeline to use YAML config and uv
- Move hyperparameters from hardcoded script values to `config.yaml`
- Replace pip requirements with `pyproject.toml` and `uv` support (CUDA 12.6)
- Refactor all scripts to use `pathlib` for robust path handling
- Optimize `generate_dataset.py` with GPU acceleration
- Register quantizer constants as buffers for proper device mapping
- Update README with new installation and usage instructions
2026-01-18 01:13:38 -05:00

24 lines
757 B
Python

import json
import pathlib
from torch.utils.data import Dataset
class AudioDataset(Dataset):
def __init__(self, path):
# Convert string path to Path object if necessary for consistency
self.path = pathlib.Path(path)
with open(self.path, encoding='utf-8') as f:
self.dataset = json.load(f)
def __len__(self):
return len(self.dataset)
def __getitem__(self, idx):
text, audio = self.dataset[idx]
# Format: [STOP][TEXT]<text prompt>[START]<audio tokens>[STOP]
# Optimization: Use a generator expression for joining tokens
audio_tokens = ''.join(f'[{x}]' for x in audio)
res = f"[STOP][TEXT]{text}[START]{audio_tokens}[STOP]"
return res