4.4 Numerical Stability and Initialization

In Section 4.2, initializing our one-hidden-layer MLP with N(0,0.012)\mathcal{N}(0, 0.01^2) weights caused a sluggish first epoch, yet the network recovered and reached 87%87\% accuracy. What happens if we stack ten hidden layers of width 256256 with that same N(0,0.012)\mathcal{N}(0, 0.01^2) initialization? Ten epochs later, the loss has not budged from log⁡10≈2.30\log 10 \approx 2.30 and accuracy sits at 10%10\% random guessing. Conversely, if we initialize the weights with N(0,1)\mathcal{N}(0, 1), activations and gradients come out astronomically large, and a single SGD update throws the weights so far that the next forward pass overflows to inf and NaN.

As we saw in Section 4.3, forward activations and backward gradients pass through a product of KK weight and slope matrices across a KK-layer network. Unless each layer preserves the signal variance, keeping its multiplicative factor near 11, signals either vanish exponentially to zero or explode exponentially to infinity. In this section, we quantify per-layer variance propagation, derive Xavier and He initialization, verify them on a 10-layer MLP on Fashion-MNIST, and prove why initial weights must be random to break permutation symmetry among hidden units.

4.4.1 Vanishing and Exploding Gradients#

4.4.1.1 A Product over Layers#

In a KK-layer MLP with hidden layers Z(k)=H(k−1)W(k)+b(k)\mathbf{Z}^{(k)} = \mathbf{H}^{(k-1)}\mathbf{W}^{(k)} + \mathbf{b}^{(k)} and H(k)=ϕ(Z(k))\mathbf{H}^{(k)} = \phi(\mathbf{Z}^{(k)}) of width hh, the backward recurrence from Section 4.3 propagates activation gradients one layer down via

∂L∂H(k−1)=(∂L∂H(k)⊙ϕ′(Z(k))) W(k)⊤.(4.4.1)\frac{\partial L}{\partial \mathbf{H}^{(k-1)}} = \Bigl(\frac{\partial L}{\partial \mathbf{H}^{(k)}} \odot \phi'\bigl(\mathbf{Z}^{(k)}\bigr)\Bigr)\, \mathbf{W}^{(k)\top}. \tag{4.4.1}

Unrolling (4.4.1) from the top hidden layer K−1K - 1 down to layer kk expresses the gradient at layer kk as a product of K−1−kK - 1 - k matrix--slope factors:

∂L∂H(k)=∂L∂H(K−1)  ⊙ ϕ′(Z(K−1)) W(K−1)⊤⏟layer K−1⋯  ⊙ ϕ′(Z(k+1)) W(k+1)⊤⏟layer k+1.(4.4.2)\begin{aligned} \frac{\partial L}{\partial \mathbf{H}^{(k)}} &= \frac{\partial L}{\partial \mathbf{H}^{(K-1)}}\; \underbrace{\odot\, \phi'\bigl(\mathbf{Z}^{(K-1)}\bigr)\, \mathbf{W}^{(K-1)\top}}_{\textrm{layer } K-1} \\ &\quad \cdots\; \underbrace{\odot\, \phi'\bigl(\mathbf{Z}^{(k+1)}\bigr)\, \mathbf{W}^{(k+1)\top}}_{\textrm{layer } k+1}. \end{aligned} \tag{4.4.2}

For a single example with upstream gradient row g′\mathbf{g}' and downstream gradient row g\mathbf{g} across a layer of width hh whose weights wijw_{ij} are drawn i.i.d. with mean 00 and variance τ2\tau^2, each coordinate gi=∑j=1hwij ϕ′(zj) gj′g_i = \sum_{j=1}^h w_{ij}\,\phi'(z_j)\,g'_j has expected square (treating weights, slopes, and upstream gradients as approximately independent at initialization)

E[gi2]=∑j=1hE[wij2] E[ϕ′(zj)2] E[(gj′)2]=h τ2 E[ϕ′(z)2]⏟per-layer factor E[(gj′)2].(4.4.3)\begin{aligned} \mathbb{E}[g_i^2] &= \sum_{j=1}^h \mathbb{E}[w_{ij}^2]\,\mathbb{E}[\phi'(z_j)^2]\,\mathbb{E}[(g'_j)^2] \\ &= \underbrace{h\, \tau^2\, \mathbb{E}\bigl[\phi'(z)^2\bigr]}_{\textrm{per-layer factor}}\, \mathbb{E}[(g'_j)^2]. \end{aligned} \tag{4.4.3}

