PythiloLesson 8 of 8 · progress kept in this browser

Layer Normalization

Normalize within one token’s feature vector, using population variance and epsilon inside the square root. Learned gain and bias then restore useful scale.

import math
values = [1, 3]
mean, variance, epsilon = 2, 1, 3
print([(x-mean)/math.sqrt(variance+epsilon) for x in values])
Your task

layer_norm(values, gain, bias, epsilon) returns per-feature gain*(x-mean)/sqrt(variance+epsilon)+bias. Inputs are nonempty with matching widths; epsilon > 0.

All lessons