0Pricing
NLP Academy · 课时

多头注意力与位置信息

多种视角与顺序感知

多头注意力与位置信息 是 CoddyKit 上的免费 NLP Academy 课时。 这是第 3 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 NLP Academy 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 NLP Academy 课程共包含 4 节课。

本课时的部分内容尚未翻译,以英文显示。

One Head Is Limiting

A single attention head can track only one kind of relationship at a time. Real language needs many patterns noticed at once. 🧠

Many Heads, Many Views

Multi-head attention runs several attention computations in parallel, each with its own learned projections and its own focus.

What Each Head Learns

One head might track subject-verb links while another follows pronouns. Together they capture a far richer picture of the sentence.

Split the Dimensions

The model splits its vector size across heads, so each head works in a smaller subspace. The total compute stays roughly the same.

d_head = d_model // num_heads

Combine the Heads

After each head produces an output, you concatenate them and pass the result through one more linear layer to mix the views.

out = concat(head_1, head_2, ...) @ W_o

Attention Ignores Order

Self-attention treats input as a set, so by itself it cannot tell "dog bites man" from "man bites dog." It is order-blind.

Adding Position Information

To fix this, we inject a positional encoding into each word so the model knows where every token sits in the sequence.

Sinusoidal Encodings

The original Transformer uses fixed sine and cosine waves of different frequencies to give each position a unique, smooth signature.

pe[pos, 2i] = sin(pos / 10000 ** (2*i/d))

Added, Not Appended

Position vectors are added to the word embeddings, not stuck on the end. So each token carries both meaning and place together.

x = token_embeddings + positional_encoding

Learned Positions Too

Many modern models replace fixed waves with learned position embeddings, trained alongside everything else for flexibility.

Why Both Matter

Multi-head attention sees many relationships; positional encodings restore order. Together they let the Transformer truly understand sequences. ✨

Quick Check

Let us test positions and heads.

Recap

You saw how multi-head attention captures many relationships in parallel, while positional encodings give the model a sense of order. 🎯

常见问题解答

「多头注意力与位置信息」课时是免费的吗?

是的 — 「多头注意力与位置信息」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 NLP Academy 课程的其余内容,请升级到 CoddyKit PRO。 NLP Academy 课程共包含 4 节课。

「多头注意力与位置信息」这节课中我会学到什么?

多种视角与顺序感知 你通过在浏览器中直接运行的动手代码来练习 NLP Academy,全天候 AI 导师会在你学习这节课的过程中回答你的问题。

学习 NLP Academy 需要有经验吗?

无需任何先前经验。CoddyKit 上的 NLP Academy 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 3 节课,共 4 节。

「多头注意力与位置信息」课时需要多长时间?

大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。

我能在这节 NLP Academy 课中编写并运行代码吗?

能。每节 NLP Academy 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。

此课程中的所有课时

  1. 注意力机制的理念
  2. 一步步理解自注意力
  3. 多头注意力与位置信息
  4. Transformer 模块内部
← 返回 NLP Academy