← Playground← 놀이터

PRISM · Machine Learning PlaygroundPRISM · 머신러닝 놀이터

Self-Attention셀프 어텐션
Every token looks at every other and mixes by learned relevance모든 토큰이 서로를 보고 학습된 관련도로 섞는다

Attention lets each token build its new representation by looking at the whole sequence and taking a weighted average of the others. The weights come from compatibility: a query from one token is compared to a key from each token, and softmax(q·k / √d) turns those scores into a distribution. Pick a query and watch where it attends — and how the attention matrix carries the structure of the sequence.어텐션은 각 토큰이 시퀀스 전체를 바라보며 나머지의 가중 평균을 취해 새 표현을 만들게 한다. 가중치는 적합도에서 나온다: 한 토큰의 쿼리가 각 토큰의 와 비교되고, softmax(q·k / √d)가 그 점수를 분포로 바꾼다. 쿼리를 골라 어디에 주목하는지, 그리고 어텐션 행렬이 시퀀스의 구조를 어떻게 담는지 보라.

Tokens & attention — where the query looks토큰 & 어텐션 — 쿼리가 보는 곳 click a token토큰 클릭
query쿼리 keys / values키 / 값 output (blended)출력 (혼합)
Attention matrix · softmax(QKᵀ/√d)어텐션 행렬 · softmax(QKᵀ/√d) row = query, column = key행 = 쿼리, 열 = 키
Controls제어판

Query token쿼리 토큰

Sharpness (1/temperature)날카로움 (1/온도) scaling of q·kq·k 스케일링3.0

Sequence시퀀스

Raise sharpness → attention collapses onto the single most-related token.날카로움을 올리면 → 어텐션이 가장 관련 있는 토큰 하나로 집중됩니다.
Measurements측정값
query쿼리
attends most to가장 주목
top weight최대 가중치
attention entropy어텐션 엔트로피
effective #attended실효 주목 수
sharpness날카로움
Things to try해볼 것들
  1. Blocks in the matrix: with Two topics, the attention matrix shows two bright blocks — tokens attend within their topic.행렬의 블록: 두 주제에서는 어텐션 행렬에 두 개의 밝은 블록이 나타난다 — 토큰이 자기 주제 안에서 주목한다.
  2. Temperature: low sharpness spreads attention (soft averaging); high sharpness makes it a hard lookup of one token.온도: 날카로움이 낮으면 어텐션이 퍼지고(부드러운 평균), 높으면 한 토큰을 집는 하드 조회가 된다.
  3. Output is a blend: the teal marker shows where the query's representation moves — toward the tokens it attends to.출력은 혼합: 청록 마커는 쿼리의 표현이 이동하는 곳을 보여준다 — 주목하는 토큰들 쪽으로.
  4. Unrelated: switch to Unrelated — attention flattens toward uniform, the token learns little from context.무관: 무관으로 바꾸면 어텐션이 균등에 가까워지고, 토큰은 맥락에서 배우는 것이 적다.

Query, key, value쿼리, 키, 값

Each token emits a query (what am I looking for), a key (what I offer), and a value (what I pass on). Attention weight A_ij = softmax_j(q_i·k_j/√d), and the output is Σ_j A_ij v_j — a content-addressed, differentiable lookup over the whole sequence.각 토큰은 쿼리(무엇을 찾는가), (무엇을 제공하는가), (무엇을 전달하는가)을 낸다. 어텐션 가중치는 A_ij = softmax_j(q_i·k_j/√d)이고, 출력은 Σ_j A_ij v_j — 시퀀스 전체에 대한 내용 기반의 미분 가능한 조회다.

Why √d왜 √d인가

Dot products of d-dimensional vectors grow like √d, which would saturate the softmax into a hard argmax. Dividing by √d keeps the scores in a sane range so gradients flow — the sharpness slider here plays that role in reverse.d차원 벡터의 내적은 √d처럼 커져 softmax를 하드 argmax로 포화시킨다. √d로 나누면 점수가 적정 범위에 머물러 기울기가 흐른다 — 여기 날카로움 슬라이더가 그 역할을 반대로 한다.

The engine of TransformersTransformer의 엔진

Stacking self-attention builds the Transformer — now used far beyond language: on clinical time series, genomic sequences, and medical images, wherever long-range relationships between elements matter. It is also modern Hopfield associative memory in disguise.셀프 어텐션을 쌓으면 Transformer가 된다 — 이제 언어를 훨씬 넘어 임상 시계열, 유전체 서열, 의료 영상 등 요소 간 장거리 관계가 중요한 곳 어디에나 쓰인다. 또한 이것은 변장한 현대 Hopfield 연상 기억이기도 하다.