Across tt layers, the gradient's mean square is multiplied by (h τ2 E[ϕ′(z)2])t\big(h\,\tau^2\,\mathbb{E}[\phi'(z)^2]\big)^t. For symmetric pre-activations and ReLU, ϕ′(z)∈{0,1}\phi'(z) \in \{0, 1\} is 11 half the time, so E[ϕ′(z)2]=1/2\mathbb{E}[\phi'(z)^2] = 1/2 and the per-layer multiplier is 12hτ2\frac{1}{2}h\tau^2. At width h=256h = 256:

  • With τ=0.01\tau = 0.01: the multiplier is 256×10−4/2=0.0128256 \times 10^{-4} / 2 = 0.0128, which after 99 hops shrinks the gradient mean square by 0.01289≈10−170.0128^9 \approx 10^{-17} vanishing gradients.
  • With τ=1\tau = 1: the multiplier is 256×1/2=128256 \times 1 / 2 = 128, which after 99 hops inflates the gradient mean square by 1289≈1019128^9 \approx 10^{19} exploding gradients.
  • With sigmoid activations (σ′(z)≤1/4\sigma'(z) \leq 1/4, so E[σ′(z)2]≤1/16\mathbb{E}[\sigma'(z)^2] \leq 1/16): even if hτ2=1h\tau^2 = 1, every layer shrinks the gradient mean square by at least a factor of 1616 ((Bengio et al., 1994)).

Let us verify these three predictions directly on a 10-layer, width-256 network at initialization using moments:

def moments(phi, dphi, scale, depth=10, width=256, n=256):
    """Mean squares of the activations and of their gradients, per layer."""
    Ws = [scale * torch.randn(width, width) for _ in range(depth)]
    H, Zs, acts = torch.randn(n, width), [], []
    for W in Ws:  # forward pass, keeping the pre-activations
        Zs.append(H @ W)
        H = phi(Zs[-1])
        acts.append(float((H ** 2).mean()))
    G, grads = torch.randn(n, width), []  # dL/dH at the top layer
    for W, Z in zip(reversed(Ws), reversed(Zs)):  # backward pass
        grads.insert(0, float((G ** 2).mean()))
        G = (G * dphi(Z)) @ W.T  # dL/dH one layer down
    return acts, grads

relu = (torch.relu, lambda Z: (Z > 0).float())
sigmoid = (torch.sigmoid, lambda Z: torch.sigmoid(Z) * (1 - torch.sigmoid(Z)))

Let us compare three setups: ReLU with τ=0.01\tau = 0.01 (as in Section 4.2), ReLU with τ=1\tau = 1, and sigmoid with τ2=1/256\tau^2 = 1/256 (so hτ2=1h\tau^2 = 1, isolating pure activation attenuation).

runs = {'ReLU, N(0, 0.01²)': moments(*relu, 0.01),
        'ReLU, N(0, 1)': moments(*relu, 1.0),
        'sigmoid, N(0, 1/256)': moments(*sigmoid, 1 / 16)}
for name, (acts, grads) in runs.items():
    print(f'{name}: gradient mean square at layer 1: {grads[0]:.1e}')
d2l.plot(list(range(1, 11)), [grads for acts, grads in runs.values()],
         'layer', 'mean square of gradient', legend=list(runs),
         yscale='log', figsize=(4.5, 3))
ReLU, N(0, 0.01²): gradient mean square at layer 1: 8.5e-18
ReLU, N(0, 1): gradient mean square at layer 1: 8.2e+18
sigmoid, N(0, 1/256): gradient mean square at layer 1: 5.5e-12

On a logarithmic vertical axis, all three curves are straight lines whose slopes match our analytical multiplier (4.4.3) (10−1710^{-17}, 101910^{19}, and 5×10−125 \times 10^{-12} at layer 1).

4.4.2 Parameter Initialization#

4.4.2.1 Xavier Initialization#

How do we choose the initial weight variance τ2\tau^2 so that every layer's multiplier equals 11? Consider a linear layer oj=∑i=1ninxiwijo_j = \sum_{i=1}^{n_{\textrm{in}}} x_i w_{ij} with ninn_{\textrm{in}} inputs (the layer's fan-in) and noutn_{\textrm{out}} outputs (its fan-out), where weights wijw_{ij} are i.i.d. with mean 00 and variance τ2\tau^2 and inputs xix_i are uncorrelated with mean 00 and variance γ2\gamma^2. In the forward pass, E[oj]=0\mathbb{E}[o_j] = 0 and

