Self-attention krok po kroku
Queries, keys i values
Self-attention krok po kroku to bezpłatna lekcja NLP Academy na CoddyKit. To lekcja 2 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej NLP Academy, a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs NLP Academy zawiera 4 lekcji w sumie.
Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.
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. ⚙️
Często zadawane pytania
Czy lekcja „Self-attention krok po kroku” jest bezpłatna?
Tak — pełny tekst „Self-attention krok po kroku” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu NLP Academy, przejdź na CoddyKit PRO. Kurs NLP Academy zawiera 4 lekcji w sumie.
Co nauczysz się w „Self-attention krok po kroku”?
Queries, keys i values Ćwiczysz NLP Academy z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.
Czy potrzebuję doświadczenia, aby zacząć NLP Academy?
Nie wymagamy żadnego doświadczenia. NLP Academy w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 2 z 4.
Ile czasu zajmuje lekcja „Self-attention krok po kroku”?
Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.
Czy mogę pisać i uruchamiać kod w tej lekcji NLP Academy?
Tak. Każda lekcja NLP Academy zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.
Wszystkie lekcje w tym kursie
- Idea mechanizmu attention
- Self-attention krok po kroku
- Multi-head attention i pozycje
- Wewnątrz bloku Transformera