How swapnoneelbarua/music-therapy-llm works
1. Overall shape
- This is a Python research codebase organized as a pipeline of stable artifacts, not a single monolith.
- The main flow is: raw audio dataset → indexed metadata → validated/preprocessed segments and features → human annotations and consensus labels → CNN benchmarks → downstream therapist/RAG modules.
2. Primary source package boundaries
- The implementation lives under src/indian_music_therapy_ai/, split by concern:
- dataset for discovery/indexing/preparation
- processing for audio preprocessing and feature extraction
- annotations for the annotation platform and consensus workflow
- training and benchmark for model experimentation
- therapist for retrieval/reasoning/recommendation logic
- cli, config, and utils for orchestration and shared infrastructure
- This separation matters because each stage writes artifacts that later stages reuse without schema churn.
3. Configuration and command layer
- The repository is YAML-driven: configs/*.yaml define dataset, preprocessing, annotation, training, benchmark, and evaluation settings.
- The CLI entrypoint is icmta via src/indian_music_therapy_ai/cli/main.py, which runs phase-specific commands like indexing, preprocessing, annotation, consensus, and benchmarking.
- utils/logging.py and config/loader.py suggest consistent logging and centralized config loading across phases.
4. Dataset ingestion and indexing
- Raw audio is expected under dataset/esraj/ and dataset/sarod/, recursively discovered by the dataset subsystem.
- dataset/indexer.py, dataset/audio_probe.py, and dataset/preparation.py generate a canonical metadata/metadata.csv plus validation and summary artifacts.
- The key boundary here is that all later processing depends on this indexed metadata rather than scanning raw files again.
5. Preprocessing and feature generation
- The processing package handles audio QC and transformation: validation, resampling, mono conversion, normalization, silence trimming, padding, segmentation, and feature extraction.
- Outputs are staged under data_processed/ and related directories: audio segments, manifests, spectrograms, and tensor/feature stores.
- Feature types are explicitly separated into their own directories (features/mfcc, features/chroma, features/energy, features/mel_spectrogram, etc.), which supports reuse by both CNN training and analysis.
6. Reusable manifests and experiment inputs
- Dataset splits live under dataset/splits/ and benchmark-specific normalized manifests under experiments/benchmark/normalized_manifests/.
- This indicates a deliberate boundary between raw annotation/processing outputs and model-ready train/val/test manifests.
- The benchmark suite consumes these manifests to ensure comparisons across backbones are repeatable.
7. Annotation platform and consensus workflow
- annotations/ contains an offline SQLite-backed annotation system with GUI support (gui.py), session/database management, segment selection, playback, validation, and export.
- The presence of consensus.py, export.py, and validation.py shows a pipeline from individual annotator records to consensus labels and quality checks.
- Artifacts include annotator statistics, agreement reports, publication tables, and consensus_labels.csv, which become another downstream dataset boundary.
8. Benchmarking and training
- training/ contains model/dataset/trainer abstractions for CNN experimentation, while benchmark/runner.py wraps repeated runs across architectures.
- The benchmark outputs under experiments/benchmark/<model>/ include configs, history, predictions, confusion matrices, metrics, and TensorBoard logs.
- Multiple backbones are represented in the repo state: simplecnn, squeezenet, mobilenetv2, resnet18, and resnet50, reinforcing that this is a comparative research suite.
9. Therapist / retrieval / reasoning layer
- The therapist package is a later-stage application layer that combines knowledge, retrieval (rag.py), recommendation logic, and local SLM integration (ollama_slm.py, slm.py).
- The README’s architecture suggests the model stack is not the end product; CNN emotion classification feeds a RAG + reasoning layer that ultimately produces music recommendations.
- This is the clearest “top-of-pipeline” boundary: learned emotion recognition is treated as an input to decision support, not the final output.
10. Interface and runtime surfaces
- app.py and .agents/skills/developing-with-streamlit indicate a Streamlit-facing interface for interactive use, while the annotation GUI uses PySide6.
- This repo therefore has multiple presentation surfaces: a command-line orchestration layer, a desktop annotation tool, and a browser-style app interface.
- Those interfaces are thin shells over the same underlying artifact pipeline.
11. Persistent storage layout
- The repo is artifact-heavy and stores state in versioned folders: metadata/, data_processed/, dataset/splits/, annotations/, experiments/, models/, figures/, results/, and database/.
- SQLite and vector-store placeholders show planned persistence boundaries for annotation records and future retrieval infrastructure.
- The diagrams should reflect that most modules read/write files rather than communicating through a live service mesh.
12. Documentation, audits, and tests
- docs/ includes architecture, protocol, and phase-specific design docs, which appear to formalize the pipeline into stages.
- scripts/ provides dataset audits and validation checks, likely used to enforce consistency across phases.
- tests/ covers dataset indexing, preprocessing, annotations, training, AI therapist behavior, and benchmark execution, mirroring the repository’s subsystem boundaries.
Main entry points: orchestrator.py Therapist · pipeline.py Processing · trainer.py Training · metadata.csv Metadata
Components 26
Core pipeline
Source packages that implement the repository's staged workflow
- Config loader · Centralized configuration loading for pipeline phases
src/indian_music_therapy_ai/config/loader.py - Indexing · Discovers raw audio and builds canonical metadata
src/indian_music_therapy_ai/dataset/indexer.py - Audio probe · Inspects source audio and captures validation details
src/indian_music_therapy_ai/dataset/audio_probe.py - Preparation · Validates and prepares indexed dataset artifacts
src/indian_music_therapy_ai/dataset/preparation.py - Processing · Coordinates preprocessing, segmentation, and feature extraction
src/indian_music_therapy_ai/processing/pipeline.py - Audio ops · Validation, resampling, normalization, trimming, and segmentation
src/indian_music_therapy_ai/processing/audio.py - Features · Builds reusable audio feature representations
src/indian_music_therapy_ai/processing/features.py - Annotation DB · Session and record persistence for annotation workflow
src/indian_music_therapy_ai/annotations/database.py - Consensus · Aggregates annotator records into consensus labels
src/indian_music_therapy_ai/annotations/consensus.py - Export · Produces reports and downstream label artifacts
src/indian_music_therapy_ai/annotations/export.py - Training · Dataset and trainer abstractions for model experimentation
src/indian_music_therapy_ai/training/trainer.py - Benchmark · Runs repeatable comparisons across CNN backbones
src/indian_music_therapy_ai/benchmark/runner.py - Therapist · Orchestrates retrieval, reasoning, and recommendation outputs
src/indian_music_therapy_ai/therapist/orchestrator.py - RAG · Retrieval and context assembly for therapy decisions
src/indian_music_therapy_ai/therapist/rag.py - Recommend · Maps model and knowledge signals to recommendations
src/indian_music_therapy_ai/therapist/recommendation.py
Interfaces
Command, desktop, and app surfaces
- CLI · Main command-line orchestrator for phase-specific runs
src/indian_music_therapy_ai/cli/main.py - App · Interactive application surface over the artifact pipeline
app.py - Annotator UI · Offline annotation interface with playback and segment review
src/indian_music_therapy_ai/annotations/gui.py
Artifact stores
Persistent dataset, feature, annotation, and experiment outputs
- Metadata · Canonical indexed metadata for all later stages
metadata/metadata.csv - Processed data · Validated audio, segments, manifests, spectrograms, and tensors
data_processed - Feature store · Reusable feature families for training and analysis
features - Labels · Annotator records, consensus labels, and reports
annotations/consensus_labels.csv - Splits · Train, validation, and test manifests for experiments
dataset/splits/train_manifest.csv - Benchmark runs · Per-model metrics, predictions, and reports
experiments/benchmark
Connections 23
- CLI → Config loader: loads · CLI resolves YAML-driven phase configuration
- App → Therapist: uses · Interactive app calls the top-level therapy workflow
- Annotator UI → Annotation DB: writes · GUI persists annotator sessions and segment decisions
- Indexing → Audio probe: inspects · Indexing uses audio probing to validate source files
- Indexing → Metadata: builds · Creates the canonical indexed metadata artifact
- Preparation → Metadata: reads · Preparation consumes indexed metadata rather than raw scans
- Preparation → Processed data: stages · Produces validated prepared artifacts for later phases
- Processing → Audio ops: coordinates · Pipeline delegates signal transforms and segmentation
- Processing → Features: generates · Pipeline emits reusable feature representations
- Processing → Processed data: writes · Stores manifests, segments, spectrograms, and tensors
- Features → Feature store: writes · Feature families are stored as reusable artifacts
- Consensus → Labels: produces · Consensus workflow turns annotator records into labels
- Export → Labels: exports · Export writes reports and publication tables from labels
- Training → Splits: consumes · Model training uses split manifests as stable inputs
- Training → Feature store: trains on · Training reuses extracted feature artifacts
- Benchmark → Training: wraps · Benchmarking repeatedly invokes the training stack
- Benchmark → Benchmark runs: writes · Benchmark runs emit configs, metrics, predictions, and reports
- Therapist → RAG: orchestrates · Top-level therapist flow combines retrieval and reasoning
- Therapist → Recommend: produces · Orchestrator returns music recommendation outputs
- Therapist → Benchmark runs: consumes · Therapy layer can depend on learned classifier outputs
- Docs → CLI: describes · Documentation formalizes the pipeline entrypoints and phases
- Scripts → Metadata: audits · Utility scripts validate dataset indexing and exclusions
- Scripts → Labels: checks · Utility scripts inspect annotation and consensus consistency