| 第49行: |
第49行: |
| | * <math>c</math>:注入系数(injection coefficient),控制引导[[向量]]强度。 | | * <math>c</math>:注入系数(injection coefficient),控制引导[[向量]]强度。 |
| | | | |
| − | === 算法 1([[Algorithm]] 1)=== | + | ===ActAdd算法=== |
| − | 以下为与论文 [[Algorithm]] 1 等价的表述(略去实现细节,仅保留关键步骤):[^https://arxiv.org/pdf/2308.10248v4] | + | 以下为与论文<ref name="ActAdd"/>中的 [[Algorithm]] 1 等价的算法表述(略去实现细节,仅保留关键步骤): |
| | | | |
| − | # 对齐 token 长度:将 <math>(p_+,p_-)</math> 右侧填充到相同 token 长度,得 <math>(p'_+,p'_-)</math>。[^https://arxiv.org/pdf/2308.10248v4] | + | # 对齐 token 长度:将 <math>(p_+,p_-)</math> 右侧填充到相同 token 长度,得 <math>(p'_+,p'_-)</math>。 |
| | # 读取两端激活: | | # 读取两端激活: |
| | #* <math>\mathbf{h}^l_+ = \mathbf{h}^l(p'_+)</math> | | #* <math>\mathbf{h}^l_+ = \mathbf{h}^l(p'_+)</math> |
| − | #* <math>\mathbf{h}^l_- = \mathbf{h}^l(p'_-)</math> [^https://arxiv.org/pdf/2308.10248v4] | + | #* <math>\mathbf{h}^l_- = \mathbf{h}^l(p'_-)</math> |
| | # 计算引导[[向量]](差分): | | # 计算引导[[向量]](差分): |
| − | #* <math>\mathbf{h}^l_A = \mathbf{h}^l_+ - \mathbf{h}^l_-</math> [^https://arxiv.org/pdf/2308.10248v4] | + | #* <math>\mathbf{h}^l_A = \mathbf{h}^l_+ - \mathbf{h}^l_-</math> |
| | # 读取用户[[提示词]]激活: | | # 读取用户[[提示词]]激活: |
| − | #* <math>\mathbf{h}^l_* = \mathbf{h}^l(p^*)</math> [^https://arxiv.org/pdf/2308.10248v4] | + | #* <math>\mathbf{h}^l_* = \mathbf{h}^l(p^*)</math> |
| | # 注入并继续前向:在对齐位置 <math>a</math> 处进行加法[[干预]]并继续完成前向计算,得到输出 <math>S</math>: | | # 注入并继续前向:在对齐位置 <math>a</math> 处进行加法[[干预]]并继续完成前向计算,得到输出 <math>S</math>: |
| − | #* <math>S = \mathrm{ContinueForward}\bigl(M,\ \mathbf{h}^l_* + c\cdot \mathbf{h}^l_A \text{ at position } a\bigr)</math> [^https://arxiv.org/pdf/2308.10248v4] | + | #* <math>S = \mathrm{ContinueForward}\bigl(M,\ \mathbf{h}^l_* + c\cdot \mathbf{h}^l_A \text{ at position } a\bigr)</math> |
| | | | |
| | === 超参数与实现要点 === | | === 超参数与实现要点 === |