Natural Language Processing · 免费预览

自注意力

来自邻居加权和、查询、键、值、缩放点积得分以及多个注意力头的上下文嵌入。

1. Self-Attention

Self-Attention

2. Queries, keys, values, and heads

Queries, keys, values, and heads

3. Attention weights in NumPy

Attention weights in NumPy

4. Softmaxing attention scores

A token attends to three prior tokens with raw scores 22, 11, −1-1. Compute the attention weight for the first token after the softmax, round to three decimals.

5. Why divide by the root of the dimension

A query-key dot product is 1212 with head dimension dk=25d_k = 25. Compute the scaled score q⋅kdk\frac{\mathbf{q} \cdot \mathbf{k}}{\sqrt{d_k}} and round to three decimals.

6. Queries, keys, and values

Match each projection to its role in one attention head.

7. Masking with minus infinity

In the masked attention matrix for a causal language model, future positions receive the value −∞-\infty before the softmax rather than 0. Why?

8. Head width in multi-head attention

A transformer has model dimension d=512d = 512 and A=16A = 16 attention heads, with the usual choice dv=d/Ad_v = d/A so all heads share the budget. What is dvd_v? Answer with the number.

进入交互式练习

免费注册 · 即时批改 · 自动安排间隔复习。

免费开始这门课