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.
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.
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.
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.
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.User: and Assistant: roles. The new parser reads those roles and skips
any block that doesn't have both.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.
HOLD
(keep sounding), REST (silence), BAR (bar line) and start, end and padding
markers. Nothing was downloaded.Here is how the first beats of a chorale look to the model:
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.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.
See both scores side by side → · Full token catalog → · All the code on GitHub (MIT) →
HOLDThe 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.
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).