跟讀練習: Encoder-Only Transformers (like BERT) for RAG, Clearly Explained!!! - 通過影片學習英語口語

選擇練習模式

每種模式都會開啟全屏練習室。

172 句
如果句子過短或過長,請點選 Edit 進行調整。
1
Encoder -only transformers can cluster things and classify things that's cool.
2
StatQuest.
3
Hello, I'm Josh Starmer and welcome to StatQuest.
4
Today we're going to talk about encoder -only transformers and they're going to be clearly explained.
5
This StatQuest is brought to you by the letters A, B, and C.
6
A always, B, B, C curious always be curious.
7
Note, this stat quest assumes that you are already familiar with the main ideas of how neural networks work.
8
If not, check out the quest.
9
Also note, this stat quest focuses on the main ideas of how encoder -only transformers work
10
and what we can do with them.
11
That said, if you want to see the nitty -gritty details, check out these fine quests.
12
Okay,
13
way back in 2017 the first transformer ever made had one part called an encoder and a second part called a decoder.
14
And the encoder and the decoder were connected to each other so they could work together.
15
This first transformer was based on something called a seek -to -seek or an encoder -decoder model.
16
Encoder -decoder models were designed to translate text in one language, like English, into another language, like Spanish.
17
For example, Squatch might say, Pizza is great!
18
And the encoder would crunch a lot of numbers to encode the input, and the decoder would crunch a lot of numbers,
19
including the output from the encoder, and, ultimately, decode those numbers into a translation.
20
La pizza es magnifico.
21
Bam!
22
However, it wasn't long after this first encoder -decoder transform was published
23
that people realized that both parts could work just fine on their own.
24
It turned out that we could generate text, including translations of text, with just a decoder.
25
And these models, which formed the basis for ChatGPT, were named decoder -only transformers.
26
Likewise, models based entirely on the encoder started to be very useful on their own.
27
And these models, which formed the basis for BERT and many other models, were named encoder -only transformers.
28
However, over the years, the models based on decoder -only transformers kind of stole the show.
29
Pretty much everyone has used, or at least heard of, ChatGPT or Gemini or any of the other countless decoder -only transformers out there.
30
And I've heard some super smart people, who keep up with AI and everything, ask me if people still used encoder -only transformers.
31
So, in this stat quest, I want to dive deep into encoder -only transformers so we can understand their significant, but understated, power.
32
And that means starting with a deep dive into the first thing a transformer does, which is create word embeddings.
33
Word embedding converts words, bits of words, and symbols, collectively called tokens, into numbers.
34
We need to convert tokens into numbers because transformers are a type of neural network and neural networks only operate on numbers.
35
One super easy way to convert words into numbers is to just assign each word to a random number.
36
For example, if Squatch just ate a delicious pizza, they might say, Pizza is great!
37
And we could assign a random number to each word.
38
Now, if Norm came along and said, Pizza is awesome!
39
Then we could reuse the random numbers that we already assigned to pizza and is, and assign a new random number to awesome.
40
In theory, this is fine.
41
But it means that even though great and awesome mean similar things and are used in similar ways,
42
they have very different numbers associated with them.
43
And that means the neural network will probably need a lot more complexity
44
and training because learning how to correctly process the word great won't help the neural network correctly use the word awesome.
45
So it would be nice if similar words that are used in similar ways could be given similar numbers.
46
So that learning how to use one word will help learn how to use the other at the same time.
47
And because the same words can be used in different contexts, or made plural, or used in some other way,
48
it might be nice to assign each word more than one number, so that the neural network can more easily adjust to different contexts.
49
For example, the word great can be used in a positive way, like, pizza is great.
50
And it can also be used in a sarcastic negative way, like, my cell phone's broken.
51
Great.
52
And it would be nice if we had one number that could keep track of the positive ways that great is used,
53
and a different number to keep track of the negative ways.
54
Hey Josh, deciding what words are similar and are used in similar contexts sounds like a lot of work.
55
And using more than one number per word to account for different contexts sounds like even more work.
56
Don't worry Squatch, the good news is
57
that we can get a relatively simple neural network to do all of the work for us.
58
For example, let's imagine we have two phrases.
59
Pizza is great and pizza is awesome.
60
The first thing we do is create inputs to a relatively simple neural network for each unique word.
61
Then we create an output for each word.
62
Then we connect all of the inputs to at least one activation function.
63
And in this example, we'll connect the inputs to two activation functions.
64
The number of activation functions determines how many numbers we will use to represent each word.
65
In this case, since we have two activation functions, we'll end up with two numbers or word embeddings representing each word.
66
Then we add weights to the connections from the inputs to the activation functions.
67
These weights are initialized with random numbers, so right now they're not very useful.
68
But the plan is to train them and thus change them using this data.
69
Lastly, we connect the activation functions to the outputs with some boring details that we don't need to worry about right now.
70
Because we have one word embedding for each word going to the activation function on the top,
71
and one word embedding for each word going to the activation function on the bottom,
72
we can plot each word on a graph that has the top word embeddings on the x -axis
73
and the bottom word embeddings on the y -axis.
74
For example, the word pizza goes here because its top word embedding is negative 0 .11,
75
and its bottom word embedding is 0 .10.
76
Likewise, the word is goes here, great goes here, and awesome goes here.
77
Now, with this graph, we see that the words great
78
and awesome are currently no more similar to each other than they are to any of the other words.
79
However, because both words appear in the same context in the training data, we hope that training the network will make their word embeddings more similar.
80
The idea is that we want each word in the training data to predict the next word.
81
For example, we want the first word in each sentence, pizza, to predict the word that comes after it, is.
82
And we want the word IS to predict the words that come after it, GREAT and AWESOME.
83
So, in order to see which word the network predicts should come after PIZZA, we put a 1 in the input for PIZZA,
84
and we put 0s in all of the other inputs.
85
Then we do the math with the randomly initialized parameters, and we end up predicting GREAT,
86
because it has the largest output value, 0 .45.
87
Thus, with the randomly initialized parameters, the network does not correctly predict IS, the word that comes after PIZZA.
88
However, after we train the model, we end up with these new word embeddings.
89
And PIZZA correctly predicts IS and is correctly predicts great and awesome.
90
Now when we graph the words with the new word embeddings, great and awesome cluster together.
91
This result is great and awesome because great and awesome are similar words used in similar contexts,
92
and they ended up with similar word embeddings.
93
So far, we've seen the simplest way to create word embeddings.
94
We used a simple network that we trained to predict the word that comes after the input.
95
However, just predicting the next word doesn't give us a lot of context to determine the optimal word embeddings.
96
In contrast, if we had a more complicated training data set, then we would have more inputs and outputs for our neural network.
97
And we could connect everything like we did before.
98
But now, because we have more inputs and outputs, and longer sentences in the training data,
99
we can add more context to the training process.
100
For example, we can use the pizza came out to predict the next word of.
101
In other words, instead of just using one word to predict the next, we can use the preceding four words to predict the next.
102
Increasing the context can help create better word embedding values.
103
But I want to point out that the way we are doing things right now ignores word order.
104
And because we are not currently keeping track of word order, any jumble is just as good as anything else.
105
In other words, the pizza came out of would give us the same inputs an output, as the jumbled up phrase,
106
pizza out came the of.
107
So it would be nice if there were some way to create word embedding values that also took word order into account.
108
And that leads us to the part of a transformer that comes after the initial word embedding layer, called positional encoding.
109
Positional encoding helps keep track of word order.
110
For example, if Norm said, Squatch eats pizza, then Squatch might say, yum.
111
In contrast, if Norm said, pizza eats Squatch, then Squatch might say, yikes.
112
So these two phrases, Squatch eats pizza and pizza eats squash use the exact same words but have very different meanings.
113
So, keeping track of word order is super important.
114
There are a bunch of ways to implement positional encoding, but these details are out of the scope of this quest.
115
Anyway, now we know that positional encoding helps keep track of word order.
116
However, it would be great if there was also a way to keep track of the relationships among words.
117
For example, if the input sentence was this, The pizza came out of the oven and it tasted good.
118
Then this word, it, could refer to pizza or potentially it could refer to the word oven.
119
Josh, I've heard of good tasting pizza but never a good tasting oven.
120
I know, Squatch, that's why it's important that the transformer correctly associates the word it with pizza.
121
And that leads us to the part of a transformer that comes after positional encoding, called attention.
122
And, specifically, in an encoder -only transformer, it's called self -attention.
123
Attention helps keep track of the relationships among words.
124
Going back to our example about pizza coming out of an oven, attention can help correctly associate the word it with the word pizza.
125
Note, there are different types of attention, but encoder -only transformers only use self -attention, so we'll focus on that.
126
In general terms, self -attention works by seeing how similar each word is to all of the other words in the sentence, including itself.
127
For example, self -attention calculates the similarity between the first word,
128
the, and all of the other words in the sentence, including itself.
129
And self -attention calculates these similarities for every word in the sentence.
130
Once the similarities are calculated, they are used to determine how the transformer encodes each word. For example,
131
if you looked at a lot of sentences about pizza and the word it was more commonly associated with pizza than oven,
132
then the similarity score for pizza will cause
133
it to have a larger impact on how the word it is encoded by the transformer.
134
Bam.
135
Now that we understand the ideas behind self -attention,
136
we understand the ideas behind the three fundamental building blocks that make up an encoder -only transformer.
137
Word embedding converts the input into numbers, positional encoding helps keep track of word order,
138
and self -attention helps establish relationships among words.
139
Combining all three layers creates a new kind of embedding for each token that takes position and relationships among words into account.
140
And this new type of embedding is sometimes called context -aware embedding or contextualized embedding.
141
Because context -aware embeddings include information about the position of each word as well as the relationships among the words,
142
Context -aware embeddings can help cluster similar sentences or even similar documents.
143
Bam!
144
To summarize, encoder -only transformers like BERT that only use self -attention can create context -aware embeddings.
145
And just like plain old word embeddings can help cluster similar words that are used in similar ways,
146
Context -aware embeddings can help cluster similar sentences or similar documents.
147
Note, the ability to cluster similar sentences in documents is the foundation for something called Retrieval Augmented Generation, or RAG.
148
RAG works by breaking a document into blocks of text
149
and then using an encoder -only transformer to create context -aware embeddings for each one.
150
Then, when someone gives an AI a prompt like, what is pizza?
151
RAG generates embeddings for what is pizza and finds the chunks of text that are the most similar.
152
Double bam!
153
Now that we understand the main ideas behind encoder -only transformers and context -aware embeddings,
154
let's talk about another cool thing we can do with them.
155
One thing that we can do is use the context -aware embeddings as inputs to a normal neural network
156
that classifies the sentiment of the input.
157
For example, we might want to see if people are posting positive or negative sentiments about pizza on LinkedIn.
158
And the context -aware embeddings are great inputs for a neural network that can do that type of classification.
159
Alternatively, we could use the context -aware embeddings as variables in a logistic regression model that does classification.
160
Anyway, even though decoder -only transformers like ChatGPT get all the hype, the context -aware embeddings
161
that encoder -only transformers create can be used in a wide variety of settings to do very cool things triple bam.
162
Now it's time for some shameless self -promotion.
163
If you want to review statistics and machine learning offline, check out the StatQuest PDF study guides and my books,
164
the StatQuest Illustrated Guide to Machine Learning, and the StatQuest Illustrated Guide to Neural Networks and AI at StatQuest .org.
165
There's something for everyone.
166
Hooray!
167
We've made it to the end of another exciting StatQuest.
168
If you like this StatQuest and want to see more, please subscribe.
169
And if you want to support StatQuest, consider contributing to my Patreon campaign, becoming a channel member, buying one or two of my original songs,
170
or a t -shirt, or a hoodie, or just donate.
171
The links are in the description below.
172
All right, until next time, quest on!

