· Xiaojing Yang · NLP and LLMs · 3 min read

EN

Attention Mechanism:注意力机制

注意力机制是一种学习到的上下文选择方式:每个 token 应该看哪里。

核心观点

Attention 让每个 token 询问:此刻哪些其他 token 和我相关?

1. 直觉

Attention 是一种相关性机制。对每个位置,模型会计算它应该从其他位置使用多少信息。

Self-attention
输入 embeddings
每个 token 一个向量
Queries
这个 token 想找什么
Keys
每个 token 提供什么线索
Scores
query-key 相似度
Values
被混合进输出的信息

2. Q、K、V

常见解释是:query 提问,key 描述 token 含有什么,value 携带要被组合的信息。attention weights 决定每个 value 贡献多少。

Attention(Q, K, V) = softmax(QKᵀ / √d) V

3. 它为什么推动 NLP

Attention 让长距离依赖更容易建模,也让翻译系统能更灵活地对齐源文本和目标文本内容。

RNN 瓶颈

信息必须经过顺序 hidden states 传递。

Attention 视角

每个位置可以直接访问相关位置。

4. 我的研究连接

对技术翻译来说,attention-like 机制很重要,因为目标术语必须依赖具体源术语,而不只是句子整体流畅。但 attention weights 不自动等于解释,仍然需要错误分析。

总结

Attention 是让上下文表示成为现代 NLP 核心的机制。

面试回答模板

如果面试问到这个概念,我通常会这样回答:

  1. 用一句话定义;
  2. 解释数据如何流动;
  3. 指出主要失败模式;
  4. 连接到 evaluation、multilinguality 或 fine-tuning。

参考资料

Share:
Back to Blog

Related Posts

View All Posts »
FoundationsNLP and LLMsEN

Attention Mechanism

Attention as a learned way to decide what context matters for each token.

FoundationsNLP and LLMsEN

Fine-Tuning Transformers

How pretrained language models are adapted to a task or domain with supervised data.

FoundationsNLP and LLMsEN

LLM Evaluation and Failure Modes

A practical map of LLM evaluation risks: hallucination, prompt sensitivity, bias, contamination, and brittle benchmarks.

FoundationsNLP and LLMsEN

NLP Evaluation

Why NLP evaluation needs metrics, uncertainty, human judgment, and task-specific error analysis.