Compute a small additive attention layer and follow its gradients.
Preparation: Vector addition, weighted averages and tanh.
Plan 20–35 minutes with the activities; this is a study estimate, not a timed requirement. Both paths have complete narration. Your notes and progress are kept separately for each level.
FULL LOCAL NARRATION
Follow the complete explanation.
Narration includes worked solutions. Pause at each practice prompt before continuing. Formula notation has a spoken explanation; all teaching text remains readable.
College path. Compute a small additive attention layer and follow its gradients.
Preparation: Vector addition, weighted averages and tanh. Work through one section at a time. Predict the experiment result before changing its controls, then explain what the example leaves out.
Additive attention builds a compatibility score by transforming the query and each source, adding them, applying a nonlinearity, and projecting to a scalar. A common score is v transpose tanh(Wq q + Wk k_i + b). The hidden attention width need not equal the query or key width.
Worked step 1. Use scalar query q=0 and keys [-1,0,1].
Worked step 2. Set both projections and v to 1, bias 0.
Worked step 3. Scores are about [-0.762,0,0.762].
Try it yourself. Are these scores already probabilities?
Pause the recording and write your reasoning before continuing. The worked solution follows.
Reveal worked solution
Worked solution. No. They can be negative and need normalization before being used as ordinary attention weights.
Section 02 / 07
Keep the axes explicit
One query generates one score per source. Multiple queries generate a table. Broadcasting is a convenient implementation technique, but it must reproduce the intended query-source comparisons. Projected queries have shape Tq by h and keys Tk by h. Their broadcast sum is Tq by Tk by h; the final projection removes h.
Worked step 1. Two queries and three keys produce six comparisons.
Worked step 2. With hidden width four, the temporary tensor has 24 entries.
Worked step 3. Final scores have shape 2 by 3.
Try it yourself. Is the output length three because there are three keys?
Pause the recording and write your reasoning before continuing. The worked solution follows.
Reveal worked solution
Worked solution. No. There are two output query positions. Key count controls how many source alternatives each query can combine.
Section 03 / 07
Normalize across sources
Softmax turns each query’s source scores into nonnegative weights summing to one. Mask invalid sources before normalization. A padding source must not quietly receive a share. Use a stable softmax by subtracting each row maximum. With at least one valid source, masked scores can be negative infinity; handle fully masked rows explicitly.
αᵢ = exp(eᵢ)/Σⱼexp(eⱼ)
Worked step 1. For scores [-0.762,0,0.762], weights are roughly [0.1294,0.2771,0.5935].
Worked step 2. Their sum is one within rounding.
Try it yourself. What happens if only the middle source is valid?
Pause the recording and write your reasoning before continuing. The worked solution follows.
Reveal worked solution
Worked solution. Its weight becomes one and the others zero. If no source is valid, the application needs a defined fallback.
Section 04 / 07
Values carry the result
Compatibility scores choose weights; values provide the information being combined. Changing values can change the output without changing the compatibility scores in this separated fixture. The context is the sum of alpha_i times value_i. Its feature width follows the values. Do not confuse key representations used for scoring with value representations used for aggregation.
Worked step 1. Use weights [0.2,0.3,0.5] and scalar values [10,20,30].
Worked step 2. Products are 2,6,15.
Worked step 3. The weighted result is 23.
Try it yourself. If every value increases by 5, what happens?
Pause the recording and write your reasoning before continuing. The worked solution follows.
Reveal worked solution
Worked solution. The result increases by 5 because the weights sum to one. The score computation is unchanged in this fixture.
Section 05 / 07
Differentiate both nonlinearities
Learning passes through the weighted sum, softmax and tanh. Large absolute tanh inputs have small derivatives, which can weaken a gradient along that branch. For h=tanh(z), the derivative is 1-h squared. Softmax couples scores: changing one score changes every normalized weight. Check gradients by finite differences on a tiny fixture.
Worked step 1. At z=0, tanh derivative is 1.
Worked step 2. At z=2, tanh is about 0.964 and derivative about 0.071.
Worked step 3. Compare responses to a small input change.
Try it yourself. Does saturation mean the entire model cannot learn?
Pause the recording and write your reasoning before continuing. The worked solution follows.
Reveal worked solution
Worked solution. No. It describes this local derivative. Other parameters, examples and paths can still receive useful gradients.
Section 06 / 07
Compare mechanisms fairly
Additive and dot-product attention use different compatibility functions. Precomputing key projections can reduce repeated work. Actual speed depends on tensor sizes, kernels and hardware. Additive scoring often materializes or computes a query-key-hidden interaction. Scaled dot product maps well to matrix multiplication. Complexity and numerical behavior must be compared for a specified configuration.
Worked step 1. Hold query, key and value counts fixed.
Worked step 2. Record score shapes and peak temporary storage.
Worked step 3. Benchmark after warm-up with the same precision.
Try it yourself. Is additive attention always faster?
Pause the recording and write your reasoning before continuing. The worked solution follows.
Reveal worked solution
Worked solution. No. The compatibility formula alone does not determine measured latency. Report the configuration and implementation.
Section 07 / 07
Mastery and transfer
Bring the pieces together. First answer the checkpoint without the worked solutions. Then explain the mechanism in your own words, using one numerical example from this lesson.
Additive attention normalizes scores across… Option 1: Hidden feature coordinates only. Option 2: Valid source positions for each query. Option 3: All unrelated examples together.
Pause here and choose an answer before continuing. The checkpoint explanation follows.
Reveal worked solution
The correct choice is option 2: Valid source positions for each query. Each query has its own distribution over permitted sources.
Transfer task. Change one assumption in the worked example. State your prediction, calculate or test it in Workbench, then explain whether the result supports your prediction.
Reveal worked solution
Self-check rubric. Name the changed assumption, keep the other inputs fixed, show at least one intermediate calculation, and distinguish what the toy example guarantees from what would require a trained model or a real measurement.
WORKBENCH / PREDICT → TEST → EXPLAIN
Inspect exact numerical data
These are computed teaching fixtures. No remote AI model or GPU is called by the experiment.
CHECK YOUR UNDERSTANDING
Commit to an explanation.
Keep your learning record.
Sources and scope
Original worked examples and teaching text, grounded in these primary references. Numerical fixtures explain mechanisms; model quality and hardware performance require separate measurements. Both levels share key examples, with different explanations and checkpoints.