下載應用

流利口語所需的一切

AI 發音評分逐句打分
音標練習掌握每個音
詞彙學習建立你的詞庫
詞彙遊戲邊玩邊學

同頻道

FOR YOU

推薦影片

本課的詞彙與口語要點

這節口語課以影片“Encoder-Only Transformers (like BERT) for RAG, Clearly Explained!!!”為素材。 影片中反覆出現的詞有:word, embedding, pizza, transformer, encoder。 這段影片共有 172 個句子、2494 個單詞可供跟讀。 講話部分時長為 18:50。 說話人語速平穩,每分鐘約 132 個詞,很適合跟讀。 只有 80% 的單詞屬於英語最常用的 3,000 詞,詞彙難度較高。

影片中的重點詞彙

影片中 15 個值得學習的單詞,附發音和釋義:

單詞發音釋義
pizza 名詞/ˈpi.tsə/比薩 /比薩, 披薩 /披薩
input 名詞/ˈɪnpʊt/輸入 /輸入
predict 動詞/pɹɪˈdɪkt/預言 /預言
activation 名詞/ˌæktəˈveɪʃən/啟用
output 名詞/ˈaʊtpʊt/輸出 /輸出
quest 名詞/kwɛst/探索, 尋求 /尋求
cluster 名詞/ˈklʌstɚ/串, 叢 /叢
connect 動詞/kəˈnɛkt/連線 /連線
oven 名詞/ˈʌ.vn̩/烤爐 /烤爐, 爐 /爐
assign 動詞/əˈsaɪn/分配, 分派
associate 名詞/əˈsoʊʃi.ət/同行, 同事
similarity 名詞/ˌsɪm.ɪˈlæɹ.ɪ.ti/相似, 類似 /類似
phrase 名詞/ˈfɹeɪ̯z/短語 /短語, 片語 /片語
graph 名詞/ɡɹæf/圖表 /圖表
stat 副詞/stæt/即刻

