How did we get here? Part 1

Chances are, if you’re reading this, then you have used an LLM at some point in your life. In fact, even if you’re an LLM reading this you have likely called another LLM at some point too. AI adoption and awareness has grown immensely since the release of ChatGPT towards the end of 2022. As we grow nearer to the 4 year anniversary of this day I wanted to take the time to understand how we got to this position.

Over a series of posts I want to take you through the history of the development of language models in the hopes that explaining certain design decisions will help you better understand why LLMs do specific things.

There is plenty of information about how LLMs work but I think some of the decisions can sound a bit strange or unnecessary until you begin to dive into the problem of next word prediction. In doing so I think you’ll find a greater appreciation for the technology that is so easily within our reach today.

It’s difficult to remember exactly what life was like before LLMs became widespread but I want you to place yourself in a pre-ChatGPT world and imagine that I have set the following challenge to you:

Your first intuition might be to create a dictionary or lookup table of every single possible word in the english language and then to find the most common corresponding word that would come afterwards. So for instance let’s say we create a lookup table that looks like this:

If the last word is……the next word is

We can predict the next word by simply looking it up in the dictionary.

Try it yourself: edit the dictionary above, then press play to watch a word go through the machine.

the
Dictionary
  • the → cat
  • cat → sat
  • sat → on
  • on → the
  • dog → is
  • is → a
  • a → peanut
  • I → am
  • peanut → butter
the

After playing around with this a bit you’ve probably run into some problems. Firstly, if you start with a word such as the you’ll very quickly run into a nonsensical loop.

thecatsatonand around again, forever

Secondly, whilst we can edit our dictionary to ensure it’s non-circular we can still end up with gibberish as in the case below:

dogisapeanutbutter✓✓✓✓each neighbouring pair is a valid lookupbut the sentence as a whole is nonsense ✗

Thirdly, each word can only point to a single next word. Consider the word I in our dictionary: it is always going to point to am even though there are plenty of other options.

Iamalways chosenhavenever chosenthinknever chosen

We’ve shown that solving the first problem with a non-circular dictionary leads to the second problem but you might still be feeling optimistic and sense that you can solve the third one by just increasing the number of options available to your prediction machine. So for every word in your dictionary you might want to store the three most likely words that follow on from that word.

WordNext word is one of these, each equally likely
33%33%33%
33%33%33%
50%50%
50%50%
33%33%33%
33%33%33%
50%50%

Now when the machine looks up a word it picks one of the options at random, each one equally likely. Press play, or generate a few sentences at once, to see what comes out.

the
the →
  • cat
  • dog
  • world
the

As you can see, this also runs into another problem. You can end up with sentences such as the cat is the world and whilst the dog might not be so happy to hear that it also doesn’t seem to make that much sense. The most obvious issue with this approach is that we aren’t taking into account context.

cat and world aren't related ✗thecatistheworld✓✓✓✓each neighbouring pair is a valid lookup

With this in mind we might be motivated to consider more context. The idea is that just looking at the in isolation doesn’t contain that much information, but if we have the dog we could be more informed about what is more likely to happen.

So it sounds like the problem is that we don’t have enough context. So let’s instead increase our dictionary to take in two words at a time and then the next likely word. For instance:

Last two wordsNext word is one of these, each equally likely
33%33%33%
50%50%
50%50%
33%33%33%
33%33%33%
33%33%33%
50%50%
33%33%33%

This time the machine looks up the last two words together, so give it two words to start with. Generate a few sentences and see whether the cat can still sit on the dog.

the cat
the cat →
  • sat
  • is
  • and
thecat

This looks a bit better because now the cat and dog can only do certain things and it’s now no longer possible for the cat to sit on the dog. However, there are still problems. In principle we could still end up in a loop if the dictionary allows a cycle, but more importantly we still aren’t encoding that much context. By the time we get to the pair on the, the machine has forgotten that this sentence is about a cat.

thecatsatthecatsatonthecatsatonthethecatsatonthe?cat has slid out of view: was it a cat or a dog?

At this point you may be thinking: why not store words 3 at a time, or 4, or just take n words together and keep scaling n higher? Unfortunately this runs into a wall from both directions.

With a small number of words in combination, we’ve seen every combination plenty of times, but there isn’t enough information to predict anything sensible, which is how we ended up with loops and gibberish.

With a large number of words in combination there’s plenty of information, but we’ll almost never have seen that exact sequence before. A 30,000 word context is very unlikely to appear twice anywhere in our training data, so our dictionary either has no entry for it or can only repeat the one continuation it saw, word for word.

And that’s before we get to storage: the number of possible contexts grows exponentially with n, so the table gets enormous very quickly. Drag the slider to see how quickly.

Possible word combinations to store
2,500,000,000
Chance this combination appeared in the text used to build the dictionary
almost 100%

Almost certainly seen before, so the machine will usually have an entry to look up.

Assuming a vocabulary of 50,000 words and dictionary probabilities generated from 10 trillion words of data.

Underlying all of these attempts is the same problem, whilst we think we’re providing more context to our predictor machine we aren’t actually providing any useful information about how language works. For instance, we know that a dog and a cat are similar in some ways, so if you’ve seen a sentence like: the dog sat on the mat you should be able to work out that the cat sat on the mat is a valid sentence too. Just showing probabilities of a word appearing after another, isn’t teaching the model anything useful about language and so it will struggle when it sees text that it has never seen before.

What we really want is a system that can handle a context it has never seen before by recognising that it’s similar to ones it has. This mimics how chess players approach positions. Rather than taking on the impossible task of memorising every possible positon they learn patterns and apply themes from those patterns to their games. Similarly, our language model would have to learn language patterns. If we could teach a model language patterns it will likely be more able to generate text.

Whilst you wait for part 2, you can think about how you would teach a machine that the concepts cat and dog are similar but cat and post office are not.