DataToll 中文

3Blue1Brown · Attention in Transformers · YouTube Transcript

This is a caption track snapshot for eMlx5fFNoYc. Read 80 timestamped excerpts from video eMlx5fFNoYc. The full caption track contains 4,903 words in 423 segments, with 12 chapters.

Results · YouTube Transcript

Snapshot ·

00:00In the last chapter, you and I started to step
00:01through the internal workings of a transformer.
00:04This is one of the key pieces of technology inside large language models,
00:07and a lot of other tools in the modern wave of AI.
00:10It first hit the scene in a now-famous 2017 paper called Attention is All You Need,
00:15and in this chapter you and I will dig into what this attention mechanism is,
00:19visualizing how it processes data.
00:26As a quick recap, here's the important context I want you to have in mind.
00:30The goal of the model that you and I are studying is to
00:32take in a piece of text and predict what word comes next.
00:36The input text is broken up into little pieces that we call tokens,
00:40and these are very often words or pieces of words,
00:42but just to make the examples in this video easier for you and me to think about,
00:47let's simplify by pretending that tokens are always just words.
00:51The first step in a transformer is to associate each token
00:54with a high-dimensional vector, what we call its embedding.
00:57The most important idea I want you to have in mind is how directions in this
01:02high-dimensional space of all possible embeddings can correspond with semantic meaning.
01:07In the last chapter we saw an example for how direction can correspond to gender,
01:11in the sense that adding a certain step in this space can take you from the
01:15embedding of a masculine noun to the embedding of the corresponding feminine noun.
01:20That's just one example you could imagine how many other directions in this
01:23high-dimensional space could correspond to numerous other aspects of a word's meaning.
01:28The aim of a transformer is to progressively adjust these embeddings
01:32so that they don't merely encode an individual word,
01:35but instead they bake in some much, much richer contextual meaning.
01:40I should say up front that a lot of people find the attention mechanism,
01:43this key piece in a transformer, very confusing,
01:46so don't worry if it takes some time for things to sink in.
01:49I think that before we dive into the computational details and all
01:52the matrix multiplications, it's worth thinking about a couple
01:55examples for the kind of behavior that we want attention to enable.
02:00Consider the phrases American shrew mole, one mole of carbon dioxide,
02:04and take a biopsy of the mole.
02:06You and I know that the word mole has different meanings in each one of these,
02:09based on the context.
02:11But after the first step of a transformer, the one that breaks up the text
02:15and associates each token with a vector, the vector that's associated with
02:18mole would be the same in all of these cases,
02:21because this initial token embedding is effectively a lookup table with no
02:24reference to the context.
02:26It's only in the next step of the transformer that the surrounding
02:29embeddings have the chance to pass information into this one.
02:33The picture you might have in mind is that there are multiple distinct directions in
02:38this embedding space encoding the multiple distinct meanings of the word mole,
02:42and that a well-trained attention block calculates what you need to add to the generic
02:47embedding to move it to one of these specific directions, as a function of the context.
02:53To take another example, consider the embedding of the word tower.
02:57This is presumably some very generic, non-specific direction in the space,
03:01associated with lots of other large, tall nouns.
03:04If this word was immediately preceded by Eiffel,
03:06you could imagine wanting the mechanism to update this vector so that
03:10it points in a direction that more specifically encodes the Eiffel tower,
03:14maybe correlated with vectors associated with Paris and France and things made of steel.
03:19If it was also preceded by the word miniature,
03:22then the vector should be updated even further,
03:24so that it no longer correlates with large, tall things.
03:29More generally than just refining the meaning of a word,
03:32the attention block allows the model to move information encoded in
03:35one embedding to that of another, potentially ones that are quite far away,
03:39and potentially with information that's much richer than just a single word.
03:43What we saw in the last chapter was how after all of the vectors flow through the
03:47network, including many different attention blocks,
03:50the computation you perform to produce a prediction of the next token is entirely a
03:55function of the last vector in the sequence.
03:59Imagine, for example, that the text you input is most of an entire mystery novel,
04:03all the way up to a point near the end, which reads, therefore the murderer was.
04:08If the model is going to accurately predict the next word,
04:11that final vector in the sequence, which began its life simply embedding the word was,
04:16will have to have been updated by all of the attention blocks to represent much,
04:20much more than any individual word, somehow encoding all of the information
04:24from the full context window that's relevant to predicting the next word.
04:29To step through the computations, though, let's take a much simpler example.
04:32Imagine that the input includes the phrase, a
04:35fluffy blue creature roamed the verdant forest.
04:38And for the moment, suppose that the only type of update that we care about
04:42is having the adjectives adjust the meanings of their corresponding nouns.
04:47What I'm about to describe is what we would call a single head of attention,
04:50and later we will see how the attention block consists of many different heads run in
04:54parallel.

Key Takeaways

3Blue1Brown · Attention in Transformers ·

Explore sample reports

YouTube Transcript

Frequently asked questions (FAQ)

What does 3Blue1Brown say at the start?
“In the last chapter, you and I started to step through the internal workings of a transformer. This is one of the key pieces of technology inside large language models,”
How much can I use for free?
Reading and exporting samples is free. Each IP can run 100 live searches per rolling 24 hours.
Which formats can I export?
Save captions as .srt, .md or .txt. Download products, reviews, ads and jobs as Excel-compatible .csv, or copy a Markdown summary of low-rated reviews or open roles.
How fresh are the results?
Each sample shows its capture date. Fetch Latest Live requests the public source again. Exports use the displayed sample and filters.
What happens to my search?
Live searches send the target to DataToll and include it in the shareable page URL. Filtering, copying and downloads happen in your browser.