影片中出現的短語動詞

單詞發音釋義
check out 動詞退房
come along 動詞陪伴, 陪同
end up 動詞到達
make up 動詞/ˌmeɪk ˈʌp/組成 /組成
point out 動詞指, 指出
turn out 動詞原來 /原來

影片中的語法

說話人最常用的結構,並附上影片中的原話:

結構影片中的用法
被動語態 be + 過去分詞 — 強調發生了什麼,而不是誰做的be clearly explained · is brought · were connected
現在完成時 have/has + 過去分詞 — 過去發生但與現在仍有關聯的事has used · I've heard · we've seen

需要注意的發音

說話人用了 16 次縮略和弱讀形式,例如 we'll, don't, I've。請按聽到的簡短形式來說。

  • “sh” 和 “zh” 音: activation /ˌæktəˈveɪʃən/, associate /əˈsoʊʃi.ət/, contrast /kənˈt(ʃ)ɹæst/, translation /tɹænzˈleɪʃən/, classification /ˌklæsɪfɪˈkeɪʃən/
  • 長單詞——注意重音位置: activation /ˌæktəˈveɪʃən/, associate /əˈsoʊʃi.ət/, similarity /ˌsɪm.ɪˈlæɹ.ɪ.ti/, classification /ˌklæsɪfɪˈkeɪʃən/, parameter /pəˈɹæm.ə.tɚ/

