LIVENew with Anna Willstedt: AI, AI, AI! WTF is going on? A live conversation where your questions leadNew: AI, AI, AI! WTF is going on?
mk
SV
Hobby project

Pytte

A tiny language model that writes Swedish children's stories. I trained it from scratch on my laptop, to understand how a language model actually works.

Everything below runs in your browser. Nothing is sent anywhere.

The same opening, the same random seed, six models. Drag the slider and watch language take shape: from loose sentences at 0.3 million parameters to a story at 7. Pytte writes in Swedish. The default opening means “Alma lives in a small cottage in the forest. One day”.

The model files are 0.4–16 MB and load only when you pick them.

See what happens inside

Type a sentence and follow it through the model: how it is split into pieces, which words look at each other, how the answer takes shape layer by layer, and how chance picks the next word. Everything is computed in your browser, with the model's own numbers.

Open Inside Pytte
Table from Inside Pytte: the model's guess for the next word after each layer, for the sentence Alma bor i en liten. The guess goes from liten to stuga and finally stad.

How Pytte works

Pytte does one thing: it guesses the next piece of text. The picture shows the way from what you type to that guess. Click a part to see what it does and how big it is.

Why I did this

I wanted to understand every part of a language model: how text becomes tokens, what attention does, what a layer is, and why the model can end up writing a sentence. The only way I know to really understand something is to build it.

So I built one. No existing models, no paid services, no budget at all. The same kind of architecture as the large models, only thousands of times smaller, trained on my MacBook in between five minutes and half an hour.

Everything was documented while it was built: every run, every measurement and every mistake is in a log. That way I keep learning the whole time, and the lessons are what I want to share.

Pytte in numbers

6
models, from 0.3 to 15.7 million parameters
120,000
Swedish children's stories as training data, generated locally
5–30 min
training time per model on a MacBook Pro
0.4–16 MB
per model, in a single file
0 kr
budget. Only electricity.

What I learned

  1. 01

    It takes surprisingly little

    A model with a third of a million parameters writes grammatical Swedish sentences. At about one million it writes short, coherent stories. That model is 1.4 MB and trains in eight minutes.

  2. 02

    The data decides more than the model

    My first models could not form plurals, whatever their size. The stories were about one child and one ball, so they had hardly seen a plural. When 40 percent of the new stories were written with several things in the plural, every model got it right, even the smallest. A model can do what its data shows.

  3. 03

    A model can learn a template instead of a language

    The first version of the data was too uniform: every sixth story opened with the same sentence. The models looked excellent in my measurements but fell apart on freer text. I only found out when I made a second, more varied batch of stories.

  4. 04

    Variety costs coherence

    The new, more varied stories gave better grammar, but when several children appeared the models started mixing up who was who. A mix in which the new stories have a single child kept most of both.

  5. 05

    Numbers lie unless you count twice

    Every error I found was found because two numbers did not agree: a metric divided by the wrong count, a clock that kept running while the laptop slept, junk characters in twelve percent of the training data. The errors and the fixes are in the report.

What I do not know

This is a hobby project, not research. I want to be clear about where the limits are.

Download

The report

19 pages in English with a Swedish summary: data, models, measurements, twenty findings, limitations and mistakes.

Download the report (PDF)

The models

Each file contains the model and its vocabulary and is all you need to run it. The chat versions take a request; the base versions continue a text.

ModelParametersSizeBaseChat
pytte-0.3m0.33 million0.38 MB Download Download
pytte-1m1.33 million1.44 MB Download Download
pytte-2m2.24 million2.37 MB Download Download
pytte-3m3.44 million3.59 MB Download Download
pytte-7m7.16 million7.33 MB Download Download
pytte-15m15.74 million15.97 MB Download Download

Run it on your own computer

One C program with no dependencies. Works on Mac and Linux.

cc -O3 -o run run.c -lm
./run pytte-7m-chat.bin -chat
run.c

The code and the log

All the code, the recipe for the training data, the measurements and the log of the whole project are on GitHub.

Go to GitHub

The training data

SagoSvenska: 120,000 Swedish children's stories, each with the recipe that produced it. Free to use with attribution (CC BY 4.0).

Download (zip, 49 MB)

Code and models: Apache-2.0. Data: CC BY 4.0.

Back to side projects