Var[oj]=E[oj2]=∑i=1ninE[xi2] E[wij2]=nin τ2γ2.\mathrm{Var}[o_j] = \mathbb{E}[o_j^2] = \sum_{i=1}^{n_{\textrm{in}}} \mathbb{E}[x_i^2]\,\mathbb{E}[w_{ij}^2] = n_{\textrm{in}}\, \tau^2 \gamma^2.

Preserving forward variance across the layer requires ninτ2=1n_{\textrm{in}}\tau^2 = 1. By (4.4.3) with unit slope, preserving backward gradient variance requires noutτ2=1n_{\textrm{out}}\tau^2 = 1. When nin≠noutn_{\textrm{in}} \neq n_{\textrm{out}}, Xavier initialization (or Glorot initialization, (Glorot and Bengio, 2010)) averages the two fan counts:

12(nin+nout) τ2=1⟺τ2=2nin+nout,(4.4.4)\frac{1}{2}(n_{\textrm{in}} + n_{\textrm{out}})\,\tau^2 = 1 \quad \Longleftrightarrow \quad \tau^2 = \frac{2}{n_{\textrm{in}} + n_{\textrm{out}}}, \tag{4.4.4}

drawing weights either from N ⁣(0,2nin+nout)\mathcal{N}\!\left(0, \frac{2}{n_{\textrm{in}} + n_{\textrm{out}}}\right) or from the variance-matched uniform interval U ⁣(−6nin+nout, 6nin+nout)U\!\left(-\sqrt{\frac{6}{n_{\textrm{in}} + n_{\textrm{out}}}},\, \sqrt{\frac{6}{n_{\textrm{in}} + n_{\textrm{out}}}}\right). Xavier initialization is the standard choice for linear and zero-centered unit-slope activations such as tanh⁡\tanh.

4.4.2.2 He Initialization#

For ReLU layers, zeroing out the negative half of a symmetric zero-mean pre-activation zz cuts its mean square in half: E[ReLU(z)2]=12E[z2]\mathbb{E}[\mathrm{ReLU}(z)^2] = \frac{1}{2}\mathbb{E}[z^2]. Because E[oj2]=ninτ2 E[xi2]\mathbb{E}[o_j^2] = n_{\textrm{in}}\tau^2\,\mathbb{E}[x_i^2] holds for zero-mean independent weights even when the inputs xi=ReLU(zi)x_i = \mathrm{ReLU}(z_i) have positive mean, the activation mean square v(k)=E[(hi(k))2]v^{(k)} = \mathbb{E}[(h_i^{(k)})^2] evolves across a ReLU layer as

v(k)=12 nin τ2 v(k−1).(4.4.5)v^{(k)} = \frac{1}{2}\, n_{\textrm{in}}\, \tau^2\, v^{(k-1)}. \tag{4.4.5}

Keeping v(k)=v(k−1)v^{(k)} = v^{(k-1)} constant across depth therefore requires doubling the variance:

τ2=2nin.(4.4.6)\tau^2 = \frac{2}{n_{\textrm{in}}}. \tag{4.4.6}

This is He initialization (or Kaiming initialization, (He et al., 2015)), the default for ReLU networks (note that standard framework layers often default to 1/(3nin)1/(3n_{\textrm{in}}), 1/nin1/n_{\textrm{in}}, or Xavier unless He is requested explicitly).

4.4.2.3 Activations, Gradients, and Training across Depth#

Let us first compare N(0,0.012)\mathcal{N}(0, 0.01^2), Xavier (τ2=1/256\tau^2 = 1/256), and He (τ2=2/256\tau^2 = 2/256) across our 10-layer synthetic ReLU probe moments(*relu, ...):

runs = {'N(0, 0.01²)': moments(*relu, 0.01),
        'Xavier': moments(*relu, (1 / 256) ** 0.5),
        'He': moments(*relu, (2 / 256) ** 0.5)}
for name, (acts, grads) in runs.items():
    print(f'{name}: activations at layer 10: {acts[-1]:.1e}, '
          f'gradient at layer 1: {grads[0]:.1e}')
