A small notebook
You awaken to complete silence. No phone, no news, no cars honking outside. It takes you a moment to see why: you are alone, stranded on an alien planet inside a broken starship.1
The air outside is probably unbreathable and, since you never packed a spacesuit, sightseeing is out of the question. Upon inspection, the engines seem fine, but the control program crashes every time you try to take off, with an error message you cannot make sense of (Figure 1.1). You briefly think that an alien language could probably be more understandable.
Figure 1.1 What the control program prints every time you try to take off.
Ironically, you can soon put this assertion to the test! After trying twice, you are able to turn on your computer, and you connect to the aliens’ version of the World Wide Web.2 But any page you open is just a long sequence of alien symbols (Figure 1.2).
Figure 1.2 A page of the alien web, as it appears on your screen.
You vaguely remember that modern AI systems start in much the same way. They are fed vast amounts of text during what engineers call training. By going through all those symbols, sometimes for months, they pick up patterns about how the symbols go together, and later use those patterns to answer questions and act on the world.
Could you somehow replicate this process and order food? Spare parts for your spaceship? You think hard and draw from memory a long-forgotten lecture on “language models”… You get to work by taking out your trusty notebook from your bag.
1.1 A glimpse of understanding
Can you really learn anything about a world just by drawing statistical relations between symbols you do not understand? At first sight the idea sounds absurd, yet today’s systems based on these ideas are able to solve PhD-level research problems in physics and mathematics.3 Allow me a very simple example to show how this is possible.
Back on the alien web: as you scroll through enough pages, you will notice that some groups of symbols seem to recur next to each other. In the sentences of Figure 1.3, for example, two of them keep turning up together, in different orders and surrounded by different words. You have no idea what either of them means, but you can be fairly sure that, whatever they are, they are related.
Figure 1.3 Two words that keep each other’s company on the alien web.
Consider a similar example, this time more familiar to us earthlings: Paris and France behave in exactly the same way (Figure 1.4).
Figure 1.4 Two words that keep each other’s company on our web.
Now play a game. Take a page of the notebook and start browsing the web back on Earth. Every time you meet the phrase “the capital of France is …”, write down the word that came right after it. After enough pages, the notebook looks like Figure 1.5. If you were to guess the next word based on this count alone, you would most likely say “Paris”.
Figure 1.5 The notebook page for “the capital of France is …”.
Nobody has told you what a capital is, or that Paris and France are places. Yet the notebook now holds a fact about the world: to guess well, you have no choice but to record that Paris is the capital of France. The fact came in as a statistical correlation, but it is a fact all the same.
As we will see, this tiny notebook is not so different from the internal state of an AI model. The performance of existing AI systems can be explained in good part by realizing that scaling this idea to massive amounts of text (along with very large notebooks) can create advanced representations of the world even in the absence of any explicit instruction.
For now, let us go back to the alien web, and to our (admittedly pretty small) notebook.
1.2 Words and letters
What we began sketching in our notebook in the last section is the first step towards what scientists call a language model. Broadly speaking, a language model is a system that tells us how probable it is to come across a given piece of text. For example, an English language model could tell us that “the cat sat on the mat” is fairly probable; “the cat sat on the hat” a bit less; “mat the on sat cat the” quite improbable; and so on (Figure 1.6).
Figure 1.6 A language model takes a piece of text and returns its probability.
It may sound complicated, but a simple language model can be built with a small extension of what we were already doing: first, we collect a lot of text (the more the merrier, as we will see); then, we count how often different words appear together, and we write the results down in our notebook, one page per word (which has now unwittingly become our first language model).
In the example before we were focused on a single sentence, “the capital of France is …”. However, if we were to count all possible combinations of words in the English language, we would quickly exceed our small notebook! For example, a young adult who grew up speaking English knows about 40,000 words.4 Any of them can be followed by any other (or by itself, as in “very very”), so there are 40,000 × 40,000 = 1.6 billion possible pairs: reading them aloud at one per second, without sleeping, would take about fifty years. If we take every word in the Oxford English Dictionary, about half a million, the pairs become 250 billion.5
There is another problem. Is “Paris” the same word as “paris”, or “Paris’s”? Are “run”, “runs”, “running” and “ran” one word or four? Keeping them separate feels strange, yet merging them (for example by writing everything in lowercase and cutting off the endings) will sometimes lose information: “US” and “us”, for example, become the same word.
For this reason, most language models divide text into smaller, more manageable units: bytes, letters, or short sequences of letters known as subwords. For simplicity, we will work with letters for now:6 just by inspection we can see there are 27 unique symbols in whatever alphabet the aliens are using (Figure 1.7).
Figure 1.7 The 27 symbols of the alien web: 26 that look like letters, plus the space between words, shown as the last symbol, which we also count as a separate symbol.
Counting by letters makes the problem more manageable: instead of 1.6 billion pairs of words, our notebook needs only 27 × 27 = 729 numbers, few enough to fit on a few pages. The trade-off is that a letter on its own means nothing, so any prediction we make from pairs alone will probably be limited. In any case, we have to start somewhere!
1.3 Counting pairs of symbols
Now that we have our list of symbols (called the vocabulary, or dictionary, of the language model), we start browsing at random over the alien web, and we simply count all pairs of symbols that we see. After looking at a few pages we stop, and we convert our counts into probabilities. This counting is the training we met at the start of the chapter, in its simplest form, and the pages we count are the model’s training data. Bigger models learn in more complicated ways, but they too are trained on a collection of text.
Figure 1.8 The notebook page for t after meeting it a hundred times in the training data.
For example, suppose that after a few sentences we have met the symbol t a hundred times. Thirty-two times the next symbol was h, twenty-eight times it was a space, eleven times o, and so on (Figure 1.8). Dividing each count by a hundred gives the probabilities: whenever we see t, the next symbol is h with probability 32% and a space with probability 28%. We do the same for every symbol, space included.
How many pages do we need to look at, that is, how large should our collection of training data be? Intuitively, common pairs of symbols will be encountered frequently, while rare pairs will take a bit longer, and some pairs of symbols we will never meet. For now we can say that after about ten pages of text, most of the probabilities in Figure 1.8 reach a value that stops oscillating (we will look at this more closely in the next chapter), which is a sign the language model has been “trained” well. The final numbers fit into a short table that we can jot down in the notebook.
Figure 1.9 Building our first language model. Each symbol and the one after it add a tally to one cell (top). After enough pages, the whole notebook is a table of 27 × 27 cells, one row per symbol, with darker cells where the next symbol is more likely (bottom). The highlighted row corresponds to the values of Figure 1.8.
Reading the table (Figure 1.9) takes a little practice. Each row corresponds to one symbol, shown on the left. If you pick one and run along its row, the darker the cell, the more likely the corresponding symbol shown on top is to come next. The highlighted row is t: its darkest cell is under h, and the next darkest is the space, in the first column.
Now look closely at the first column. Some rows, such as d and y, are darkest there, which means these symbols usually end a word; the first row, the space, works the other way around and tells us which symbols tend to start one. Near the bottom, one row has a single dark cell: whenever q appears, the next symbol is u, with only a single exception. And more than a quarter of the cells (200 out of 729) are completely empty: those pairs never showed up, not even once, in everything we read. We still have no idea what any of these symbols mean, and yet the notebook has already learned quite a lot about how they behave.
Write a text as a sequence of symbols . The model in our notebook makes a very strong assumption: each symbol depends only on the one before it. The probability of the whole message then becomes a product of entries read from the notebook: Each entry is a ratio of two counts: In Figure 1.8, for example, the probability of h after t is 32/100.
Scientists call this type of language model a bigram (or 2-gram) model: gram comes from the Greek gramma, which is used to denote something that is shown or written (as in telegram), and bi- means two, so a bigram is simply a pair of written units, letters or words.
Counting triples gives a trigram model, and in general an n-gram model counts runs of n units (we will do this in the next chapter). A sequence produced this way is called a Markov chain, after the Russian mathematician Andrey Markov. In 1913 he counted pairs of vowels and consonants in the first 20,000 letters of Pushkin’s Eugene Onegin, the first time anyone treated a text as a chain of symbols, each depending on the one before.
1.4 Using a language model
Building a language model was a nice distraction from your current predicament, but after spending one day sorting alien symbols from your screen and writing them down into the notebook, you wonder how it can help you in any meaningful way.
To understand this, recall that given some text the language model can tell us how common it is to find that text “out there” on the web (see the box “How probable is a word?”). As you stare at your big table of probabilities, however, you realize that a nice side effect is that it is equally easy to generate text by picking symbols according to how probable they are. We already did this implicitly with our Paris / France example from Section 1.1, when we guessed the word that comes after “the capital of France is”. If this works, you could start answering all your alien emails!7
Take a short piece of alien text, the, with a space before and after it, as it would appear in the middle of a page. The probability table in Figure 1.9 gives us the probability for one pair at a time: a space is followed by t with probability 15%; t by h with probability 32%; h by e with probability 43%; and e by a space with probability 37%. Under our model, the probability of the full text is the product of the four probabilities, which is easier to compute with decimals (15% is 0.15): that is, a little under 1%: about once in every 130 places where a word could start, we should expect to find exactly this one. Now shuffle the same three symbols into teh. The first step is the same, but t is rarely followed by e (8%), e almost never by h (0.2%), and h seldom ends a word (10%): about three thousand times less probable.
Given a piece of text we want to continue, our language model tells us the symbols with the highest probability of being the following one. To use this information we can take the last symbol of the text, look up the table in Figure 1.9, and choose the symbol corresponding to the strongest cell (or, in general, to any cell with a sufficiently high probability). We can repeat this process starting from the symbol we just selected: do this many times, and we can generate text of any length you wish.8
Let’s try it out! You decide to browse to a random forum online, find what appears to be a promising question, and generate some answer using the question as a starting point (Figure 1.10).
Figure 1.10 Generating text one symbol at a time. Look up the row of the last symbol (highlighted), take the most probable next symbol, add it to the text, and repeat.
Although you do not really know what happened,9 you just stumbled on a technical forum, where an alien is wondering why its car keeps crashing after a software update.10 You type a helpful response, twice (Figure 1.11). Translated into plain English, your first answer, built by always taking the strongest cell, reads “the the the the the the”. Embarrassed, you try again. This time, at each step, you pick the next symbol at random, giving more probable symbols a higher chance of being chosen (a method called sampling). Your second answer reads “ugaindid he as thee antt cckee ainist an se tis an te a me”, which a generous reader might take for a line of Old English. You never receive an answer.
Figure 1.11 The first alien contact went poorly. Damn you, unresponsive driver!
What went wrong? Look again at how your answers were made. At every step the language model from our notebook looked at a single symbol, the last one: of the driver’s whole question, it never saw anything but the final space, so it could not possibly have said anything about cars or updates. A better model has to look further back: at the last two symbols, say, instead of one, or three, or four… In the parlance of AI models, we need to work on the context of the answers!
- c. 850 In Baghdad, the philosopher al-Kindi writes the oldest known guide to breaking secret codes. He counts how often each symbol appears and compares the counts with the letters of a language he knows.
- 1948 At Bell Labs, Claude Shannon writes imitation English without filling any tables: he opens a book at random, reads until he meets the letters he has just written, and copies the one that follows. His triplets write “IN NO IST LAT WHEY CRATICT FROURE BIRS GROCID PONDENOME OF DEMONSTURES OF THE REPTAGIN IS REGOACTIONA OF CRE”.
- 1976 At IBM, Frederick Jelinek’s group recognizes speech with the help of tables of word triplets. For the next thirty years, most speech recognition and machine translation runs on counts like these.
How did you get here from a monastery? That’s a good question and it deserves a much better narrator than me.↩︎
The attentive reader may ask how you managed to type in a working web address. Or how you got onto the Wi-Fi. An attentive reader may have a lot of questions. The only sensible answer is: yes.↩︎
In September 2026, for example, OpenAI announced that its models had settled one of the Clay Millennium Prize Problems, on the equations that describe how fluids move. At the time of writing, mathematicians are still scrutinizing the formal proof and its scope.↩︎
The estimate counts “run”, “runs” and “ran” as one word.↩︎
There are also other technical issues: written Chinese, for example, does not put spaces between words, so before counting anything we would have to decide where each word ends.↩︎
Subwords will make their appearance in Chapter 4.↩︎
Sadly, they all turned out to be alien spam.↩︎
This is known as autoregressive generation, since the model is using its own predictions in a continuous loop (auto- in this context means “self”). Most language models today are of this kind. Alternatives exist, but they do not change the core arguments of this book.↩︎
And you start feeling eerily like the man in Searle’s Chinese room, who answers questions written in Chinese by following a rulebook, without understanding a word of them.↩︎
It turns out software updates make life more miserable for everyone in the universe.↩︎
Sources
Passages cited in this chapter.