Compression is intelligence
contents
A language model predicts the next token. A compressor makes a file smaller. If a model gives a text the probability , we can store that text in about bits.. The higher the probability, the fewer bits it needs, which means better model = better compressor (loss that trains a language model is ~ file size) which leads to compression being intelligence.. The Hutter Prize pays on the same idea 500,000 € (woah) for the smallest copy of 1 GB of Wikipedia.. Okay I think this is a lot of information; let's unwrap.. Some high school math is required for this one...
1. bits are probabilities
A messenger sends one of 4 symbols (A,B,C,D). It sends A half of the time, B a quarter of the time, and C and D an eighth of the time each. Each symbol is independent of the others. The goal is to send a long stream of these symbols in as few bits as possible.
The simple code uses 2 bits for each symbol: 00, 01, 10, 11. A better code gives short codewords to common symbols: 0 for A, 10 for B, 110 for C and 111 for D. On average it uses
The receiver reads bits until they make a complete codeword. Then it writes the symbol and starts again. This works because no codeword is the start of a different codeword. Codes with this property are prefix-free. Huffman's algorithm (1952) finds the best prefix code for any list of probabilities.
every codeword uses part of a budget
Put every binary string in a tree. The first row is 0 and 1, the next is 00, 01, 10, 11, and each row doubles. Choose 0 as a codeword and you can't use 00 or 01 anymore, because they start with 0 and the receiver could not tell where a codeword ends. Half of every row starts with 0, so 0 takes half the tree. 00 takes a quarter, 000 an eighth, and a codeword of length takes . All the codewords together can't take more than the whole tree, this is basically log property of trees...
with the length of the -th codeword. It's called the Kraft inequality.
The good code uses ½, ¼, ⅛ and ⅛ of the tree. These numbers are the symbol probabilities.
Solid boxes are the good code's codewords. The pale boxes under a codeword start with it, so no other symbol can use them. Each codeword's share of the bottom row is its symbol's probability.
the length of a codeword is log₂(1/p)
Read the good code as a game of yes/no questions. The first bit asks "is it A?". A shows up half the time, so one question settles half of all symbols. If the answer is no, the second bit asks "is it B?", and that settles half of what's left. C and D need a third bit to tell them apart. Each bit is a fair coin, and it halves what's still possible. A string of fair coin flips has probability (heads, tails n number of times), so a symbol with probability gets bits. Doing some mathematical gymnastics around this:
Shannon called this number the information of an event. A probability of ½ is 1 bit. A probability of ⅛ is 3 bits. A 1-in-1000 event is about 9.97 bits. Double the probability and the cost drops by exactly 1 bit. This is also just logarithm...
So the cost of a message in bits depends only on how probable it is. To compress well -> you must know the probabilities -> and that means you must predict.
2. entropy
What's the best you can do on average? Weight each symbol's cost by how often it shows up:
That's entropy. For our source it's 1.75 bits, exactly what the good code uses. Shannon proved in 1948 that no code beats it.
English is harder, because each letter depends on the letters before it. After "q" you almost always get "u", and after "sherlock holm" you almost always get "e". You don't know those probabilities, so you can't plug them into the formula.
So how do you measure it? Shannon used people. In 1951 he had people guess the next letter of a text and counted their guesses. With 100 letters of context, English came out at about 0.6 to 1.3 bits per letter.
To measure compression, Shannon needed an intelligent predictor... (did you get the hint yet?)
3. a model puts a price on text
A language model is Shannon's guesser. It reads the letters so far and gives a probability to every possible next letter.
Probability of a whole text = the probabilities of its letters multiplied together. Take the log and it becomes a sum:
Each letter adds its own cost. An expected letter costs almost nothing and a surprising one costs a lot.
The model below predicts each letter from the 5 letters before it. It trains in your browser on Alice in Wonderland and Sherlock Holmes (672k letters, lowercase and spaces only). Type something.
Each bar is one letter's cost in bits. The first letters of a word cost a lot, and the letters that finish an obvious word cost almost nothing. The model only read two Victorian books, so modern words cost more. Hover a bar for its probability.
4. cross-entropy
Models are never perfect. So what does a wrong model cost?
Back to our messenger. Say it changes: D now shows up half the time, C a quarter, A and B an eighth each. The receiver still uses the old code (0, 10, 110, 111):
A code built for the new probabilities would use 1.75. The wrong model costs 0.875 extra bits per symbol. That's worse than treating all four symbols as equally likely.
In general, reality is and your model assumes :
That's cross-entropy: what you pay when reality is and your code assumes . The extra bits on top of are the KL divergence (difference), 0.875 bits for our messenger.
With two outcomes you can plot it. Move the slider:
The cost bottoms out exactly at q = p. Any other guess costs more..
Cheapest code = the one whose model matches reality.
5. language models train on cross-entropy
How pretraining works:
- Go through a ton of text.
- At every position, check the probability the model gave to the token that actually came next.
- Loss = the average of of those probabilities.
That's the cross-entropy from section 4, on real text. ( instead of just switches the unit from bits to nats.)
So the training loss = how many nats the model needs, on average, to store each token.
Each token costs bits, where is the probability the model gave it. That's the information from section 1. costs 1 bit, costs 3 bits, and costs about 0.015 bits. Add up the costs of all the tokens and you get the size of the file:
Divide the total by the number of tokens -> that's the training loss (in bits). Minimize the loss -> you shrink the file that holds the training data. Gradient descent does this one small step at a time. (The ChatGPT post has the short version.)
How can a token cost 0.015 bits? A prefix codeword is at least 1 bit long (try "one at 0.97" in the Huffman widget), so Huffman can't do it. Arithmetic coding can. Here it is on "AB" from our messenger:
- Cut the line from 0 to 1 into one slice per symbol, each as wide as its probability. A gets 0 to ½, B ½ to ¾, C ¾ to ⅞ and D ⅞ to 1.
- The first symbol is A, so zoom into 0 to ½ and cut it the same way. B's slice inside it runs from ¼ to ⅜.
- Keep going for every symbol. At the end the whole text is one thin slice, as wide as the text's probability . For "AB" that's ½ × ¼ = ⅛.
- Send a binary number inside the slice. It takes about bits. 0.010 in binary is ¼, which sits inside ¼ to ⅜: 3 bits, the same
010that Huffman's0+10gives.
A token the model was sure about barely shrinks the slice, so it costs almost nothing. Here is the same zoom on real text, with the 5-letter model from section 3:
Each row zooms into the chosen slice of the row above. The strip at the bottom shows why the number costs about log₂(1/p) bits. The decode check rebuilds your text from that number and the model.
To turn a loss into a compression rate, divide by to get bits per token, then by the bytes per token. A loss of 2.0 nats at 4 bytes per token = 2.0 / 0.693 / 4 ≈ 0.72 bits per byte. nanochat reports its validation loss in bits per byte, so the number stays comparable when you change the tokenizer.
6. why compression looks like intelligence
What is intelligence?
- Legg and Hutter (2007): the ability to reach goals in many different environments.
- Chollet (2019): how well a system turns experience into new skills.
- Mahoney (2009): the ability to find the structure in data, so you can write it in fewer bits.
I like the last one...
Compression lines up with that definition in three ways.
1. Prediction. Arithmetic coding turns any predictor into a compressor. It works backwards too, so any compressor is also a predictor. Compress "sherlock holm", then "sherlock holme". If the second file is bits bigger, the compressor thinks "e" comes next with a probability of about .
2. The model counts too. A big model can memorize a famous text and compress it to almost nothing. Push that far enough and you could hide the whole text inside the decompressor and send an empty file. So the score has to count the model:
- Score = compressed file + decompressor (model is part of the decompressor)
That's minimum description length (MDL, Rissanen 1978). A small model that predicts as well as a big one wins, because its weights take fewer bits.
DeepMind tried this with Chinchilla 70B (Delétang et al., 2024). Trained only on text, it compressed ImageNet patches to 43.4% of their size (PNG: 58.5%) and LibriSpeech audio to 16.4% (FLAC: 30.3%). Then they added the 70B parameters to the file size, and on 1 GB of data the total was much bigger than the raw data.
3. Learning fast. The sender and the receiver start with the same random model. Then, for every token:
- Both models predict the same probabilities for the next token.
- The sender writes the real token with those probabilities. The receiver reads it back.
- Now both sides know the token. Both do the same training step on it.
The receiver trains the model again while it decodes the text, so the weights never go in the file. Every step must give the same numbers on both sides, bit for bit. One different rounding changes a probability, and every token after it decodes wrong.
File size = the sum of the losses during one pass of training = the area under the learning curve.
Learn faster -> smaller file.
An order-k model predicts each letter from the k letters before it, so section 3's model is order 5. Here are orders 1, 3 and 5 learning Alice in Wonderland from zero:
File size = the area under each curve (shaded for order 5). Order 1 learns fast and stays high. Order 5 starts slower and ends lowest.
You can also send a small trained model and keep learning from there. That only pays if the model saves more bits than it adds. TufaZip (2026) tried this on 1 GB of Wikipedia:
If the orange bar ends past the dashed line, the trained start made the file bigger. The 6-layer model predicts better and still loses by 4.14 MB. The 2-layer one wins by 0.59 MB.
There are multiple ideas around a 'perfect compressor' but we haven't built it yet..
- Kolmogorov complexity. The size of the shortest program that prints your data. A million digits of π look like noise, but a few lines of code print them, so their true size is a few lines. Every compressor in this post is a cheap search for that shortest program. No program can find the shortest program for every input, so the perfect search is impossible.
- AIXI. Marcus Hutter (2000) asked: what if an agent predicted the world with that perfect compressor? It weighs every program that explains everything it has seen, trusts the short ones most, then picks the action with the most expected reward. On paper it's the smartest possible agent (Legg and Hutter's definition at the top of this section scores it highest), but no computer can run it. The Hutter Prize (section 7) is the runnable version of the same idea.
- Sutskever's take. In his 2023 talk An Observation on Generalization, Ilya Sutskever argues that big neural nets trained with gradient descent are a practical approximation of that perfect compressor. Compressing a huge pile of data forces the net to find patterns, and the same patterns then compress (and predict) the data you care about. That is his explanation for why pretraining works.
GPT-3's loss is cross-entropy on the next token, which isn't the loss function of general intelligence... Also GPTs have no long-term memory so it's hard to get to AGI/ultimate intelligence with this architecture of course.
7. the hutter prize
Hutter turned this into money:
- 500,000 € to compress enwik9, the first 1 GB of an English Wikipedia dump.
- Score = compressed file + decompressor. MDL, from section 6.
- One CPU core, about 50 hours, under 10 GB of RAM -> no GPUs, no giant model hiding in the decompressor.
Current record: 100.4 MB, about 0.80 bits per byte (Vladimir Ivanov's fx2-cmix-T, July 2026).
Every top entry is a language model glued to an arithmetic coder. Every compressor does three jobs: transform the text, predict the next symbol, code it into bits.
The Hutter prize measures how much a small program can learn from 1 GB of text, it's quite fascinating.. I read about it the first time while watching a George Hotz video.. and now that I know some big boy math I feel like it has unlocked a new way of me thinking about AI.. It's such a simple yet groundbreaking idea.. Gives you a framework for AI.. Never had a definition of intelligence but always had one for compression and now we can treat the two as the same thing. No way I wasn't going to write about it :)
Compression is prediction is intelligence, intelligence is prediction is compression. One of the coolest facts I ever learned. So, feed in the whole internet, build a compressive model, make it really really big, and you just won the universe?