Lab notes · November 2, 2026

A small model that learned Bach from nothing.

We built a language model from scratch. It had no internet, no borrowed knowledge and no pretrained parts, and its only teacher was Bach's chorales. Then we gave it the opening of a chorale it had never seen and let it write the rest. This is the first trial run, unedited.

Rise Solutions LLC · trained on one Intel iMac, no GPU, in 15 minutes

Why we built it

Large AI models are trained on huge amounts of text and many borrowed parts, so it is hard to say where any answer comes from. We wanted the opposite: a model small enough to understand completely, with every source of knowledge accounted for.

The question behind it: a model that does nothing but predict what comes next, given only raw examples, can still find the structure inside them. Can it do that with music, without being told a single rule? If it can, the same method can show the patterns inside any sequence, including ones nobody can read yet.

Ground rules

No internet access, and nothing in its training that tells it the internet exists. No pretrained weights: the model starts from random numbers. No outside training data except sources approved one by one: here, Bach's chorales. No hand-editing of anything it produces.

Where it started

This project began with Hassan Habib's LLMfromNothing: a minimal, complete example of training a GPT-2-style model from random numbers on a tiny text file, testing it, and converting it for llama.cpp. His three short scripts gave us a working pipeline to run on day one, and everything below grew from them. Our thanks to him for sharing it.

What we corrected before running it

Prompt mismatch
Training split each example into User: Hello and Assistant: World!, so the model learned to write Assistant: itself. The test prompt already ended in Assistant:, so the model would have written it a second time. Fix: training now uses the same User: … / Assistant: prompt as the test and learns only the reply. After the fix it answered once and stopped.
Comment vs data
A comment said the data used no roles, while the data file has User: and Assistant: roles. The new parser reads those roles and skips any block that doesn't have both.
Our machine
Not a flaw in his code: our Intel iMac can only run PyTorch up to 2.2.2 on Python 3.12, so we pinned the other libraries (Transformers 4.x, NumPy 1.x) to versions that work with it.

The music version is new code built on his idea: a home-made note vocabulary in place of the text tokenizer, and Bach's chorales in place of the two-line text file.

What we built

Notes become tokens

Idea
A language model never sees words, only numbered tokens. Change what the numbers stand for and the same model learns music.
Vocabulary
We made our own: 75 tokens. There are 69 pitches, plus HOLD (keep sounding), REST (silence), BAR (bar line) and start, end and padding markers. Nothing was downloaded.
Time
Each bar is cut into sixteenth-note steps. Every step is exactly four tokens: soprano, alto, tenor, bass. A note's length is how many steps it keeps sounding. Silence takes up tokens just like sound.

Here is how the first beats of a chorale look to the model:

BAR P69 P65 P62 P50 HOLD HOLD HOLD HOLD HOLD HOLD P60 HOLD HOLD HOLD HOLD HOLD BAR P68 P64 P59 P52 HOLD HOLD HOLD HOLD HOLD HOLD HOLD P50 …

The model

Design
GPT-2 architecture: 6 layers, 384-wide, 6 attention heads, 10.9 million parameters, starting from random values.
Data
Bach's four-part chorales from the open-source music21 library: 351 usable pieces. 20 were locked away before training and never seen in any form. The other 331 were shifted into all 12 keys (still only Bach's notes), giving 3.47 million tokens.
Training
Two passes over the data, 15 minutes on an Intel iMac CPU. Its only task is to guess the next token; the real next token in Bach's score is the answer key.
Result
Its error on the 20 locked-away chorales (0.63) ended slightly lower than on its training data (0.67): it learned general patterns rather than memorizing.

The test: first trial run

We took one of the locked-away chorales (from Bach's Cantata BWV 4) and gave the model its opening four bars. Then it wrote eight more bars on its own, one token at a time, with a little randomness (temperature 0.9, fixed seed 0). This was the first and only run: we did not try several and pick the best.

The model's version
Bach's opening, then the model takes over at 0:10.8.
What Bach actually wrote
The same opening, followed by Bach's real continuation.

See both scores side by side →  ·  Full token catalog →  ·  All the code on GitHub (MIT) →

What it got right, and wrong

10.9M
parameters, from random
75
tokens in its vocabulary
15 min
training, CPU only
70.7%
of all tokens are HOLD

What it means, and what it doesn't

The model predicts what comes next. It cannot tell you why: it has no words for "key" or "cadence", and it never saw the hymn texts or anything about how the music feels. The patterns are inside its numbers, and explaining them is up to the person studying it.

That is also why the method is interesting for undeciphered writing. A model like this can show a script's structure (which signs behave like word endings, whether it behaves like a language at all) without knowing what it says. Meaning still needs something known to anchor it.

Next

Credits

Started from Hassan Habib's LLMfromNothing. Chorales by J. S. Bach (public domain), from the music21 corpus. Model code built on PyTorch and Hugging Face Transformers. Scores engraved with Verovio. Code: github.com/ProjectEvolutionEVE/small-llm-bach (MIT license).