0Pricing
Deep Learning Academy · Lektion

Self-Attention: Query, Key und Value

Lassen Sie jedes Token jedes andere betrachten.

Self-Attention: Query, Key und Value ist eine kostenlose Deep Learning Academy-Lektion auf CoddyKit. Dies ist Lektion 1 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Deep Learning Academy-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Deep Learning Academy-Kurs umfasst insgesamt 4 Lektionen.

Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.

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!

Häufig gestellte Fragen

Ist die Lektion „Self-Attention: Query, Key und Value“ kostenlos?

Ja — der vollständige Text von „Self-Attention: Query, Key und Value“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Deep Learning Academy-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Deep Learning Academy-Kurs umfasst insgesamt 4 Lektionen.

Was lerne ich in „Self-Attention: Query, Key und Value“?

Lassen Sie jedes Token jedes andere betrachten. Du übst Deep Learning Academy mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.

Brauche ich Erfahrung, um Deep Learning Academy zu starten?

Keine Vorkenntnisse erforderlich. Deep Learning Academy auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 1 von 4.

Wie lange dauert die Lektion „Self-Attention: Query, Key und Value“?

Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.

Kann ich in dieser Deep Learning Academy-Lektion Code schreiben und ausführen?

Ja. Jede Deep Learning Academy-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.

Alle Lektionen in diesem Kurs

  1. Self-Attention: Query, Key und Value
  2. Skaliertes Skalarprodukt und Multi-Head
  3. Positionskodierung für die Reihenfolge
  4. Einen Transformer-Encoder-Block stapeln
← Zurück zu Deep Learning Academy