Example 1
Arguments: [
[
[
1,
3
]
],
[
1,
1
],
[
0,
0
],
0
]
Expected result: [
[
-1,
1
]
]The mean is 2 and variance is 1, giving [-1,1].
Tensor and numerical foundations · Medium
Problem 5 of 50 · Python and NumPy
Center and normalize each activation row, then apply a learned affine transform. Use population variance mean((x−mean(x))²), not sample variance. Compute y = (x−mean)/sqrt(variance+eps)*weight+bias.
def layer_norm(x, weight, bias, eps):Arguments: [
[
[
1,
3
]
],
[
1,
1
],
[
0,
0
],
0
]
Expected result: [
[
-1,
1
]
]The mean is 2 and variance is 1, giving [-1,1].
Arguments: [
[
[
2,
2
]
],
[
3,
4
],
[
1,
-1
],
1
]
Expected result: [
[
1,
-1
]
]A constant row centers to zero, so the output equals bias [1,-1].