Skip to content

Commit

Permalink
Merge pull request OpenNMT#654 from ratishsp/master
Browse files Browse the repository at this point in the history
Fixes issue of copy_loss_by_seqlength results in overflow over value …
srush authored Apr 11, 2018
2 parents 586e147 + c302378 commit df0a0f2
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion onmt/modules/CopyGenerator.py
Original file line number Diff line number Diff line change
@@ -207,7 +207,7 @@ def _compute_loss(self, batch, output, target, copy_attn, align):
# Compute Loss as NLL divided by seq length
# Compute Sequence Lengths
pad_ix = batch.dataset.fields['tgt'].vocab.stoi[onmt.io.PAD_WORD]
tgt_lens = batch.tgt.ne(pad_ix).sum(0).float()
tgt_lens = batch.tgt.ne(pad_ix).float().sum(0)
# Compute Total Loss per sequence in batch
loss = loss.view(-1, batch.batch_size).sum(0)
# Divide by length of each sequence and sum

0 comments on commit df0a0f2

Please sign in to comment.