中文母語者容易讀錯的音:

  • /v/ — 不要讀成 /w/,上齒輕觸下唇: activation /ˌæktəˈveɪʃən/, oven /ˈʌ.vn̩/, convert /kənˈvɝt/, dive /daɪv/, variable [ˈvæɹ.i.ə.bl̩]
  • 詞尾子音 — 要讀清楚,後面不要加母音: input /ˈɪnpʊt/, predict /pɹɪˈdɪkt/, output /ˈaʊtpʊt/, quest /kwɛst/, connect /kəˈnɛkt/
  • /r/ 和 /l/ 的區別: neural /ˈnʊɹəl/, correctly /kəˈɹɛk(t).li/, similarity /ˌsɪm.ɪˈlæɹ.ɪ.ti/, translation /tɹænzˈleɪʃən/, randomly /ˈɹændm̩li/

如何用這段影片練習

  1. 先完整聽一遍影片,不要開口,記下不認識的單詞。
  2. 用正常速度逐句跟讀,每句重複到你的節奏與說話人一致為止。
  3. 錄下自己的聲音並與原聲對比,特別注意 pizza, input, predict 這類單詞。

什麼是跟讀法?

跟讀法 (Shadowing) 是一種有科學依據的語言學習技巧,最初開發用於專業口譯員的培訓,並由多語言者Alexander Arguelles博士普及。這個方法簡單而強大:您在聽英語母語原聲的同時立即大聲重複——就像是一個延遲1-2秒緊跟說話者的影子。與被動聽力或語法練習不同,跟讀法強迫您的大腦和口腔肌肉同時處理並模模擬實的講話模式。研究表明它能顯著提高發音準確性,語調,節奏,連讀,聽力理解和口語流利度——使其成為雅思口語備考和真實英語交流最有效的方法之一。

影子跟讀法: 閱讀完整分步指南 →