0Pricing
Deep Learning Academy · レッスン

Self-Attention:Query、Key、Value

すべてのトークンが他のすべてのトークンを参照できるようにします

「Self-Attention:Query、Key、Value」はCoddyKit上の無料Deep Learning Academyレッスンです。 これはレッスン1/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはDeep Learning Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Deep Learning Academyコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

Tokens That Talk

In a sequence, the meaning of one word depends on others. Self-attention lets every token look at every other token to gather the context it needs.

Three Roles per Token

Each token plays three roles: a query that asks, a key that answers, and a value that carries content. These come from the same word, used three ways.

The Query

A token's query describes what it is looking for. Think of it as the question this word is asking about the rest of the sentence.

The Key

Every token also exposes a key, a label advertising what it offers. A query is compared against all keys to find good matches.

The Value

Once a match is found, the value is the actual information that gets passed along. Keys decide how much, values decide what.

Make Q, K, V

You build queries, keys, and values by projecting the input through three learned linear layers. Same input, three different weight matrices.

q = self.W_q(x)
k = self.W_k(x)
v = self.W_v(x)

Score by Similarity

To see how well a query matches a key, you take their dot product. A bigger score means the two tokens are more relevant to each other.

scores = q @ k.transpose(-2, -1)

Scores to Weights

Raw scores become attention weights with softmax, so each query's weights are positive and sum to one across all keys.

weights = scores.softmax(dim=-1)

Blend the Values

The output for each token is a weighted sum of all values, mixed by the attention weights. Relevant tokens contribute more.

out = weights @ v

Why It Beats RNNs

Self-attention connects any two tokens in one step, so distance does not matter. This parallel view is why transformers handle long context so well.

Learned, Not Fixed

The Q, K, V projections are trained by gradient descent. The network learns what to ask, what to advertise, and what to share, all from data.

Quick Check

Let's test how attention combines its pieces.

Recap

You learned that self-attention turns each token into a query, key, and value, scores query-key matches, and blends values by softmax weights. Nice work!

よくある質問

「Self-Attention:Query、Key、Value」レッスンは無料ですか?

はい。「Self-Attention:Query、Key、Value」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Deep Learning Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Deep Learning Academyコースには全4レッスンが含まれています。

「Self-Attention:Query、Key、Value」で何を学びますか?

すべてのトークンが他のすべてのトークンを参照できるようにします ブラウザで直接実行するハンズオンコードでDeep Learning Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Deep Learning Academyを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのDeep Learning Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン1/4です。

「Self-Attention:Query、Key、Value」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このDeep Learning Academyレッスンでコードを書いて実行できますか?

はい。すべてのDeep Learning Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. Self-Attention:Query、Key、Value
  2. Scaled Dot-ProductとMulti-Head
  3. 順序のための位置エンコーディング
  4. Transformer Encoderブロックを積み重ねる
← Deep Learning Academyに戻る