Alterna · learning material

When a model really learns

As long as the program only calculates the answer, the weights remain the same. The learning begins with their change by mistake.

What this material covers

Content and key concepts

On the previous page, entry and rule of conversion.
As long as the program only calculates the answer, the weights remain the same. The learning begins with their change by mistake.
The model calculates the answer using numerical settings. The program around it prepares the entrance and can trigger a search or a tool.
Для интерактивного эксперимента нужен JavaScript. Теория, модель и ручные расчёты выше доступны без него.
Criterion turns error into a number
Let
x=2
the famous Target
y*=6
and the model with
w=1
,
b=0
Gives away.
y=2
It's not enough to say "bad answer" automatically for an automatic setting. You need to define an objective. Take a single example:
e
=
y
−
y
∗
,
L
=
1
2
e
2
.
e=y-y^*,\qquad L=\frac12e^2.
e
=
y
−
y
∗
,
L
=
2
1
​
e
2
.
Loss is non-negative and equals zero with exact coincidence.
1/2
It's an educational regression obprojective, not a universal measure for any model.
For dataset from
N
The following examples can be average:
L
D
(
θ
)
=
1
N
∑
a
=
1
N
1
2
(
f
θ
(
x
a
)
−
y
a
∗
)
2
.
L_D(\theta)=\frac1N\sum_{a=1}^{N}\frac12\left(f_\theta(x_a)-y_a^*\right)^2.
L
D
​
(
θ
)
=
N
1
​
a
=
1
∑
N
​
2
1
​
(
f
θ
​
(
x
a
​
)
−
y
a
∗
​
)
2
.
The optimizer sees this criterion on selected data; it does not directly minimize "reasonableness, safety or quality" on all possible future inputs.
Withdrawal of gradient without black box
For
y=wx+b
I'll increase it.
w
Small
δ
while retaining
x
and
b
A new mistake equals
e+xδ
, so
L
(
w
+
δ
,
b
)
−
L
(
w
,
b
)
δ
=
e
x
+
1
2
x
2
δ
.
\frac{L(w+\delta,b)-L(w,b)}{\delta}
=ex+\frac12x^2\delta.
δ
L
(
w
+
δ
,
b
)
−
L
(
w
,
b
)
​
=
e
x
+
2
1
​
x
2
δ
.
Prix
δ→0
received
∂L/∂w=ex
. Same.
∂L/∂b=e
I. Gradient
∇
θ
L
=
[
e
x
,
e
]
\nabla_\theta L=[ex,e]
∇
θ
​
L
=
[
e
x
,
e
]
indicates the direction of local growth in coordinates
(w,b)
. Gradient descent uses the opposite direction:
w
n
e
w
=
w
−
η
e
x
,
b
n
e
w
=
b
−
η
e
,
w_{new}=w-\eta ex,\qquad b_{new}=b-\eta e,
w
n
e
w
​
=
w
−
ηe
x
,
b
n
e
w
​
=
b
−
ηe
,
where
η>0
- Learning rate. Both gradient values are in the same old state and should be applied simultaneously.
w
, count
e
and then update it.
b
It's gonna be another algorithm.
One fully verifiable step
For
x=2
,
w=1
,
b=0
,
y*=6
,
η=.1
:
Stage
Calculation
Meaning
Forward
y=1·2+0
2
Error
e=2−6
−4
Loss
.5·(−4)²
8
Gradient
[ex,e]
[−8,−4]
Update
(1,0)−.1·(−8,−4)
(1.8,.4)
New Forward
1.8·2+.4
4
New loss
.5·(4−6)²
2
Why a big step can make the loss worse
Let's put extradate in a new mistake for the same example:
e
n
e
w
=
[
1
−
η
(
x
2
+
1
)
]
e
.
e_{new}=\left[1-\eta(x^2+1)\right]e.
e
n
e
w
​
=
[
1
−
η
(
x
2
+
1
)
]
e
.
Prix
x=2
multiplier is equal to
1−5η
For
η=.1
The error module is halved.
η=.2
This is the only example that hits exactly the line.
2w+b=6
I. INTRODUCTION
η=.4
The error changes the sign, but saves the module, so the loss stays eight.
η=.5
The module becomes 1.5 times larger and the loss grows to 18.
The condition for reducing non-zero loss in this specific one-dimensional task is:
∣
1
−
5
η
∣
<
1
⟺
0
<
η
<
0.4.
|1-5\eta|<1\quad\Longleftrightarrow\quad0<\eta<0.4.
∣1
−
5
η
∣
<
1
⟺
0
<
η
<
0.4.
This is not the universal tolerance range for neuronets. It's taken from the selected range.
x
, adjective and simultaneously update two parameters.
Zero Training Loss does not prove the law of the world
For one example, any parameter pair on a straight line
2w+b=6
Gives you a loss 0.
(3,0)
,
(2,2)
and
(1,4)
They explain the only point equally, but they give different preferences at
x=3
Optimization of training and synthesis are different issues: separate data, assumptions about the task and evaluation from unused examples are needed.
Training and inference are different computational branches.
Process
We need a Target.
Computes Gradient
Updates Parameters
Training step
Yes for a supervised example
Yes
Yeah, at the update stage.
Inference / forward
None
Not required
None
Adding an example in prompt changes the input. This can change actions and output at the same time. Few-shot mode GPT-3 is described without gradiant updates at the time of request.
S05
)] The name in-contect lightning should not be automatically interpreted as recording new coefficients in parameter store.
Separate from the model forward application, it is possible to keep history, and the future transaction pipeline is to use authorized data. The statement "normal inference does not update webs" is not a promise that a particular service does not store messages anywhere. These are different boundaries of the system, policy and operations.
Transparent Python: One update
def train_step(eta=.1):
x,w,b,target = 2,1,0,6
y = w*x+b
error = y-target
loss = .5*error**2
gw,gb = error*x,error
new_w,new_b = w-eta*gw,b-eta*gb
new_y = new_w*x+new_b
return {'y':y,'loss':loss,'gradient':[gw,gb],
'updated':[new_w,new_b],'new_y':new_y,'new_loss':.5*(new_y-target)**2}
In the autograd library, these derivatives will compute the transaction graph. In this chapter, they are written manually; NumPy/PyTorch and autograph will appear in detail after the mathematical foundation.
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.
Forward and loss calculate values for old parameters. Only the extradate assigns new values to the parameters.
How is the follow-up chosen? How does this question continue?
Academic base

Textbook contents map