How electricalexis/notagen works
Project Type and Purpose
• Type: A multi-stage machine-learning pipeline for symbolic music generation built around a large language model (LLM).
• Purpose: Train, fine-tune, and optimize “NotaGen” to generate high-quality classical sheet music, and provide data-conversion utilities and a Gradio demo for inference.
File Structure & Architectural Patterns
• Top-level directories represent distinct pipeline stages or utilities:
• data/ → Data conversion (MusicXML ↔ ABC), indexing
• pretrain/ → Unsupervised pre-training on large corpus
• finetune/ → Supervised fine-tuning with composer/style prompts
• RL/ → Reinforcement Learning via CLaMP-DPO
• clamp2/ → External feature extractor (CLaMP 2)
• inference/ → Generating new samples from trained weights
• gradio/ → Local Gradio UI for demo & inference
• notebook/ → Jupyter prototype & visualization
• Architectural Pattern: Linear, staged pipeline with clear separation of concerns; each stage reads model weights and data indexes, produces updated weights or artifacts.
Key Insights from README
• Three-stage training: Pre-train → Fine-tune → RL.
• Data preprocessing/postprocessing for ABC notation and MusicXML.
• Dependency on external CLaMP-2 feature extractor (clamp2/).
• Optional Gradio UI for local/online demos.
Components
a. Main Components
1. Data Ingestion & Conversion (data/)
2. Pre-training Pipeline (pretrain/)
3. Fine-tuning Pipeline (finetune/)
4. CLaMP-2 Feature Extraction Service (clamp2/)
5. Reinforcement Learning Pipeline (RL/)
6. Inference Service (inference/)
7. Gradio UI & Notebook (gradio/, notebook/)
8. Model Weights Store (weights on disk or HuggingFace)
b. Relationships & Interactions
• Raw music → data/ converts to ABC/jsonl → pretrain uses this to train base LLM → outputs pretrain weights
• pretrain weights + jsonl → finetune → outputs finetuned weights
• finetuned weights → inference → generates samples (original & interleaved)
• generated samples + ground truth → clamp2 feature extractor → produces feature vectors
• features + preference rules → RL/data.py → builds preference dataset → RL/train.py → produces RL-optimized weights
• RL weights → inference → updated samples → loop for additional RL iterations
• Final weights → gradio/ & notebook/ for local demo & exploration
c. Architectural Patterns & Principles
• Pipeline pattern: Each stage consumes inputs (data, weights), produces outputs for next stage.
• Modularity: Separation of data processing, model training, feature extraction, and UI layers.
• Reusability & Extensibility: Config files in each module allow parameter tweaks; clamp2 and RL routines can be replaced or extended.
d. Technologies & Frameworks
• Python scripts, PyTorch (accelerate, optimum)
• JSONL for data indexing
• CLaMP-2 for feature extraction
• Gradio for UI
• HuggingFace for hosting model weights & Spaces