· Xiaojing Yang · NLP and LLMs · 3 min read

EN

NLP 中的 Transformers

Transformers 如何组合 self-attention、feed-forward layers、residuals 和位置信息。

核心观点

Transformer 是一层层基于 attention 的表示更新。

1. 架构想法

Transformers 用 self-attention 和并行计算替代 recurrence。每一层都会利用序列信息更新 token representations。

Transformer block
Token embeddings
输入向量
Self-attention
混合上下文信息
Residual + norm
稳定更新
Feed-forward
逐位置变换
下一层
重复

2. Encoder、decoder、encoder-decoder

类型常见用途
Encoder-only分类、NER、句向量
Decoder-only语言建模、聊天、生成
Encoder-decoder翻译、摘要、text-to-text tasks

3. Hugging Face 实践

from transformers import AutoTokenizer, AutoModelForSequenceClassification

name = "distilbert-base-uncased"
tokenizer = AutoTokenizer.from_pretrained(name)
model = AutoModelForSequenceClassification.from_pretrained(name, num_labels=2)

4. 我的研究连接

Transformers 是多语 encoder、MT 系统、COMET 类指标和 LoRA fine-tuning 的共同骨架。理解 block 有助于解释 adapter 插在哪里,以及为什么 tokenization 会影响后续一切。

工程视角

使用 pretrained checkpoints 和 task heads。

研究视角

追问架构支持什么表示、语言覆盖和适配机制。

总结

Transformers 不是一个模型,而是一种可复用的上下文表示和生成架构模式。

面试回答模板

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

  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.