Skip to content

Instantly share code, notes, and snippets.

View MBaltz's full-sized avatar
:atom:
CTRL+L, pls

Mateus Baltazar MBaltz

:atom:
CTRL+L, pls
View GitHub Profile
@kaizenman
kaizenman / micromusic.py
Created April 5, 2026 23:33
micromusic
"""
micromusic.py - A GPT that learns to compose melodies.
Pure Python, zero dependencies, one file.
Inspired by @karpathy's microgpt. Same algorithm, different domain.
Instead of learning the pattern of names, it learns the pattern of music
python micromusic.py trains on CPU, prints hallucinated melodies
python micromusic.py --save same + saves MIDI files you can listen to
@kaizenman
"""
The most atomic way to train and run inference for a GPT in pure, dependency-free Python.
This file is the complete algorithm.
Everything else is just efficiency.
@karpathy
"""
import os # os.path.exists
import math # math.log, math.exp