rnn-tutorial-rnnlm
rnn-tutorial-rnnlm copied to clipboard
I think there is something wrong with code of the function of calculate_total_loss
Hi, since the loss function formula is
$ \begin{aligned} L(y,o) = - \frac{1}{N} \sum_{n \in N} y_{n} \log o_{n} \end{aligned} $
And the code in RNNLM.ipynb is
def calculate_total_loss(self, x, y):
L = 0
# For each sentence...
for i in np.arange(len(y)):
o, s = self.forward_propagation(x[i])
# We only care about our prediction of the "correct" words
correct_word_predictions = o[np.arange(len(y[i])), y[i]]
# Add to the loss based on how off we were
L += -1 * np.sum(np.log(correct_word_predictions))
return L
L += -1 * np.sum(np.log(correct_word_predictions))
didn't take $y_n$ that is the true labels into consideration. I'm not sure I am right, maybe $y_n$ is just 1 with one-hot encoding. Am I right? Thank you!
It uses one-hot encoding. The true labels are accounted for with the indexing of o
.