Self-Attention を順を追って理解する
クエリ、キー、バリュー
「Self-Attention を順を追って理解する」はCoddyKit上の無料NLP Academyレッスンです。 これはレッスン2/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはNLP Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 NLP Academyコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
What Is Self-Attention?
In self-attention, every word looks at every other word in the same sentence to build a richer, context-aware version of itself. 🔍
Three Roles per Word
Each word is projected into three vectors: a query, a key, and a value. These three roles drive the whole self-attention computation.
The Query
The query represents what a word is looking for. Think of it as the question this word asks about the rest of the sentence.
Keys and Values
Each word also offers a key that advertises what it contains, and a value holding the actual information to pass along if chosen.
Scoring With Dot Products
Compare a query to every key using a dot product. A larger product means the query and key align, so that word deserves more focus.
scores = query @ keys.TScale the Scores
Divide scores by the square root of the key dimension. This scaling keeps numbers stable so softmax does not become too sharp.
scores = scores / (d_k ** 0.5)Softmax for Weights
Run the scaled scores through softmax to get attention weights that are positive and sum to 1 across all words in the sentence.
weights = softmax(scores)Blend the Values
Multiply each value by its weight and add them up. The result is a new vector that blends information from the most relevant words.
output = weights @ valuesThe Full Formula
All steps combine into one tidy expression: scaled dot-product attention over queries, keys, and values, as introduced in the Transformer paper.
attn = softmax(Q @ K.T / d_k**0.5) @ VWhy Self, Not Cross
It is called self-attention because the queries, keys, and values all come from the same sequence, letting words attend to their own neighbors.
Resolving Ambiguity
In "it was tired," self-attention links it to the right noun by weighting nearby words, giving every token clearer context.
Quick Check
Let us confirm the self-attention steps.
Recap
You walked through self-attention: turn words into queries, keys, and values, score, scale, softmax, then blend the values. That is the engine. ⚙️
よくある質問
「Self-Attention を順を追って理解する」レッスンは無料ですか?
はい。「Self-Attention を順を追って理解する」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、NLP Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 NLP Academyコースには全4レッスンが含まれています。
「Self-Attention を順を追って理解する」で何を学びますか?
クエリ、キー、バリュー ブラウザで直接実行するハンズオンコードでNLP Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
NLP Academyを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのNLP Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン2/4です。
「Self-Attention を順を追って理解する」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このNLP Academyレッスンでコードを書いて実行できますか?
はい。すべてのNLP Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- Attention の考え方
- Self-Attention を順を追って理解する
- マルチヘッド Attention と位置情報
- Transformer ブロックの内部