-
Notifications
You must be signed in to change notification settings - Fork 2.3k
[WIP v2 - deprecated] Unlikelihood token loss #2011
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
6d93dcc
c1787a8
770f60d
118a43f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -2,7 +2,7 @@ | |||
import torch.nn as nn | ||||
|
||||
from onmt.utils.misc import aeq | ||||
from onmt.utils.loss import CommonLossCompute | ||||
from onmt.utils.loss import LossComputeBase | ||||
|
||||
|
||||
def collapse_copy_scores(scores, batch, tgt_vocab, src_vocabs=None, | ||||
|
@@ -177,7 +177,7 @@ def forward(self, scores, align, target): | |||
return loss | ||||
|
||||
|
||||
class CommonCopyGeneratorLossCompute(CommonLossCompute): | ||||
class CommonCopyGeneratorLossCompute(LossComputeBase): | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure to grasp the whole rationale behind the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Underlying question is: do we really need both There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The _compute_loss, _make_shard_state and the way to use the generator are different between CopyGeneratorLoss and the other classes There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can do it in one class, the code is already not very clear, it's not going to be worse. If we do that CopyGenerator will override _compute_loss, _compute_log_ppl and _compute_alignement_loss will only be used in the compute_loss of the main class There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes I think this might be a bit better to explicitly override this method instead of having a full class that we don't really know what it's for unless we look at this specific CopyGeneratorLoss. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I merged it, the ppl part is not nice. Also there is a normalization args that was not used anywhere, I will investigate to see if the normalization process disappeared by mistake There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. normalization was already not used a year ago Line 228 in 7835130
|
||||
"""Common Copy Generator Loss Computation.""" | ||||
def __init__(self, criterion, generator, tgt_vocab, normalize_by_length, | ||||
lambda_coverage=0.0, tgt_shift_index=1): | ||||
|
@@ -231,7 +231,8 @@ def _compute_loss(self, batch, output, target, copy_attn, align, | |||
target_data[correct_mask] += offset_align | ||||
|
||||
# Compute sum of perplexities for stats | ||||
stats = self._stats(loss.sum().clone(), scores_data, target_data) | ||||
stats = self._stats(loss.sum().clone(), loss.sum().clone(), | ||||
scores_data, target_data) | ||||
|
||||
# this part looks like it belongs in CopyGeneratorLoss | ||||
if self.normalize_by_length: | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo 'unlikelihood'