d2l.plot(list(range(1, 11)), [acts for acts, grads in runs.values()],
         'layer', 'mean square of activations', legend=list(runs),
         yscale='log', figsize=(4.5, 3))
N(0, 0.01²): activations at layer 10: 1.2e-19, gradient at layer 1: 1.2e-17
Xavier: activations at layer 10: 7.4e-04, gradient at layer 1: 1.9e-03
He: activations at layer 10: 5.7e-01, gradient at layer 1: 8.3e-01

Notice how N(0,0.012)\mathcal{N}(0, 0.01^2) crushes layer-10 activations to ∼10−19\sim 10^{-19} and Xavier halves the activation mean square at every ReLU layer (∼2−10≈10−3\sim 2^{-10} \approx 10^{-3} by layer 10), whereas He initialization keeps both activations and gradients near O(1)O(1). To see how this variance propagation governs real training, we now define a 10-hidden-layer ReLU classifier DeepMLP parameterized by a per-layer standard-deviation rule std(n_in, n_out):

class DeepMLP(d2l.Classifier):
    """A deep MLP whose weights have the standard deviation std(n_in, n_out)."""
    def __init__(self, std, lr, depth=10, width=256):
        super().__init__()
        self.save_hyperparameters(ignore=['std'])
        sizes = [784] + [width] * depth + [10]
        layers = [nn.Flatten()]
        for n_in, n_out in zip(sizes[:-1], sizes[1:]):
            layer = nn.Linear(n_in, n_out)
            nn.init.normal_(layer.weight, std=std(n_in, n_out))
            nn.init.zeros_(layer.bias)
            layers += [layer, nn.ReLU()]
        self.net = nn.Sequential(*layers[:-1])  # No ReLU after the logits

All three runs share the exact same architecture and hyperparameters, varying only std(n_in, n_out). Let us compare their training curves and final validation accuracies.

inits = {'N(0, 0.01²)': lambda n_in, n_out: 0.01,
         'Xavier': lambda n_in, n_out: (2 / (n_in + n_out)) ** 0.5,
         'He': lambda n_in, n_out: (2 / n_in) ** 0.5}
data = d2l.FashionMNIST(batch_size=256)
losses = {}
for name, std in inits.items():
    trainer = d2l.Trainer(max_epochs=10, num_gpus=1)
    trainer.board.display = False
    trainer.fit(DeepMLP(std, lr=0.05), data)
    losses[name] = trainer.history['train_loss']
    print(f'{name}: validation accuracy {trainer.history["val_acc"][-1]:.2f}')
d2l.plot(list(range(1, 11)), list(losses.values()), 'epoch', 'training loss',
         legend=list(losses), figsize=(4.5, 3))
N(0, 0.01²): validation accuracy 0.10
Xavier: validation accuracy 0.84
He: validation accuracy 0.87

Look at how closely the 10-epoch training curves follow our variance analysis:

  • Under N(0,0.012)\mathcal{N}(0, 0.01^2), layer-10 activations (∼10−19\sim 10^{-19}) and layer-1 gradients (∼10−17\sim 10^{-17}) vanish completely, leaving the training loss frozen at log⁡10≈2.30\log 10 \approx 2.30 and validation accuracy at 10%10\%.
  • Under Xavier, losing a factor of 22 per ReLU layer shrinks signals by 2−10≈10−32^{-10} \approx 10^{-3}, causing a slower first epoch before training recovers to above 80%80\% accuracy.
  • Under He initialization, both activations and gradients stay near order 11 across all 10 layers and training drops smoothly from the very first epoch.

Initialization is not the whole answer to depth, though. The variance argument describes the network at step 00 only: once SGD has moved the weights, nothing keeps the per-layer factor of (4.4.3) near 11. Networks with dozens or hundreds of layers therefore rely on mechanisms that act throughout training. Normalization layers (Section 7.3) rescale the activations at every step, residual connections (Section 7.4) give signals and gradients a path around each layer, and gradient clipping (Section 8.4) caps the occasional exploding gradient. A good initialization gets training started. These mechanisms keep the signals scaled afterwards.

4.4.3 Symmetry among Hidden Units#

