Here’s a notebook for training a Capsule Networks on MNIST dataset.
+
Here’s a notebook for training a Capsule Network on MNIST dataset.
@@ -351,12 +351,12 @@ The length of each output capsule is the probability that class is present in th
\lambda (1 - T_k) \max(0, \lVert\mathbf{v}_k\rVert - m^{-})^2
$T_k$ is $1$ if the class $k$ is present and $0$ otherwise.
-The first component of the loss is $0$ when if the class is not present,
-and the second component is $0$ is the class is present.
+The first component of the loss is $0$ when the class is not present,
+and the second component is $0$ if the class is present.
The $\max(0, x)$ is used to avoid predictions going to extremes.
$m^{+}$ is set to be $0.9$ and $m^{-}$ to be $0.1$ in the paper.
The $\lambda$ down-weighting is used to stop the length of all capsules from
-fallind during the initial phase of training.
+falling during the initial phase of training.
137classMarginLoss(Module):
diff --git a/docs/normalization/batch_norm/index.html b/docs/normalization/batch_norm/index.html
index 1888ef0f..ad1b211d 100644
--- a/docs/normalization/batch_norm/index.html
+++ b/docs/normalization/batch_norm/index.html
@@ -85,8 +85,8 @@ could be in distribution $\mathcal{N}(0.5, 1)$.
Then, after some training steps, it could move to $\mathcal{N}(0.5, 1)$.
This is internal covariate shift.
Internal covariate shift will adversely affect training speed because the later layers
-($l_2$ in the above example) has to adapt to this shifted distribution.
-
By stabilizing the distribution batch normalization minimizes the internal covariate shift.
+($l_2$ in the above example) have to adapt to this shifted distribution.
+
By stabilizing the distribution, batch normalization minimizes the internal covariate shift.
Normalization
It is known that whitening improves training speed and convergence.
Whitening is linearly transforming inputs to have zero mean, unit variance,
@@ -95,9 +95,9 @@ and be uncorrelated.
Normalizing outside the gradient computation using pre-computed (detached)
means and variances doesn’t work. For instance. (ignoring variance), let
-where $x = u + b$ and $b$ is a trained bias.
-and $\mathbb{E}[x]$ is outside gradient computation (pre-computed constant).
-
Note that $\hat{x}$ has no effect of $b$.
+where $x = u + b$ and $b$ is a trained bias
+and $\mathbb{E}[x]$ is an outside gradient computation (pre-computed constant).
+
Note that $\hat{x}$ has no effect on $b$.
Therefore,
$b$ will increase or decrease based
$\frac{\partial{\mathcal{L}}}{\partial x}$,
@@ -106,14 +106,14 @@ The paper notes that similar explosions happen with variances.
Batch Normalization
Whitening is computationally expensive because you need to de-correlate and
the gradients must flow through the full whitening calculation.
-
The paper introduces simplified version which they call Batch Normalization.
+
The paper introduces a simplified version which they call Batch Normalization.
First simplification is that it normalizes each feature independently to have
zero mean and unit variance:
where $x = (x^{(1)} … x^{(d)})$ is the $d$-dimensional input.
The second simplification is to use estimates of mean $\mathbb{E}[x^{(k)}]$
and variance $Var[x^{(k)}]$ from the mini-batch
-for normalization; instead of calculating the mean and variance across whole dataset.
+for normalization; instead of calculating the mean and variance across the whole dataset.
Normalizing each feature to zero mean and unit variance could affect what the layer
can represent.
As an example paper illustrates that, if the inputs to a sigmoid are normalized
@@ -126,8 +126,8 @@ where $y^{(k)}$ is the output of the batch normalization layer.
like $Wu + b$ the bias parameter $b$ gets cancelled due to normalization.
So you can and should omit bias parameter in linear transforms right before the
batch normalization.
-
Batch normalization also makes the back propagation invariant to the scale of the weights.
-And empirically it improves generalization, so it has regularization effects too.
+
Batch normalization also makes the back propagation invariant to the scale of the weights
+and empirically it improves generalization, so it has regularization effects too.
Inference
We need to know $\mathbb{E}[x^{(k)}]$ and $Var[x^{(k)}]$ in order to
perform the normalization.
@@ -136,7 +136,7 @@ and find the mean and variance, or you can use an estimate calculated during tra
The usual practice is to calculate an exponential moving average of
mean and variance during the training phase and use that for inference.
Here’s the training code and a notebook for training
-a CNN classifier that use batch normalization for MNIST dataset.
+a CNN classifier that uses batch normalization for MNIST dataset.
@@ -251,7 +251,7 @@ mean $\mathbb{E}[x^{(k)}]$ and variance $Var[x^{(k)}]$
#
x is a tensor of shape [batch_size, channels, *].
-* could be any number of (even 0) dimensions.
+* denotes any number of (possibly 0) dimensions.
For example, in an image (2D) convolution this will be
[batch_size, channels, height, width]
@@ -286,7 +286,7 @@ mean $\mathbb{E}[x^{(k)}]$ and variance $Var[x^{(k)}]$
Sanity check to make sure the number of features is same
+
Sanity check to make sure the number of features is the same
174assertself.channels==x.shape[1]
diff --git a/docs/sitemap.xml b/docs/sitemap.xml
index 112e8b84..bbd43813 100644
--- a/docs/sitemap.xml
+++ b/docs/sitemap.xml
@@ -85,14 +85,14 @@
https://nn.labml.ai/normalization/layer_norm/index.html
- 2021-02-02T16:30:00+00:00
+ 2021-02-12T16:30:00+00:001.00https://nn.labml.ai/normalization/layer_norm/readme.html
- 2021-02-02T16:30:00+00:00
+ 2021-02-12T16:30:00+00:001.00
@@ -477,7 +477,7 @@
https://nn.labml.ai/capsule_networks/index.html
- 2021-01-30T16:30:00+00:00
+ 2021-02-12T16:30:00+00:001.00
diff --git a/labml_nn/normalization/batch_norm/__init__.py b/labml_nn/normalization/batch_norm/__init__.py
index 0e914a0c..eef75e2c 100644
--- a/labml_nn/normalization/batch_norm/__init__.py
+++ b/labml_nn/normalization/batch_norm/__init__.py
@@ -22,9 +22,9 @@ Then, after some training steps, it could move to $\mathcal{N}(0.5, 1)$.
This is *internal covariate shift*.
Internal covariate shift will adversely affect training speed because the later layers
-($l_2$ in the above example) has to adapt to this shifted distribution.
+($l_2$ in the above example) have to adapt to this shifted distribution.
-By stabilizing the distribution batch normalization minimizes the internal covariate shift.
+By stabilizing the distribution, batch normalization minimizes the internal covariate shift.
## Normalization
@@ -37,10 +37,10 @@ and be uncorrelated.
Normalizing outside the gradient computation using pre-computed (detached)
means and variances doesn't work. For instance. (ignoring variance), let
$$\hat{x} = x - \mathbb{E}[x]$$
-where $x = u + b$ and $b$ is a trained bias.
-and $\mathbb{E}[x]$ is outside gradient computation (pre-computed constant).
+where $x = u + b$ and $b$ is a trained bias
+and $\mathbb{E}[x]$ is an outside gradient computation (pre-computed constant).
-Note that $\hat{x}$ has no effect of $b$.
+Note that $\hat{x}$ has no effect on $b$.
Therefore,
$b$ will increase or decrease based
$\frac{\partial{\mathcal{L}}}{\partial x}$,
@@ -52,7 +52,7 @@ The paper notes that similar explosions happen with variances.
Whitening is computationally expensive because you need to de-correlate and
the gradients must flow through the full whitening calculation.
-The paper introduces simplified version which they call *Batch Normalization*.
+The paper introduces a simplified version which they call *Batch Normalization*.
First simplification is that it normalizes each feature independently to have
zero mean and unit variance:
$$\hat{x}^{(k)} = \frac{x^{(k)} - \mathbb{E}[x^{(k)}]}{\sqrt{Var[x^{(k)}]}}$$
@@ -60,7 +60,7 @@ where $x = (x^{(1)} ... x^{(d)})$ is the $d$-dimensional input.
The second simplification is to use estimates of mean $\mathbb{E}[x^{(k)}]$
and variance $Var[x^{(k)}]$ from the mini-batch
-for normalization; instead of calculating the mean and variance across whole dataset.
+for normalization; instead of calculating the mean and variance across the whole dataset.
Normalizing each feature to zero mean and unit variance could affect what the layer
can represent.
@@ -76,8 +76,8 @@ like $Wu + b$ the bias parameter $b$ gets cancelled due to normalization.
So you can and should omit bias parameter in linear transforms right before the
batch normalization.
-Batch normalization also makes the back propagation invariant to the scale of the weights.
-And empirically it improves generalization, so it has regularization effects too.
+Batch normalization also makes the back propagation invariant to the scale of the weights
+and empirically it improves generalization, so it has regularization effects too.
## Inference
@@ -89,7 +89,7 @@ The usual practice is to calculate an exponential moving average of
mean and variance during the training phase and use that for inference.
Here's [the training code](mnist.html) and a notebook for training
-a CNN classifier that use batch normalization for MNIST dataset.
+a CNN classifier that uses batch normalization for MNIST dataset.
[](https://colab.research.google.com/github/lab-ml/nn/blob/master/labml_nn/normalization/batch_norm/mnist.ipynb)
[](https://web.lab-ml.com/run?uuid=011254fe647011ebbb8e0242ac1c0002)
@@ -162,7 +162,7 @@ class BatchNorm(Module):
def forward(self, x: torch.Tensor):
"""
`x` is a tensor of shape `[batch_size, channels, *]`.
- `*` could be any number of (even 0) dimensions.
+ `*` denotes any number of (possibly 0) dimensions.
For example, in an image (2D) convolution this will be
`[batch_size, channels, height, width]`
"""
@@ -170,7 +170,7 @@ class BatchNorm(Module):
x_shape = x.shape
# Get the batch size
batch_size = x_shape[0]
- # Sanity check to make sure the number of features is same
+ # Sanity check to make sure the number of features is the same
assert self.channels == x.shape[1]
# Reshape into `[batch_size, channels, n]`