S3-02 · 进阶 S3-02 · Advanced

前馈网络 · 每个 token 各自加工 Feed-Forward Network · Each Token Gets Its Own Pass

token position → expand → activate → contract

前馈网络(Feed-Forward Network,FFN)是对每个位置独立应用的多层非线性变换。Transformer 不只有注意力:注意力先汇总信息,FFN 再逐位置加工。 A Feed-Forward Network (FFN) applies the same multilayer nonlinear transform to each position independently. A Transformer is more than attention: attention gathers information, then the FFN processes each position.

01 · 像四张照片各自过同一个滤镜 01 · Like four photos through the same filter

信息已经送到每个 token 手里后,谁负责让它各自“消化”一遍? Once information reaches each token, what lets every position process it on its own?

02 固定注意力结果,只调 FFN Hold Attention Fixed, Adjust the FFN

逐位置加工型 Position-wise transform
位置数 Positions
4
各自处理 processed separately
位置间连线 Cross-position links
0
正常为零 zero by design
输出形状 Output shape
4 × 2
逐位置返回 one per position

注意力输出保持固定;此页只改变 FFN 的两组教学权重。 Attention output stays fixed. Only the two teaching FFN weights change here.

03 FFN 的 4 个零件 Four Parts of an FFN

同规则,不串线 Shared, not mixed
PART 01

每个位置输入 Position input

每张 token 卡拿到注意力已经汇总好的表示。 Each token card receives a representation already gathered by attention.

PART 02

升维扩张 Expand

第一层把表示展开到更宽的中间空间。 The first layer opens the representation into a wider hidden space.

PART 03

非线性激活 Nonlinearity

负值被压低,强响应得以保留并组合。 Negative values are suppressed while strong responses can combine.

PART 04

降回原宽度 Contract

第二层把加工结果送回该 token 的输出位。 The second layer returns the processed result to that token's output slot.

04 最小机制:同一个 FFN 分别作用于每个位置 Minimal Mechanism: The Same FFN Acts on Each Position

FFN(xi) = W2σ(W1xi + b1) + b2
xi → W1 → σ → W2 → yi
下标 i 从头到尾不变:这一页里没有 xj 进入 yi Index i stays unchanged end to end: no xj enters yi on this page.
调 W1 Adjust W1 中间条形扩张 Hidden bars expand
经过 σ Pass through σ 负响应被截断 Negative response clips
调 W2 Adjust W2 该卡输出收缩 That card contracts

05 边界实验:强行让 token 互相串线 Boundary Test: Force Tokens to Cross-Link

主动制造失败 Create a failure

一串线,就不再是逐位置 FFN Cross-links break position-wise FFN

让第 1 张卡的输入流进第 4 张卡输出。这会制造位置间混合,与本页定义冲突。 Route card 1 input into card 4 output. That creates cross-position mixing, contradicting this page's definition.

尚未执行。正常 FFN 的位置间连线为 0。 Not run yet. A normal position-wise FFN has zero cross-position links.
FFN 负责 token 彼此查看。 The FFN makes tokens inspect one another. → ✓ 注意力负责汇总,FFN 负责逐位置加工。 Attention gathers; the FFN processes each position.
每个 token 都有完全不同的 FFN。 Each token gets a different FFN. → ✓ 同一组参数应用到所有位置。 The same parameters apply at every position.
线越多,FFN 越强。 More links make a stronger FFN. → ✓ 位置间连线会改变机制类别。 Cross-position links change the mechanism.
06 · 一句话带走 06 · One line to keep

FFN 用同一组多层非线性规则分别加工每个 token;拖两组权重时,每张卡都会变,但位置之间始终不串线。 An FFN uses the same multilayer nonlinear rule on every token independently. Adjust either weight and every card changes without cross-position links.