Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I think there is something wrong with code of the function of calculate_total_loss #16

Open
GoingMyWay opened this issue May 5, 2017 · 1 comment

Comments

@GoingMyWay
Copy link

GoingMyWay commented May 5, 2017

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!

@DanielTakeshi
Copy link

It uses one-hot encoding. The true labels are accounted for with the indexing of o .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants