Previously: Chapter 1 - What is AI?

Chapter 2

You now know at a fundamental level what an AI model is, how it is produced, and how it does its work. But here are a couple questions you should be curious about at this point:

  1. If neural networks have been around for such a long time, why did they only get good in the last few years?
  2. How does taking a number and producing a different number help a computer understand human language or generate an image?

In this chapter I’ll give you an inkling on both questions by explaining the developments that made AI quality explode in the past few years.

Challenges with training

I said in the last chapter that the training loop is simple, but it’s not easy. First of all, it took until the late 80s before we could do step 3 (“Tweak all the weights just a little bit to move the output closer to the right answer”) reliably for a neural network of any size and shape. When there are trillions of them, you can’t just change all the numbers randomly and check if things got any better! But fortunately, mathematicians worked out clever ways to adjust each weight in a way that moves a given input slightly closer to the desired output.

But this by itself wasn’t enough, because we found that models trained this way tended to hit a wall eventually. They would get better up until a certain point, and then running more loops just wouldn’t significantly improve the output any more. The technical term for this is reaching a local maximum. Think of it like trying to navigate a corn maze with a compass – you know which way the exit is, and you are trying to always move in that direction. If it’s a very boring maze then you might get through it that way – e.g. if it was more of a corn hallway. But for most mazes, you would eventually reach a point where you don’t have any moves that will immediately take you in the direction of the exit. If that’s your only rule, you’ll get stuck forever!

All machine learning models get stuck a some point which is less than the theoretical best that they can be. But for most of their history, that point has just been too low to be useful for the tasks we expected “AI” to solve. There were plenty of specialized tasks they were useful for: neural networks were successfully used for handwriting recognition (think of old PDAs), spam filtering, and trend forecasting. But they always got stuck before they were good enough for really challenging jobs, like understand human speech.

Breakthrough in neural network structure

Researchers developed countless hours to exploring different sizes and shapes of neural networks and different ways of training them to push back they point where they would get stuck. Things improved gradually over time. But the breakthrough came around 2017, when Google’s research arm developed a way of structuring the neurons in a network called “transformers.” I am not going to try to explain the details of how and why they work, partly because I don’t fully grasp it myself. But suffice it to say that they immediately empowered AI researchers to make much bigger models and train them much longer than before.

In the years that followed this breakthrough, the public was still mostly unaware of what had happened. This was just because it took time to a) identify the areas where transformer-powered AIs could be most useful and b) spend the time and money it took to throw more and more massive amounts of data at larger and larger models. The public finally caught on in 2020 when OpenAI released GPT-3. “GPT” stands for “Generalized Pre-trained Transformer”. OpenAI’s product was a transformer-based neural network which was trained to understand and predict human language.

Neural networks in use

So far I’ve only described how neural networks take one number and turn it into another number. You might be thinking that this sounds useful for math problems, but not so useful for anything else. How can a neural network “understand” or “produce” human language by doing math?

You probably already know that all computer data is represented as numbers. Text (like what you are reading now) is encoded by representing each letter or symbol as a different number. Colors are encoded as a number along a color scale. Images are encoded as a list of colors at each pixel in the image. So at a basic level, we can encode an input (say the phrase “Hello, ChatGPT!”) as a series of numbers, feed the numbers into a neural network, and then convert the numbers that come out back into text.

Here’s how we could train a neural network like that:

  1. Accumulate a huge list of phrases and responses.
  2. Feed each phrase in.
  3. Check how close the output was to the expected response.
  4. Update the model weights.

But this approach wouldn’t generalize. A model that we trained this way could only answer certain known phrases with other known phrases. No matter how good it got at that, it wouldn’t really look like intelligence. So this is not how GPTs are trained.

GPTs are “generalized” because at their heart, they are not trying to produce a response to the input. They are trying to predict what would come next after the input. So if the input is “My day is going”, the output is the next word, like “well” or “poorly”. You’ve seen this in action in a very small way since the early 2010s with autocomplete on your phone. A GPT is just a very, very good autocomplete.

There are interesting aspects of this which make GPTs generalized. If your output is “what comes next” after the input, then you can always turn around and use that output as your next input to get output that’s as long as you want. “My day is going” -> “My day is going well” -> “My day is going well because” -> “My day is going well because it” -> “My day is going well because it is” -> “My day is going well because it is sunny.”

That’s not too surprising, you’ve probably played around with that on your phone’s autocomplete as well, but it doesn’t give very good results, does it?

What makes GPTs so effective

That’s because the quality of the next word depends on understanding of the previous words and “common sense” about the world, and the tiny autocomplete models developed 15 years ago to run on your phone couldn’t have much of either.

Understanding the words that came before starts with grammar – recognize the jobs that each word is playing in the sentence based on the rules of human language. This is the kind of thing that neural networks could manage pretty well even before transformers came along, and your phone’s autocomplete is doing some of that. But grammar alone isn’t enough for understanding.

Compare these two sentences:

  1. “Joe’s daughter Sally walked into the room and Joe put her on the phone.”
  2. “Joe’s pet cat Mrs. Wiggles walked into the room and Joe put her on the phone.”

You probably interpreted the phrase “put her on the phone” very differently in each sentence: “let her talk to the other person on the phone” vs. “physically set her on top of the phone”. But the grammar of the original sentences are identical! To understand the natural meaning of each, you needed to know more than the grammar. You needed to know that daughters can talk on the phone but cats cannot.

This is also true for generating a “next word.” Quick, complete this sentence: “I stopped at the florist on my way home because it was Valentine’s Day and I wanted to get – “. I’m guessing the first words that came to your mind were something like “flowers for my wife”, right? This is because we share these common sense facts about the world:

  1. Florists sell flowers
  2. On Valentine’s Day, men traditionally buy flowers for their wives.

These are not grammatical facts, but they were still essential to finish the sentence in a way that sounded natural. And so if we put a GPT through the training loop using many different types of human text as inputs and outputs, we eventually start training in these patterns in the world that are necessary to make the best predictions. We wouldn’t be able to think of all the things an AI needs to know and program them in manually – we tried this for decades! But if we make the neural network big enough and run enough training loops, that knowledge automatically starts to get encoded into its weights.

So this is how all of the pieces came together to make something which seemed more like real intelligence: the GPT training loop aimed to make AI models better at understanding text, generating more text, and even incorporating “knowledge” about the world. And the transformer design made it so that we could keep making those models bigger and bigger and we got better and better results.

How big? Mind-bogglingly big. State-of-the-art models today have trillions of parameters, and are trained using practically every bit of text the human race has produced, in writing or online. This is still going on! Every few months OpenAI, Anthropic, Google, and their competitors come out with an even bigger model that they spent tens of millions of dollars training, and it is a little better than the ones that came before.

Wrapping up

If you’ve been able to follow this, you really do understand the technology that we call “AI” and why it has gotten so effective recently. Nice job! In the next chapter we are going to look at the ways that we use AI – how text generation powers “chat” experiences and even “agents” that go and “do” things themselves.

PS – GPTs are for text generation. I haven’t covered the models that power image generation. They are also built on the “transformer” design, but they are used in a different way called “diffusion”. I won’t cover them in depth in this primer.


Previous: Chapter 1 - What is AI?     Next: Chapter 3 - How we use AI