Md. Asif Uddin
    Problem I.9.B02

    Every use of a weight contributes

    symbolic▲▲▲

    Exact values where possible; six decimal places for non-exact numerical results.

    STATEMENT

    Derive backpropagation through time and compute every parameter gradient for the forward pass in I.9.B01.

    GIVEN

    Use (I.9.1) and a sum of per-step losses for the derivation. For the numerical case use the linear scalar cell, inputs (1,2,0)(1,2,0), h0=0h_0=0, (u,w,b,v,c)=(1,1/2,0,2,0)(u,w,b,v,c)=(1,1/2,0,2,0), and final target one.

    FIND

    The recurrent backward rule, the shared-weight accumulation rule, all five scalar parameter gradients, input derivatives and initial-state derivative.

    STRATEGY

    First add the two incoming backward signals at each state. Differentiate the activation, then accumulate the local parameter contributions. Specialise to the identity activation only after deriving the tanh rule.

    SOLUTION

    The readout at time tt contributes VTet\mat V^{\mathsf T}\vec e_t to its state. The next cell contributes WTδt+1\mat W^{\mathsf T}\vec\delta_{t+1}. Multiplying their sum by the coordinatewise tanh derivative gives (I.9.3).

    For a shared recurrent-weight entry WijW_{ij}, the local differential is dat,i=ht−1,j dWijd a_{t,i}=h_{t-1,j}\,dW_{ij}. Summing all uses gives

    ∂L∂Wij=∑tδt,iht−1,j.\frac{\partial\mathcal L}{\partial W_{ij}} =\sum_t\delta_{t,i}h_{t-1,j}.

    This is the entrywise derivation of (I.9.4), not an average over time. If the objective is an average, its factor is already in et\vec e_t.

    In the linear example, z3−y=3/2z_3-y=3/2 and the activation derivative is one. Only the final readout has a loss. Starting from the end,

    δ3=v(z3−y)=3,δ2=wδ3=3/2,δ1=wδ2=3/4.\begin{aligned} \delta_3&=v(z_3-y)=3,\\ \delta_2&=w\delta_3=3/2,\\ \delta_1&=w\delta_2=3/4. \end{aligned}

    The local contributions to ww are therefore 00, 3/23/2 and 15/215/2:

    ∂wL=δ1h0+δ2h1+δ3h2=9,∂uL=δ1x1+δ2x2+δ3x3=15/4,∂bL=δ1+δ2+δ3=21/4,∂vL=(z3−y)h3=15/8,∂cL=z3−y=3/2.\begin{aligned} \partial_w\mathcal L &=\delta_1h_0+\delta_2h_1+\delta_3h_2=9,\\ \partial_u\mathcal L &=\delta_1x_1+\delta_2x_2+\delta_3x_3=15/4,\\ \partial_b\mathcal L&=\delta_1+\delta_2+\delta_3=21/4,\\ \partial_v\mathcal L&=(z_3-y)h_3=15/8,\\ \partial_c\mathcal L&=z_3-y=3/2. \end{aligned}

    Input derivatives are uδtu\delta_t, giving (3/4,3/2,3)(3/4,3/2,3). The initial-state derivative is wδ1=3/8w\delta_1=3/8. We compute the latter even though this example does not optimise h0h_0.

    For an independent algebraic check, with b=c=h0=0b=c=h_0=0 the final state is h3=u(w2+2w)h_3=u(w^2+2w). Thus ∂wz3=vu(2w+2)=6\partial_w z_3=vu(2w+2)=6, and ∂wL=(3/2)6=9\partial_w\mathcal L=(3/2)6=9.

    The reproduction script perturbs each parameter by 10−610^{-6}, recomputes the full forward loss and compares central differences with the analytic derivative. It additionally checks tanh cells with losses at multiple steps and a two-coordinate state with non-symmetric recurrent weights. The latter catches transpose errors that a scalar example cannot.

    The script and run command are in the numeric check on I.9.B01.

    Answer

    In the order (u,w,b,v,c)(u,w,b,v,c) the gradient is (3.75,9,5.25,1.875,1.5)(3.75,9,5.25,1.875,1.5). All three time steps contribute to the same parameter objects.

    Check — sanity

    Since h0=0h_0=0, the first local ww contribution is zero, but the first input still receives a nonzero derivative. “This use contributes zero” does not mean “this time step is disconnected.”

    Where this breaks

    Updating parameters inside the backward sweep would mix derivatives of different forward computations. Accumulate first, then take one optimiser step. A detached boundary also removes terms and must be tested as a different graph.

    Variation

    If all three time steps had local output losses, replace each zero local readout derivative by its actual value in (I.9.3). The future term remains; local supervision does not replace it.

    Draws on