Previously: Chapter 2 - Why did AI get so good so recently?

Chapter 3

In the last chapter, we discussed how transformer models allowed us to train AI models that could understand human language and generate more of it, like an extremely high quality autocomplete. But this isn’t how you and I interact with AI most of the time. We don’t provide it with partially completed phrases and look for completions. We send a question in a chat and get a reply, or closer to the cutting edge, we ask an AI to do something and watch it happen. In this chapter I will help you understand how AI-based products leverage “autocomplete” to do all sorts of interesting things.

ChatGPT

GPT-3 was released in 2020 and turned a lot of heads – you could use it to generate text in ways that nobody had been able to before. But for most people, it wasn’t much more than a cool toy. Modern AI didn’t really take off as a useful tool for the public at large until ChatGPT came along.

ChatGPT was a product that leveraged the GPT-3 model to provide the now-iconic chatbot experience. Ask a question, receive a reply. Continue the conversation as long as you want to or start a new one. Marvel at the depth of understanding and knowledge that a computer could display in its answers. In no time at all, people were chatting in order to research products, to learn about topics they had always been curious about, to plan projects or trips – whenever texting an extremely knowledgeable, infinitely patient friend might be helpful, people were turning to ChatGPT.

The key from getting from A to B was realizing that whatever kind of document GPT-3 thought it was reading, it would produce more of that kind of document. It was trained on every kind of document produced by mankind, and very few of those documents suddenly veered from Shakespearean sonnet to double-entry accounting ledger midway through. If the input seemed to be a children’s book, then the output would be more of that children’s book. If the input seemed to be a recipe blog post, then the output would be 20 more paragraphs about the author’s childhood hatred of raisins before it finally spit out the ingredient list.

If the input looked like the log of a chat between two people, then the output would be more messages in that chat log. So at a very basic level, this is how ChatGPT operates. When you type “Hello, ChatGPT!”, it wraps your message up inside of a document like this:

Record of a chat conversation between a human and a very smart, very helpful robot named ChatGPT.

Human: Hello, ChatGPT!

ChatGPT:

Then it uses the latest GPT model to keep adding more to the document until it gets to the end of ChatGPT’s next message, and it sends that message back to the user as ChatGPT’s response. Wrapping and unwrapping messages in documents and sending them back and forth between different computers are all boring, traditional programming sorts of things. Old hat. The magic all came from the quality of the autocomplete that the GPT model could provide, and a clever idea to harness it into a nice experience for the user.

We’ll come back to this, but let’s just note it here for emphasis – the model is not ChatGPT. The model is just for predicting what text comes after some other text. It can just as well predict what a space alien named Zqirb or a medieval king who speaks Latin would say next. Inventing the character “ChatGPT” and asking it to predict what this character would say just turned out to be an effective way for everyone to leverage the model’s abilities.

Tool use

ChatGPT and its imitators from other AI companies took the world by storm and chat experiences remain the most common way that GPT models are leveraged. “Chatting” with a model by itself had a number of fun or interesting uses: collaborative story-telling, patient tutoring, brainstorming projects, or composing emails the users didn’t want to write themselves. It was mind-blowing that a computer could suddenly do all of this. But it only went so far.

Pure chat experiences like this could only get things done as fast as the human side of the conversation could make good use of the responses from the model. Pretty soon developers started to think about ways that the models could use tools to accomplish things on their own. The earliest versions of this were just tools to craft better responses for the user in the chat: what if the user was asking a question about current events or a new website? How could the model know about these things when they didn’t exist while the model was being trained? The answer was to give the model the ability to search the web to craft its answer.

This sounds almost nonsensical at first – GPT models predict what comes next in some text. What does it mean to say that they could use a tool? This is where another clever idea like chatting with a bot came in.

The easiest way to understand it is to revisit that document which we said powers ChatGPT:

Record of a chat conversation between a human and a very smart, very helpful robot named ChatGPT.

Human: Hello, ChatGPT!

ChatGPT:

To start using web search, the document would be changed to something like this:

Record of a chat conversation between a human and a very smart, very helpful robot named ChatGPT.** ChatGPT answers right away if it knows the answer but it also searches the web if it needs to learn more before answering. When it searches the web it looks like this: ChatGPT: WEB SEARCH “my question”

Human: Hello, ChatGPT! What movies have come out recently?

ChatGPT:

A likely prediction from the model would be that ChatGPT would search the web before it answered. So the next part of its prediction might be something like this:

ChatGPT: WEB SEARCH “recent movie releases”

Then the code that is using the model is programmed to look for the “WEB SEARCH” keyword, and when it sees it, it should actually run the search and put that back in the document. After that happens, the model is asked to predict what comes after something like this:

ChatGPT: WEB SEARCH “recent movie releases”

WEB SEARCH: 1. Jurassic World, 2. Superman, 3. Fast and Furious XIII

ChatGPT:

Then it can make a prediction about what ChatGPT would reply that’s informed by the results of the web search.

That same approach was eventually put to use for many other types of tools, some of which have effects in the real world beyond just informing the response that ChatGPT makes to the user. The beginning of the document might say that ChatGPT has access to tools that can send emails or make reservations at restaurants, and then when the model predicts that ChatGPT would use those tools, the code which uses the model makes it actually happen.

Wrapping up

We have now walked through the fundamental capabilities of modern AI. If you take a minute to stop and think over what we have covered, you should be able to go step by step from “a model multiplies and adds some numbers to get a result” all the way to “I talk to a robot and it books a hotel for me”. Even though the end result seems magical, I hope you have some idea how the trick is pulled off. Let’s review:

  1. Machine learning models: Take in some numbers, do some math, spit out a different number
  2. Training: Tweak the math that the models do until the numbers it spits out are useful
  3. Transformer: Design the math a certain way so that the models get better and better the more training we do
  4. GPT: Train a model that predicts what text comes next
  5. ChatGPT: Turn a GPT model’s predictions into a 2-way chat with an imaginary robot
  6. Tool use: Make the imaginary robot use tools

I hope that was interesting to you, but I didn’t walk through it all just to satisfy idle curiosity. In the chapters ahead we will talk about important questions such as: what are its limitations or weaknesses? What objections do people have to it? When is it right or wrong to use it? As I said at the beginning, these are important discussions for serious people. I have no interest in asking you to take anything on my authority. I want you to be fully capable of thinking about these questions for yourself so that you can be convinced of the answers in your own mind.


Previous: Chapter 2 - Why did AI get so good so recently?