Alterna · learning material

16.2 Weight error and influence

First we measure the confidence in the correct answer, then we go back to the calculations. The output estimates turn into weight effects.

What this material covers

Content and key concepts

On the previous page, what is the correct answer?
First we measure the confidence in the correct answer, then we go back to the calculations. The output estimates turn into weight effects.
Each known electron produces a projection of the following. The error goes backwards on the program, the optimizer changes the weight, and the individual data checks the result. The dialog and preferences mark changes the objective.
Для изменения рисунка включитеJavaScript; расчёт и теория доступны далее.
Gradient starts with logits
For one Target
y
Softmax turns logits
z
in distribution, and negative log-likelihood fines the probability of the correct ID. Sustainable implementation subtracts to maximum
exp
For softmax, the derivative for each log is particularly simple.
p
j
=
e
z
j
−
m
∑
k
e
z
k
−
m
,
L
=
−
log
⁡
p
y
,
∂
L
∂
z
j
=
p
j
−
1
[
j
=
y
]
.
p_j=\frac{e^{z_j-m}}{\sum_k e^{z_k-m}},\quad
L=-\log p_y,\quad
\frac{\partial L}{\partial z_j}=p_j-\mathbf 1[j=y].
p
j
​
=
∑
k
​
e
z
k
​
−
m
e
z
j
​
−
m
​
,
L
=
−
lo
g
p
y
​
,
∂
z
j
​
∂
L
​
=
p
j
​
−
1
[
j
=
y
]
.
Positive components reduce incorrect logs at gradient descent, negative components increase Target logit. The sum is zero: adding one constant to all logs does not change softmax. For batch/token matrix first apply mask, then explicitly selects
sum
or mean by number
VALID TARGETS
not by the size of the padded testor.
That's what the model shows.
Inspector shows logs, shifted target, probabilities, token loss and
dL/dz
Before passing the backward through LM Head and blocks.
exp(mean NLL)
It makes sense only with the same tokenizer and the same policy of masking; the meaning cannot be honestly compared between arbitrary dictionaries as a universal scale of quality.
Scope of applicability.
Low-tech-token loss does not prove validity, safety, or ability to follow instructions. Floating-point overflow is prevented by a stable form, but training can still get NaN from acts, gradiants or optimizer state. Gradient clapping limits noorm subdate signal rather than "correcting" bad data and does not guarantee convergence.
from math import exp,log
logits_16b=[1.0,0.0,-1.0]; target_16b=0; pivot_16b=max(logits_16b)
raw_16b=[exp(v-pivot_16b) for v in logits_16b]; probs_16b=[v/sum(raw_16b) for v in raw_16b]
loss_16b=-log(probs_16b[target_16b]); grad_16b=[p-(i==target_16b) for i,p in enumerate(probs_16b)]
assert abs(loss_16b-0.40760596444438046)<1e-12 and abs(sum(grad_16b))<1e-12
The code repeats the operations just taken care of.
Completely checked Python-example Chapter
Available with a separate file; the short piece shown does not replace its implementation.
Mask deletes the item from the objective, but token may remain the input.
How does this matter continue?
Python examples of Chapter 16
Academic base

Textbook contents map