What Is ChatGPT Doing? Episode 6: Why Does It Work?

John Woodard and Julio explain how embeddings work in GPT models and why they make the system effective. They walk through the technical process with visualizations, showing how language gets converted into numerical patterns that the model learns to predict.
Chapters
Hey, everybody, we're back again. I'm John Woodard and we've got Julio here. We're going back at it again. How are you doing, Julio?
Doing pretty well, John. Thanks. Thanks for keeping me here in your series. I've been really enjoying this. What are we going to talk about today?
I'm glad you're doing good. That way we don't have to cut that. I think we did a lot about embedding last time you showed me how to compute from tokens. But then let's, I guess, do more about how they're processed and maybe we can start there.
Okay. Last time I show you something like this code. Yes. These embeddings here, they are just an initial numeric representation of these words of each individual word and their position. But this is just the beginning of the story. It's not the end. The end of the story is how all these vectors are processed by the GPT model. And I can show you this image here is taking at the end. So it's a similar sequence. But now each vector hopefully contains some information about the semantic meaning of these words.
Okay, okay. Like, I'm kind of confused here because there seem to be a lot of numbers. Like, we even have pictures of numbers, actual numbers, vectors, words representing vectors. Can you show me something kind of more visual so I can get a better understanding of what's going on?
Yes. Okay. Do you remember last time we look at how we could kind of compress these long vectors into 2 or 3D and we look at digits in a 3D space. We located that. I can show you something similar for these words.
Yes, that would be helpful at this point.
Okay, so let me click to copy from Steven's blog, another one. So here what I was doing, I was using one of these networks to create these embedding vectors for all these words. And then I'm compressing them to 2D and I'm plotting them here and I'm coloring them by part of speech. So now we can start seeing how having a numerical representation of a word can be a useful thing. Because you see now if I color by part of speech, you see that all the nouns here, they tend to group together on one side. Adverbs, they tend to group together on these sides. Adjective. I guess they are kind of broader family. Maybe there's more variation or maybe depends on how the model was trained. But they are a bit more sparse, but still there is some structure. And this is what I meant when I say we hope that these vectors contain meaningful information because this is not a random collection of points. There is information in this image. And consider also that I'm throwing away some because I'm looking at this in 2D, while the real vector is maybe 500 dimensions or like 2000 dimensions. So there's a lot more information for the machine.
Okay, so that visual is really interesting. What about back to kind of more GPT and how it works with sentences? What about that?
Okay, so here it's true that I'm showing you embeddings for single words. While here we saw that actually processing a sequence, I have an embedding vector. Like each column here is an embedding vector for each word of the sequence. So this whole metrics kind of contains embeddings for every word. Now, given that each embedding is computed, like this model grows up, we say one word at a time. So each new column is computed using all the previous columns. So the idea is that if I look at the last column, it somewhat contains information about the whole history. So this is the trick how you go from embeddings for a single word to still one vector, same length, but now contains embedding for the full sentence. Maybe it helps if we visualize that as well. What do you think?
Yes, absolutely.
Another visualization. Okay, so here we were seeing like compressed to 2D embeddings for words. Let me paste another bit of code here. This is doing dimensional reduction of embeddings of sentences. I showed you this last time. Maybe now it's a bit more clear. These are sentences from Wikipedia pages that I collected searching for the word crane. Now, crane mainly has two meanings, a bird and an industrial machine. So you see like these kind of come together in two areas. I manually cut a horizontal line. And if you see this doing quite a good job in separating like sentences, like a carry deck, Crane is a small four wheel. Like I'm cropping this a bit to show it. Or like furnace by crane, hot metal, blah, blah, blah. This is all this stuff is definitely about crane the machine. While species blue crane or audio recordings of common crane, common crane plays a part. A wild crane was born in ways like all this stuff is crane the animal. So you see that somewhat the process embedding, the embedding process by the model, it has, as we hoped, some semantic meaning. So we can say that these embeddings contain some meaning. And this is what makes them helpful to kind of use them for classification like in this case, or use them to predict words. Like we see ChatGPT do a great.
So it's good to always see these visualizations. I think they really help. We kind of saw the embeddings for four words, and now the embeddings for sentences. How does the embedding change from the word to sentence?
Okay, so what you're asking basically is what does it mean to go from these to following each word to the final one? But for real sentences, what we can do is we can, like, here we plotted the initial word. Here we plot the final embedding of the whole sentence. After we process a set amount of words, we can just plot everything in between and. And connect them. So, like, for example, here I'm taking a sentence. Which is the best thing about AI is the ability to. Is what we saw in the first episode, but now we can visualize it in an embedding space. So you see the. This is the embedding for the single word, and it's similar to the part of speech which we saw a moment ago. The best. Now, this thing is not embedding for best. So it's not a word embedding. This is already a sentence embedding. Yeah. So if I do the embedding for best alone, it's going to be actually embedding for in this space. Embedding for single words are kind of like clustered together in a small corner because they're just a small portion, while almost all the space is taken out by different sentences, how they can grow. So, like you see, we had best thing about the AI is ability two. And then from here, ability two, we start predicting. So when we analyze this embedding, the networks predict this embedding. And starting from this embedding, the most probable word is learn. And then so we take that word and we attach it, and we have the best thing about AI is the ability to learn. And with this longer sentence, we have a new final embedding, and we can use that to predict the next probability distribution for words. And again, if we pick the most probable words, we just do the temperature zero sampling is called. So we just take the most probable we get from, and then we get experience. So basically, here we switch from. We feed an embedding, we predict a new final embedding, and then starting from there, we get the probability, we add a word, and then rinse and repeat. With this machinery, we can add one word at a time.
Gotcha. So I have a basic question about this visual. Why the difference in colors?
I color differently the prompt. So typically, prompt is what you write from what the model has generated. So the orange part up to here is a fixed trajectory. You know, like this is. Because this is the presentation of what I wrote from this point on, it's just where the model is going.
So you said the most probable is temperature zero, I think, yes.
Correct.
Or it's deterministic.
Is deterministic, yes. Because yeah, basically at each step I don't do any randomness. I just look at the result which is a deterministic result and I take the most probable, which is, you know, I just select that I like zero in on that one and then I keep doing that. So the temperature zero means that there's no temporal. Is like the random movement, you know, that comes with the heat. Like temperature zero, everything is frozen. There's no randomness. Right.
So then what if you raise the temperature and introduce more probability? What sort of.
Okay, so if I raise the temperature, I can start looking at the other words, the candidates that don't have maximum probability. So if I do that, I get kind of a bit of a different picture. And of course like they're like 50,000. So I'm not going to show you all of them here. I'm just taking the first 10, I think. Thank you. Well, that's going to be incomprehensible. So let's try to keep it simple here. Like I simplified the graphics a bit. I'm putting only one word. But like remember this is still sentence embedding. Yeah, this is the full sentence. But just to, I mean it's going to be impossible to see otherwise. So we saw that the first prediction was ability to learn. You see like these thing here with different shades of gray are the other like the first 10 best candidates after learn. So this model was kind of saying to learning simple game tool problem computer. So we need this kind of a theme here. But this one is kind of much darker. So that means that the model was kind of pretty confident about this. So it could be. But even if the temporary is non zero, if the best candidate is so much better, you still pick that.
Right.
And this is the case we saw that we work with tokens, not with words. So for example, if you have a broken word, the completion of that is gonna have much higher probability than, I don't know, like a space and a beginning of a new world. Because that doesn't make sense. So the model has never seen that.
Right, right. So they, they. I think it was the great tabby cat. Tabby would be completed because I think tabby got hoped.
Yes, yes, yes, yes. Or like I think we had serendipity or something like that. But right after you have serendip. I don't know. There are not many words in English that can begin with that.
Right, right. And so this also connects back to I think the first episode, the first or second episode that we did where we had just a table of probabilities.
Yeah, exactly. Right, exactly. This is exactly that. This is instead of showing you the probabilities, I had the first best five, but here I have the first best ten in embedding space. So this is why we are staying one step before we take the 500 dimensional vector that represent the embedding and when we show that this is exactly the same list with a slightly different representation.
So this is pretty fascinating. It seems like we're making a lot of connections on how the model works. How do we continue from here? What's the next step?
Well, once you have picked one, you just recompute the whole probabilities and okay, here I'm just copy pasting another bit of code. But you see, okay, the ability to learn. And I have this kind of sprout of options. And once I pick one, I pick learn, for example, then I have another sprout of options. So I have a new sequence of words I can pick from. And so here I put like screenshots of all the individual steps that were used to build the sentence from before. The ability to learn from experience. It is not just a matter of learning and arrives to here, but it's like every time it starts from the end and I have a new set of probabilities. And you see like sometimes, like here I see the vectors sometimes like here in the last one, they are very faint. And this is what I was telling you before. Yeah. Some steps the network is more sure. Some steps the network is less sure about what you should put there.
Amazing. So what, like when we look at these visuals, are there other visuals that kind of highlight this kind of process? I mean, because all I think about when I see these sort of probabilities and things that look like timelines or like the, the multiverse, you can tell. I watched a Disney movie over the weekend.
That true? I suspected that. I think I've seen something in Siemens blog. Yeah. About the 3D version of this. Okay, so as I say, this is a. You know, these are not really 2D points. Yeah, these are like few hundreds or thousand dimensional points. So it's up to me or as to which dimension. We want to compress them to 1D. You typically don't do that. Because it's not very informative. Anything above, like 3D you cannot see as a human being, it's difficult to kind of like put on a screen as well. So typically do 2D or you do 3D. There's not much connection between 2D and 3D because they are like, independently done. But 3D kind of allows you to see everything at once. So here is a full sentence and you see the initial prompt. This is fixed history. And then we start doing the green part. And these are all these little sprouts that I was telling you about. If you look at it from the top, you see is your multiverse. Like, imagine that at each point I could have picked any of these. There's much more alternatives. And then I could have gone on a different trajectory in this 3D space.
Yes. The whole life sentence could have changed.
Exactly. And these are the whole possible sentences. And when you click on ChatGPT, like Regenerate or like recompute, I don't remember how it's called. You click on that and then it starts from the prompt is the same is what you wrote. And then it continues with a new trajectory.
No, that's awesome. I think it's really helpful and I think that also kind of highlights for people who are exploring and looking at different things that we at Wolfram actually just introduced a plugin@chat GPT where you can use Wolfram Technologies, both Wolfram Alpha and Wolfram Language. And I think that that's going to be rolling out to more and more people. So if you get a chance to use that, definitely go through OpenAI and take a look at that. Julio, thanks again for this amazing walkthrough of ChatGPT and just kind of how LLMs work in general. It's been really helpful. I think we may have other things in the future. Perhaps I may try to wrangle one of the people from WolframAlpha or another group that's been working with the WolframAlpha team on that ChatGPT plugin and get them in here and ask them a bunch of questions as well. Julia, that doesn't mean that we won't come back to you, Julia, with something else.
Another question.
So you are not off the hook?
No, I don't consider myself completely free ever, but I would be actually very interesting to watch that episode. I hope you can get a hold of them.
Yeah, absolutely. Well, I think we're going to wrap this up for now. Thanks again and look forward to seeing everyone in the future.
More from Guy

Cheryl Strauss Einhorn | The Human Edge: Smarter Decisions in the Age of AI | Talks at Google

Rachel Glennerster | Innovation and the Center for Global Development | Talks at Google

Rebecca Winthrop | Rethinking the Purpose of Education in the Age of AI | Talks at Google

Dr. Robert Wachter | A Giant Leap: How AI Is Transforming Healthcare... | Talks at Google






