Skip to content

Commit

Permalink
Bug fix in the calculation of the validation loss (pytorch#427)
Browse files Browse the repository at this point in the history
The last row of tokens in data_source in never used as input data in the last batch. Those tokens are always only used as targets and thus the total_loss variable shouldn't be divided by len(data_source) but len(data_source) - 1 instead.
  • Loading branch information
trault14 authored and soumith committed Oct 29, 2018
1 parent 05ed879 commit 81f47e8
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion word_language_model/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def evaluate(data_source):
output_flat = output.view(-1, ntokens)
total_loss += len(data) * criterion(output_flat, targets).item()
hidden = repackage_hidden(hidden)
return total_loss / len(data_source)
return total_loss / (len(data_source) - 1)


def train():
Expand Down

0 comments on commit 81f47e8

Please sign in to comment.