I'm currently working on deriving the the gradients of a simple recurrent neural networks weights with respect to the loss to update the weights through backpropagation. It's a super simple network, so the derivative isn't the challenge, it's figuring out what exactly $\frac{\partial h_1}{\partial W_{hh}}$ is. When $h_1$ is the first hidden node and has no $W_{hh}$ coming into it from a previous node what happens here? Is there something that is supposed to be connected to $h_1$ (other than $x_1$ through $W_{xh}$)? Below is the gradient I'm looking at for reference and I'm looking for the very last term when $k=1$.
-
$\begingroup$ I am not so sure about your equation and notion - thats why I did not post an answer, yet. But I can state the obvious: if $h_1$ is not a function of $W_{hh}$, then the derivative $\frac{\partial h_1}{W_{hh}}=0$. $\endgroup$– BroeleCommented Aug 12 at 7:28
-
$\begingroup$ Can you give a source for that equation or at least what architecture you are using and what your variables mean? $\endgroup$– BroeleCommented Aug 12 at 11:03
-
$\begingroup$ @Broele mmuratarat.github.io/2019-02-07/bptt-of-rnn this is where that specific equation comes from, the small network I'm working with is essentially the same as the unfolded network at the top of that article, and my issue is if $h_{t-1} = h_1$ and there was no $W_{hh}$ connected to it from a previous $h$. Hopefully that makes some sense $\endgroup$– namor129Commented Aug 12 at 11:14
1 Answer
Derivative of unrelated variables
If $h_1$ is no function of $W_{hh}$ (which is the case for the first time-step), then $$\frac{\partial h_1}{\partial W_{hh}} = 0$$ This will then lead to the whole summand for $k=1$ being $0$ and we could rewrite it as
$$\frac{\partial L}{\partial W_{hh}}=\sum_t^T\sum_{k=2}^{t+1}\ldots$$
(Note the $k=2$ part, here).
The first time-step
So why not just simply start with $k=2$?
Because based on the link you gave, the first timestep is $t=0$:
NOTE: At the first time step, t=0, there are no previous outputs, so they are typically assumed to be all zeros.
This means that $$h_1 = f_h(X_1, h_0)$$ but $$\frac{\partial h_0}{\partial W_{hh}} = 0$$ This is the reason, that the sum in the derivative starts at $k=1$ and not $k=0$.
-
$\begingroup$ I see, I guess I was overthinking what was going on. Thanks for the explanation! $\endgroup$– namor129Commented Aug 12 at 19:04