Token LabSearch

← All experiments
Attention & masking / 5 OF 5

Soft attention

A smaller scale moves weights toward uniform without changing visibility.

Local calculation / simulation

Local educational experiment. No external API calls. Synthetic fixtures are not production measurements.

Study guide & lesson outlineLEARNING CONTRACT

Understand → implement → investigate

Goal: explain the mechanism in this lesson, reproduce one example and test a failure case. Reading alone does not mark mastery.

02 · Predict & configure

Technical scenario notes, parameter names and reference answers are currently in English.

03 · Inspect the evidence

Run this experiment to see results.

Methods & references

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 ↗

Practice questions

attention-5 / 01What does “Soft attention” test?

A smaller scale moves weights toward uniform without changing visibility.

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

Open lab →
attention-5 / 02Which computation produces the result in “Soft attention”?

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

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

Open lab →
attention-5 / 03What is the baseline configuration for “Soft attention”?

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

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

Open lab →
attention-5 / 04What numerical result should you check for “Soft attention”?

{"Mean entropy (bits)":1.1377371118107673,"Last output":3.700414589154465}

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

Open lab →
attention-5 / 05How would you run a controlled comparison for “Soft attention”?

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-5 / 06What failure could invalidate a conclusion from “Soft attention”?

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-5 / 07Is “Soft attention” 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 ↗

Open lab →
attention-5 / 08Which evidence should you report for “Soft attention”?

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-5 / 09How can another researcher reproduce “Soft attention”?

Open attention-5, 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-5 / 10What is the next validation step after “Soft attention”?

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 →
MATHEMATICAL REVIEW · 2026-10-26

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.

Q,K,V · four token rows → QKᵀ / √d · apply causal mask → Row softmax · allowed weights sum to 1 → Weighted V · check future invariance
Mechanism map: follow the transformations from top to bottom.

Before running: predict a boundary case

A smaller scale moves weights toward uniform without changing visibility.

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-5.mjs. No third-party runtime dependencies.

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

Test and transfer

A smaller scale moves weights toward uniform without changing visibility.

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 checks

Predict, 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