Why must initial weights be random rather than setting every entry of W(1)\mathbf{W}^{(1)} to the deterministic constant c=2/ninc = \sqrt{2 / n_{\textrm{in}}}? Because hidden units within a layer are permutation-symmetric: if all columns of W(1)\mathbf{W}^{(1)} start identical (and all rows of W(2)\mathbf{W}^{(2)} start identical), then every hidden unit computes the same forward activation, receives the same backward gradient, and takes the same SGD update step forever, collapsing a 256-unit layer into a single effective neuron. Let us verify on a 16-unit layer that constant He-scaled weights give identical gradient columns (0.00 difference between units), whereas random He-scaled weights give every unit a distinct gradient direction:

def hidden_grad(W1, W2, X, y):
    """Gradient of the squared loss with respect to the hidden weights."""
    W1 = W1.clone().requires_grad_(True)
    L = ((torch.relu(X @ W1) @ W2 - y) ** 2).mean() / 2
    L.backward()
    return W1.grad

d, h = 20, 16
X, y = torch.randn(64, d), torch.randn(64, 1)
c, c_out = (2 / d) ** 0.5, (1 / h) ** 0.5
inits = {'constant': (torch.full((d, h), c), torch.full((h, 1), c_out)),
         'random': (c * torch.randn(d, h), c_out * torch.randn(h, 1))}
for name, (W1, W2) in inits.items():
    G = hidden_grad(W1, W2, X, y)
    print(f'{name}: largest difference between two hidden units '
          f'{float((G - G[:, :1]).abs().max()):.2f}')
constant: largest difference between two hidden units 0.00
random: largest difference between two hidden units 0.16

4.4.4 Summary#

