Md. Asif Uddin

    Proposition 2I.10.P0234 of 100 in the corpus

    A gate slows the decay of a distant gradient; it does not abolish it.

    The carry line is one path among many. Its own factor is a product of forget values, which still decays geometrically. The other paths bring the recurrent weights back, and can shrink the signal or amplify it.

    The carry line's factor for three constant forget valuesThree straight lines on a logarithmic scale show f to the power n over a thousand steps. With f equal to 0.9 the factor falls below one ten-thousandth before step ninety. With 0.99 it crosses the dashed 1/e line near step one hundred and falls below one ten-thousandth a little after step nine hundred. With 0.999 it reaches 1/e at the right-hand edge.carry-line factor · constant forget value10.10.010.00110⁻⁴1/e02505007501000steps along the carry line, nf = 0.9f = 0.99f = 0.999
    Fig. 2 — Type G · Failure — The carry line's own factor for constant forget values 0.9, 0.99 and 0.999 over a thousand steps, on a logarithmic scale. Each crosses the dashed 1/e line within one step of 1/(1 − f). A forget value near one slows the decay; it does not stop it.

    The state is a pair

    The LSTM’s state at step tt is the pair (ct,ht)(\vec c_t,\vec h_t). A perturbation of either changes the next step, so the one-step Jacobian has four blocks. Differentiate (I.10.1) and (I.10.2) with σ′=σ(1−σ)\sigma'=\sigma(1-\sigma) and tanh⁡′=1−tanh⁡2\tanh'=1-\tanh^2:

    Jt=[diag⁡(ft)MtDtdiag⁡(ft)Nt],Mt=diag⁡(ct−1⊙ft⊙(1−ft))Wf+diag⁡(c~t⊙it⊙(1−it))Wi+diag⁡(it⊙(1−c~t2))Wc,Dt=diag⁡(ot⊙(1−tanh⁡2ct)),Nt=diag⁡(tanh⁡(ct)⊙ot⊙(1−ot))Wo+DtMt.\begin{aligned} \mat J_t&= \begin{bmatrix} \operatorname{diag}(\vec f_t) & \mat M_t\\ \mat D_t\operatorname{diag}(\vec f_t) & \mat N_t \end{bmatrix},\\[4pt] \mat M_t&=\operatorname{diag}\big(\vec c_{t-1}\odot\vec f_t\odot(1-\vec f_t)\big)\mat W_f\\ &\quad+\operatorname{diag}\big(\tilde{\vec c}_t\odot\vec i_t\odot(1-\vec i_t)\big)\mat W_i\\ &\quad+\operatorname{diag}\big(\vec i_t\odot(1-\tilde{\vec c}_t^2)\big)\mat W_c,\\[4pt] \mat D_t&=\operatorname{diag}\big(\vec o_t\odot(1-\tanh^2\vec c_t)\big),\\ \mat N_t&=\operatorname{diag}\big(\tanh(\vec c_t)\odot\vec o_t\odot(1-\vec o_t)\big)\mat W_o +\mat D_t\mat M_t. \end{aligned}
    (I.10.4)

    Only the top-left block is free of recurrent weights.

    The rows are ct\vec c_t and ht\vec h_t; the columns are ct−1\vec c_{t-1} and ht−1\vec h_{t-1}. The top-left block is the carry line of (I.10.3). The block Mt=∂ct/∂ht−1\mat M_t=\partial\vec c_t/\partial\vec h_{t-1} collects the three ways the preceding hidden state reaches the cell: through the forget gate, the input gate and the candidate. The bottom row passes the cell through the output nonlinearity and adds the output gate’s own dependence on ht−1\vec h_{t-1}.

    Now multiply JT⋯Js+1\mat J_T\cdots\mat J_{s+1} and read the top-left block, which is ∂cT/∂cs\partial\vec c_T/\partial\vec c_s. Expanding the product of block matrices gives a sum over paths, one block chosen per step. The path that stays in the top-left block at every step contributes diag⁡(fs+1⊙⋯⊙fT)\operatorname{diag}(\vec f_{s+1}\odot\cdots\odot\vec f_T). Any other path leaves the cell row at some step. Since it must end on the cell row, it has to return, and the only block from the hidden state to the cell is some Mk\mat M_k. Every other term therefore contains at least one recurrent matrix. That proves I.10.T1.

    The theorem guarantees that a weight-free path exists. It does not say that path dominates. When the gates and candidate are saturated, the factors f⊙(1−f)\vec f\odot(1-\vec f), i⊙(1−i)\vec i\odot(1-\vec i) and 1−c~21-\tilde{\vec c}^2 are small, Mt\mat M_t is small, and the carry line carries most of the signal. That is the regime the 1997 truncation assumed. Away from it, the other paths can be as large as the carry line or larger.

    The carry line still multiplies

    Even on its own, the carry line is a product. Suppose a coordinate’s forget value is the same number ff at every step. After nn steps its factor is fn=enln⁡ff^n=e^{n\ln f}. Define the memory horizon m=−1/ln⁡fm=-1/\ln f, the number of steps over which the factor falls by ee.

    Apply ln⁡x≤x−1\ln x\leq x-1, with equality only at x=1x=1, at x=fx=f and at x=1/fx=1/f. The first gives −ln⁡f>1−f-\ln f>1-f; the second gives −ln⁡f<(1−f)/f-\ln f<(1-f)/f. Inverting,

    fn=e−n/m,f1−f<m<11−f,f=σ(b)  ⟹  11−f=1+eb.\begin{aligned} f^n&=e^{-n/m},\qquad \frac{f}{1-f}<m<\frac{1}{1-f},\\ f=\sigma(b)&\implies\frac{1}{1-f}=1+e^{b}. \end{aligned}
    (I.10.5)

    A forget value sets a horizon within one step of 1/(1−f); a bias sets the forget value.

    The second line uses 1−σ(b)=σ(−b)=1/(1+eb)1-\sigma(b)=\sigma(-b)=1/(1+e^{b}). With b=ln⁡(m−1)b=\ln(m-1) the right-hand side is exactly mm. That proves I.10.T2.

    The figure plots fnf^n for f=0.9f=0.9, 0.990.99 and 0.9990.999 over a thousand steps. The first is gone below 10−410^{-4} before step ninety. The second keeps 0.3660320.366032 of its signal after a hundred steps and 4.3×10−54.3\times10^{-5} after a thousand. The third reaches 1/e1/e near the right-hand edge. Each curve is still a straight line on the logarithmic scale: the decay is geometric, as in I.9. What changed is the rate. It is a learned quantity, set coordinate by coordinate, which can sit close to one without asking a weight matrix to have norm close to one and without asking any unit to stay unsaturated. I.10.B03 works the limit.

    Where the forget bias starts

    At initialisation the weights are small, so a forget gate’s value is close to σ(bf)\sigma(b_f). A zero bias gives f=1/2f=1/2: a horizon of 1/ln⁡2≈1.441/\ln2\approx1.44 steps, which forgets almost everything before training has started. A bias of one gives f=0.731059f=0.731059 and 1/(1−f)=1+e≈3.721/(1-f)=1+e\approx3.72.

    Jozefowicz, Zaremba and Sutskever found that adding a bias of one to the forget gate closed the gap they had measured between the LSTM and the GRU. Keras adds one to the forget bias by default through unit_forget_bias. PyTorch does not: it draws every weight and bias uniformly from (−1/H,1/H)(-1/\sqrt H,1/\sqrt H), and its two bias vectors both have a forget slice, so the effective bias is their sum (I.10.X02).

    Tallec and Ollivier went further. Their chrono initialisation sets bf=ln⁡ub_f=\ln u with uu drawn uniformly between 11 and Tmax⁡−1T_{\max}-1, and bi=−bfb_i=-b_f. By (I.10.5) the initial horizons then range from two steps to the longest dependency expected, and i=1−fi=1-f makes each cell coordinate an exponential moving average of its candidates (I.10.X08). All of these choices set where training starts, not where it ends.

    Growth is still possible

    The other paths of (I.10.4) can amplify. Take a scalar cell whose gates are constants, i=1/2i=1/2 and f=o=3/4f=o=3/4, and whose candidate reads the hidden state through a weight of two. Then hth_t is a function of ctc_t alone, and each step’s total factor is f+i(1−c~t2) wc o(1−tanh⁡2ct−1)f+i(1-\tilde c_t^2)\,w_c\,o(1-\tanh^2c_{t-1}). Along the trajectory of I.10.B02 the factors are 1.2213261.221326 and 1.0788271.078827, so ∂c3/∂c1=1.317600\partial c_3/\partial c_1=1.317600. The carry line alone contributes 0.752=0.56250.75^2=0.5625. More than half the derivative came from paths through wcw_c, and the total exceeds one although every forget value is three quarters.

    The same mechanism can make a small perturbation grow. In I.10.X09 a cell with forget value one half amplifies a perturbation of the zero state by 1.6251.625 per step. Gating changes which paths exist; it does not bound their sum. Gradient norm clipping, (I.9.7), remains a standard part of training gated networks.

    The cell value itself is not bounded by a squashing function. Since ∣i c~∣<1|i\,\tilde c|<1, each coordinate satisfies ∣ct∣≤ft∣ct−1∣+1|c_t|\leq f_t|c_{t-1}|+1. If every forget value is at most φ<1\varphi<1, summing the geometric series gives

    ∣ct∣≤φt∣c0∣+1−φt1−φ,|c_t|\leq\varphi^t|c_0|+\frac{1-\varphi^t}{1-\varphi},

    and with φ=1\varphi=1 the bound is ∣c0∣+t|c_0|+t. That is the LSTM half of I.10.T3, and the reason for the forget gate. A large cell value also saturates tanh⁡(ct)\tanh(c_t), which makes Dt\mat D_t small: the gradient from the output into the cell vanishes while the carry line remains open.

    Backward through one cell

    Write gˉh,t\bar{\vec g}_{h,t} for the total derivative of the loss with respect to ht\vec h_t, including the local readout and everything returned from step t+1t+1, and gˉc,t\bar{\vec g}_{c,t} for the total derivative with respect to ct\vec c_t. Then

    gˉc,t=gˉh,t⊙ot⊙(1−tanh⁡2ct)+gˉc,t+1⊙ft+1,δo,t=gˉh,t⊙tanh⁡(ct)⊙ot⊙(1−ot),δf,t=gˉc,t⊙ct−1⊙ft⊙(1−ft),δi,t=gˉc,t⊙c~t⊙it⊙(1−it),δc,t=gˉc,t⊙it⊙(1−c~t2),\begin{aligned} \bar{\vec g}_{c,t}&=\bar{\vec g}_{h,t}\odot\vec o_t\odot(1-\tanh^2\vec c_t) +\bar{\vec g}_{c,t+1}\odot\vec f_{t+1},\\ \vec\delta_{o,t}&=\bar{\vec g}_{h,t}\odot\tanh(\vec c_t)\odot\vec o_t\odot(1-\vec o_t),\\ \vec\delta_{f,t}&=\bar{\vec g}_{c,t}\odot\vec c_{t-1}\odot\vec f_t\odot(1-\vec f_t),\\ \vec\delta_{i,t}&=\bar{\vec g}_{c,t}\odot\tilde{\vec c}_t\odot\vec i_t\odot(1-\vec i_t),\\ \vec\delta_{c,t}&=\bar{\vec g}_{c,t}\odot\vec i_t\odot(1-\tilde{\vec c}_t^2), \end{aligned}
    (I.10.6)

    The cell's gradient adds what it showed at this step to what it carried forward.

    with gˉc,T+1=0\bar{\vec g}_{c,T+1}=0. Each δ\vec\delta is the derivative with respect to a gate’s pre-activation. The hidden state one step back receives ∑kWkTδk,t\sum_k\mat W_k^{\mathsf T}\vec\delta_{k,t} over the four blocks, plus its own readout term; the cell one step back receives gˉc,t⊙ft\bar{\vec g}_{c,t}\odot\vec f_t. Shared weights accumulate exactly as in (I.9.4): ∇WkL=∑tδk,tht−1T\nabla_{\mat W_k}\mathcal L=\sum_t\vec\delta_{k,t}\vec h_{t-1}^{\mathsf T}, and likewise for Uk\mat U_k with xt\vec x_t.

    The first line of (I.10.6) is the carry line in the backward direction: the future’s cell gradient arrives multiplied by a forget value, with no matrix in between. I.10.B02 derives every line, and its script checks all twelve parameter blocks and both initial states of a two-unit cell against finite differences.

    Reproduce the horizons

    from math import log
    
    for f in (0.9, 0.99, 0.999):
        horizon = -1/log(f)
        print(f"{f}: f^100 = {f**100:.6f}, horizon {horizon:.3f},"
              f" bounds {f/(1-f):.1f} to {1/(1-f):.1f}")

    It prints horizons 9.4919.491, 99.49999.499 and 999.500999.500, each just under 1/(1−f)1/(1-f), with hundred-step factors 0.0000270.000027, 0.3660320.366032 and 0.9047920.904792.

    Sources