Views
No views yet
doc_ids) to prevent cross-piece attention leakage without wasting compute on zero-padding.ComposerREMI representation with Byte-Pair Encoding (2,048 vocabulary size), 12 positions per beat (triplets & rubato support), rests, chords, and pitch-shift data augmentations ($-6$ to $+5$ semitones).Bar, Position, Tempo).1ai-music-project/
2├── model.py # PyTorch MusicTransformer architecture (RoPE, SwiGLU, RMSNorm, KV-Cache)
3├── train.py # Training loop (AMP, Gradient Accumulation, W&B, Early Stopping)
4├── generate.py # Inference engine (KV-Cache decoding, CFG, Min-P, Repetition Penalty)
5├── generate_batch.py # Batch generation script for bulk sampling across composers
6├── evaluate.py # Quantitative evaluation (KL Divergence, Pitch Class Histograms, Note Density)
7├── scripts/
8│ └── tokenize_midi.py # MIDI dataset preprocessing, filtering, BPE tokenization & augmentation
9├── app.py # Gradio web application for interactive generation & audio preview
10├── checkpoints/ # Directory for trained model weights (e.g., model_best.pt)
11├── data/
12│ ├── raw_midi/ # Datasets (MAESTRO v3.0.0 & GiantMIDI-Piano)
13│ ├── processed/ # BPE tokenizer, composer mappings, tokenized PyTorch tensors
14│ └── generated/ # Output generated MIDI files
15├── requirements.txt # Python dependencies for local & cloud deployment
16└── LICENSE # MIT License1git clone https://github.com/Ururu1000/midi-transformer.git
2cd midi-transformer
3
4# Create and activate virtual environment
5python -m venv venv
6source venv/bin/activate # On Windows: venv\Scripts\activate
7
8# Install dependencies
9pip install torch miditok pretty_midi pandas scipy wandbdata/raw_midi/, then run the tokenization pipeline:python scripts/tokenize_midi.pytokens_train.pt, tokens_val.pt).python train.pytrain.py):PACK_SEQ_LEN: 4096 tokensBATCH_SIZE: 8 (Effective batch size ~56 via gradient accumulation)LEARNING_RATE: 2e-4 with Cosine Warmup SchedulerCFG_DROP_PROB: 15% probability of dropping composer tokens for CFG learningEARLY_STOP_PATIENCE: 5 validation epochspython generate.pygenerate.py)1COMPOSER = "Frédéric Chopin" # Composer steering prompt
2GENERATION_LENGTH = 1024 # Output sequence length
3TEMPERATURE = 0.95 # Sampling temperature
4MIN_P = 0.03 # Min-P confidence threshold
5CFG_SCALE = 1.2 # Classifier-Free Guidance strength
6PENALTY_WINDOW = 64 # Pitch repetition penalty context windowpython generate_batch.py.mid files will be saved in data/generated/. You can play them using any standard MIDI player or Digital Audio Workstation (DAW) like Ableton, FL Studio, or GarageBand.python evaluate.py1pip install -r requirements.txt
2python app.py.mid file for use in any DAW.| Parameter | Value | Description |
|---|---|---|
vocab_size | ~2,048 | BPE Tokenizer Vocabulary |
d_model | 768 | Hidden Embedding Dimension |
nhead | 12 | Multi-Head Attention Heads |
num_layers | 16 | Transformer Decoder Blocks |
d_ff | 3,072 | SwiGLU Hidden Layer Dimension |
max_seq_len | 4,096 | Context Window Length |