Across a KK-layer MLP of width hh and initial weight variance τ2\tau^2, each layer multiplies activation and gradient mean squares by roughly hτ2 E[ϕ′(z)2]h\tau^2\,\mathbb{E}[\phi'(z)^2], causing signals to vanish or explode exponentially with depth unless that factor stays close to 11. Xavier initialization sets τ2=2/(nin+nout)\tau^2 = 2/(n_{\textrm{in}} + n_{\textrm{out}}) to balance forward and backward variance in linear and tanh⁡\tanh layers, while He initialization doubles the variance to τ2=2/nin\tau^2 = 2/n_{\textrm{in}} to offset ReLU zeroing out its negative half-line, allowing deep ReLU stacks to train cleanly from the first epoch. Because hidden units within a layer are permutation-symmetric, weights must also be drawn independently at random rather than set to a constant; otherwise every unit receives identical gradients and updates throughout training. Beyond step 00, deeper architectures pair variance-preserving initialization with normalization layers and residual connections to keep signals well scaled as weights evolve.

4.4.5 Exercises#

  1. Spectral norm bounds. For a single example, written as a column vector, the step (4.4.1) multiplies the gradient g′\mathbf{g}' above layer kk by the matrix M(k)=W(k)diag⁡(ϕ′(z(k)))\mathbf{M}^{(k)} = \mathbf{W}^{(k)} \operatorname{diag}\bigl(\phi'(\mathbf{z}^{(k)})\bigr), where diag⁡(⋅)\operatorname{diag}(\cdot) places the entries of a vector on the diagonal of an otherwise zero matrix, so the gradient in (4.4.2) is a product of K−1−kK - 1 - k such matrices times the gradient at the top. The spectral norm (the largest singular value) is submultiplicative: ∥AB∥2≤∥A∥2∥B∥2\|\mathbf{A}\mathbf{B}\|_2 \le \|\mathbf{A}\|_2 \|\mathbf{B}\|_2.

    1. Prove submultiplicativity from the definition ∥A∥2=max⁡x≠0∥Ax∥/∥x∥\|\mathbf{A}\|_2 = \max_{\mathbf{x} \neq 0} \|\mathbf{A}\mathbf{x}\| / \|\mathbf{x}\|.
    2. Use it to bound the norm of the gradient in terms of the norms ∥M(k)∥2\|\mathbf{M}^{(k)}\|_2 of the factors. Which condition on these norms keeps the bound from growing geometrically with depth?
    3. This bound is only an upper bound. Explain why the condition of the previous part rules out exploding gradients but not vanishing ones, and give two 2×22 \times 2 matrices that satisfy the condition with equality but whose product has spectral norm strictly smaller than one.
  2. Other symmetries. Permuting the hidden units is not the only change of parameters that leaves the function of an MLP unchanged. Consider a one-hidden-layer MLP in which hidden unit jj has incoming weights wj\mathbf{w}_j, bias bjb_j, and outgoing weights vj\mathbf{v}_j.

    1. Prove that ReLU(αz)=α ReLU(z)\textrm{ReLU}(\alpha z) = \alpha\, \textrm{ReLU}(z) for α>0\alpha > 0. Use this identity to show that replacing (wj,bj,vj)(\mathbf{w}_j, b_j, \mathbf{v}_j) by (αwj,αbj,vj/α)(\alpha \mathbf{w}_j, \alpha b_j, \mathbf{v}_j / \alpha) leaves the function of a ReLU network unchanged.
    2. Find a transformation of the parameters of a single hidden unit that leaves the function of a tanh⁡\tanh network unchanged.
    3. Identical hidden units are a fixed point of the permutation, and gradient descent started at that fixed point stays there. Find the parameters of a unit that the transformation of the previous part leaves unchanged. Then show that if all weights and biases of a tanh⁡\tanh network are initialized to zero, gradient descent changes only the output bias, at every step.

    Adapted from Simon Prince, Understanding Deep Learning, Problems 3.5, 4.3, and 7.15.

  3. Fan-in versus averaged fans. Following He et al. (2015), consider a linear network with KK layers in which layer kk maps nk−1n_{k-1} inputs to nkn_k outputs and draws its weights with variance τk2\tau_k^2. By the computation of Section 4.4.2.1, layer kk multiplies the variance of the forward signal by nk−1τk2n_{k-1}\tau_k^2 and that of the backward signal by nkτk2n_k\tau_k^2.

    1. Set τk2=1/nk−1\tau_k^2 = 1/n_{k-1} in every layer. Show that the forward variance is preserved and that the backward variance changes by the total factor nK/n0n_K / n_0 at any depth.
    2. Let the widths alternate as 100,400,100,400,…100, 400, 100, 400, \ldots, and use Xavier initialization in every layer. Compute the factor by which one 100→400→100100 \to 400 \to 100 pair of layers multiplies the forward variance, and the factor after 50 such pairs.
    3. Which of the two rules keeps both variances within a depth-independent factor of their initial values for every sequence of widths?
  4. Variance under ReLU. ● The derivation in Section 4.4.2.2 tracks the mean square E[ReLU(z)2]\mathbb{E}[\textrm{ReLU}(z)^2] rather than the variance, because the next layer's pre-activation o=∑ixiwio = \sum_i x_i w_i, with inputs xi=ReLU(zi)x_i = \textrm{ReLU}(z_i) and independent zero-mean weights has Var[o]=ninτ2E[xi2]\textrm{Var}[o] = n_\textrm{in}\tau^2 \mathbb{E}[x_i^2] for any mean of xix_i.

    1. For z∼N(0,ν2)z \sim \mathcal{N}(0, \nu^2), compute E[ReLU(z)]\mathbb{E}[\textrm{ReLU}(z)] and Var[ReLU(z)]\textrm{Var}[\textrm{ReLU}(z)], and show that the variance equals (12−12π)ν2\left(\tfrac{1}{2} - \tfrac{1}{2\pi}\right)\nu^2 rather than 12ν2\tfrac{1}{2}\nu^2.
    2. A tempting shortcut substitutes Var[xi]\textrm{Var}[x_i] for E[xi2]\mathbb{E}[x_i^2] in the Xavier computation. Show that this shortcut prescribes τ2=2/(nin(1−1/π))\tau^2 = 2 / \bigl(n_\textrm{in}(1 - 1/\pi)\bigr) instead of 2/nin2/n_\textrm{in}. Compute the factor by which each ReLU layer initialized this way actually multiplies the mean square, and the total factor over fifty layers.
  5. [code] Tanh networks. ● Repeat the measurement of Section 4.4.2.3 with tanh⁡\tanh in place of ReLU, with Xavier initialization and fifty layers. A layer then maps the mean square mm of its input to m′=E[tanh⁡(z)2]m' = \mathbb{E}[\tanh(z)^2], where zz is approximately N(0,m)\mathcal{N}(0, m).

    1. Use tanh⁡(z)2≈z2−23z4\tanh(z)^2 \approx z^2 - \tfrac{2}{3}z^4 for small zz to show that m′≈m−2m2m' \approx m - 2m^2. Over many layers, does the mean square stay constant, decay geometrically, or decay more slowly? Show that the mean square at layer kk is about 1/(2k)1/(2k) for large kk.
    2. Check the prediction by plotting the measured mean square against the layer on logarithmic axes. What happens to the gradient?

Discussions