Token Lab搜索

← 全部实验
注意力与掩码 / 1 OF 5

因果注意力基线

Future positions must receive zero probability.

本地计算 / 模拟

本地教学实验,不调用外部 API。合成示例不能替代生产环境测量。

学习指南与本课目录LEARNING CONTRACT

理解 → 实现 → 研究

目标:解释本课机制、复现一个例子、测试一个失败案例。读完不自动代表掌握。

02 · 预测与配置

技术场景说明、参数名称与参考答案目前为英文。

03 · 检查证据

运行实验后查看结果。

方法与参考资料

One synthetic head, four positions, Q, K and V are fixed and printed in exported method metadata. This visualizes attention weights, not an explanation of model reasoning.

Text / 原始公式
softmax(scale × QKᵀ / √2 + mask)V
Text / 原始公式
Q = [[1,0],[0,1],[1,1],[0.5,-1]]
K = [[1,0],[0,1],[1,1],[-1,1]]
V = [1,3,5,7]

A high attention weight does not establish causal feature importance.

Attention Is All You Need · §3.2 ↗

练习题

attention-1 / 01What does “Causal baseline” test?

Future positions must receive zero probability.

Original teaching answer / local derivation. Method reference: Attention Is All You Need · §3.2 ↗

打开实验 →
attention-1 / 02Which computation produces the result in “Causal baseline”?

softmax(scale × QKᵀ / √2 + mask)V

Original teaching answer / local derivation. Method reference: Attention Is All You Need · §3.2 ↗

打开实验 →
attention-1 / 03What is the baseline configuration for “Causal baseline”?

{"scale":1,"causal":1}

Original teaching answer / local derivation. Method reference: Attention Is All You Need · §3.2 ↗

打开实验 →
attention-1 / 04What numerical result should you check for “Causal baseline”?

{"Mean entropy (bits)":1.0510152779349418,"Last output":2.980121288333647}

Original teaching answer / local derivation. Method reference: Attention Is All You Need · §3.2 ↗

打开实验 →
attention-1 / 05How would you run a controlled comparison for “Causal baseline”?

Keep the supplied fixture and other settings fixed; change scale. Inspect per-row normalization, entropy and the weighted value output.

Original teaching answer / local derivation. Method reference: Attention Is All You Need · §3.2 ↗

打开实验 →
attention-1 / 06What failure could invalidate a conclusion from “Causal baseline”?

A high attention weight does not establish causal feature importance.

Original teaching answer / local derivation. Method reference: Attention Is All You Need · §3.2 ↗

打开实验 →
attention-1 / 07Is “Causal baseline” a benchmark of a deployed language model?

No. One synthetic head, four positions, Q, K and V are fixed and printed in exported method metadata. This visualizes attention weights, not an explanation of model reasoning.

Original teaching answer / local derivation. Method reference: Attention Is All You Need · §3.2 ↗

打开实验 →
attention-1 / 08Which evidence should you report for “Causal baseline”?

Inspect per-row normalization, entropy and the weighted value output. Export inputs, engine, result and method; distinguish synthetic fixtures from observed production data.

Original teaching answer / local derivation. Method reference: Attention Is All You Need · §3.2 ↗

打开实验 →
attention-1 / 09How can another researcher reproduce “Causal baseline”?

Open attention-1, reset the preset, retain the exact inputs and run. The calculation is deterministic for identical inputs.

Original teaching answer / local derivation. Method reference: Attention Is All You Need · §3.2 ↗

打开实验 →
attention-1 / 10What is the next validation step after “Causal baseline”?

A high attention weight does not establish causal feature importance. Test the hypothesis on a representative held-out workload and document a baseline, success metric and stopping rule before claiming deployment readiness.

Original teaching answer / local derivation. Method reference: Attention Is All You Need · §3.2 ↗

打开实验 →
MATHEMATICAL REVIEW · 2026-10-26

假设、参考实现与验收

自注意力:X 为 N×d_model;W_Q、W_K 为 d_model×d_k;W_V 为 d_model×d_v。分数 N×N,输出 N×d_v。方差推导假设坐标独立、零均值、单位方差;交叉注意力可有不同查询和键长度。

已复核引擎公式、场景预设及数值保护。固定种子的合成输入不是生产基准。

Q,K,V · 四个 token 行 → QKᵀ / √d · 因果遮罩 → 逐行 softmax · 允许权重和为 1 → 加权 V · 检验未来扰动不变性
机制图:从上到下跟踪每次变换。

运行前:预测一个边界情况

Future positions must receive zero probability.

提示:隔离假设

固定基线输入,只改变一个参数或边界;同时比较数值与声明单位。单例通过仅验证该样例。

最小可运行算例

将算例及所链接模块保存在同一目录。使用 Node.js 22 或更高版本,然后运行 node attention-1.mjs. 无需第三方运行依赖。

import {calculate,network} from './academy-core.mjs';
const params={
  "scale": 1,
  "causal": 1
};
const result=calculate('attention',params);
console.log(result.metrics);

测试与迁移

Future positions must receive zero probability.

在下方笔记记录输入、代码版本、期望值和实测值;再构造违反上述假设的反例,解释原结论为何不再成立。

下载完整代码包(.tar.gz) · 完整参考代码与回归检查

预测、检验与证据记录

展开答案前先预测一个结果;练习后记录差异和迁移测试。记录仅存本地,在不同语言版本间共用。

打开记录/导出/清除 →

数学复核范围逐篇记录,不代表完成论文实证复现;可在笔记中记录疑似错误。 复核范围