Bidirectional context
Removing the mask exposes future keys.
Local calculation / simulationLocal educational experiment. No external API calls. Synthetic fixtures are not production measurements.
Study guide & lesson outline
LEARNING CONTRACTUnderstand → implement → investigate
Goal: explain the mechanism in this lesson, reproduce one example and test a failure case. Reading alone does not mark mastery.
- Understand: state assumptions, shapes/units and a counterexample.
- Implement: reproduce a numerical example and inspect boundaries.
- Investigate: compare one alternative under a matched budget.
02 · Predict & configure
Technical scenario notes, parameter names and reference answers are currently in English.
03 · Inspect the evidence
Methods & references
One synthetic head, four positions,
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 ↗Practice questions
attention-2 / 01What does “Bidirectional context” test?
Removing the mask exposes future keys.
Original teaching answer / local derivation. Method reference: Attention Is All You Need · §3.2 ↗
Open lab →attention-2 / 02Which computation produces the result in “Bidirectional context”?
softmax(scale × QKᵀ / √2 + mask)V
Original teaching answer / local derivation. Method reference: Attention Is All You Need · §3.2 ↗
Open lab →attention-2 / 03What is the baseline configuration for “Bidirectional context”?
{"scale":1,"causal":0}
Original teaching answer / local derivation. Method reference: Attention Is All You Need · §3.2 ↗
Open lab →attention-2 / 04What numerical result should you check for “Bidirectional context”?
{"Mean entropy (bits)":1.8471329825256673,"Last output":2.980121288333647}
Original teaching answer / local derivation. Method reference: Attention Is All You Need · §3.2 ↗
Open lab →attention-2 / 05How would you run a controlled comparison for “Bidirectional context”?
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 ↗
Open lab →attention-2 / 06What failure could invalidate a conclusion from “Bidirectional context”?
A high attention weight does not establish causal feature importance.
Original teaching answer / local derivation. Method reference: Attention Is All You Need · §3.2 ↗
Open lab →attention-2 / 07Is “Bidirectional context” a benchmark of a deployed language model?
No. One synthetic head, four positions,
Original teaching answer / local derivation. Method reference: Attention Is All You Need · §3.2 ↗
Open lab →attention-2 / 08Which evidence should you report for “Bidirectional context”?
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 ↗
Open lab →attention-2 / 09How can another researcher reproduce “Bidirectional context”?
Open attention-2, 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 ↗
Open lab →attention-2 / 10What is the next validation step after “Bidirectional context”?
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 ↗
Open lab →Assumptions, implementation & acceptance
Self-attention: X is N×d_model; W_Q,W_K are d_model×d_k; W_V is d_model×d_v. Scores are N×N and output N×d_v. The variance argument assumes independent, zero-mean, unit-variance coordinates. Cross-attention can have different query/key lengths.
Engine formulas, scenario presets and numerical safeguards reviewed. Seeded synthetic inputs are not a production benchmark.
Before running: predict a boundary case
Removing the mask exposes future keys.
Hint: isolate the assumption
Keep the baseline input fixed, change one parameter or boundary, and compare both the numerical result and the claimed units. A passing example verifies this fixture only.
Minimal executable example
Save the example and linked modules in one folder. Use Node.js 22 or newer, then run node attention-2.mjs. No third-party runtime dependencies.
import {calculate,network} from './academy-core.mjs';
const params={
"scale": 1,
"causal": 0
};
const result=calculate('attention',params);
console.log(result.metrics);Test and transfer
Removing the mask exposes future keys.
Record input, code version, expected result and observed result in the notebook below. Then construct a counterexample that violates the assumption above and explain why the original conclusion no longer follows.
Download complete kit (.tar.gz) · Complete reference kit and regression checksPredict, test and keep evidence
Before revealing an answer, predict one result. After the exercise, record the discrepancy and a transfer test. Saved locally across language editions.
Open notebook / export / clear →The mathematical review scope is recorded per lesson. It does not establish empirical paper reproduction; report suspected errors in your notes. Review scope