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

[WIP v2 - deprecated] Unlikelihood token loss #2011

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

funboarder13920
Copy link
Collaborator

@funboarder13920 funboarder13920 changed the title Unlikelihood token loss implementation Unlikelihood token loss Feb 19, 2021
Copy link
Member

@francoishernandez francoishernandez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few comments.

-heads 4 -transformer_ff 64 \
-word_vec_size 16 -report_every 5 \
-rnn_size 16 -train_steps 10
- name: Test LM training with unlieklihood loss
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo 'unlikelihood'

opt.label_smoothing, len(tgt_field.vocab),
ignore_index=padding_idx
)
elif opt.unlikelihood_coeff > 0:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we assert in the opts validation that unlikelihood_coeff isn't compatible with label_smoothing?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can make them mutually exclusive with the parser or I can make both of them compatible at the same time as unlikelihood_coeff can be added to any loss (but label smoothing and unlikelihood are contradictory)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, let's go for the mutually exclusive way.

@@ -177,7 +177,7 @@ def forward(self, scores, align, target):
return loss


class CommonCopyGeneratorLossCompute(CommonLossCompute):
class CommonCopyGeneratorLossCompute(LossComputeBase):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure to grasp the whole rationale behind the CommonLossCompute/LossComputeBase refactoring. Is the last big remaining difference only the log_ppl computation?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Underlying question is: do we really need both CommonLossCompute and LossComputeBase anymore?)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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

Copy link
Member

Choose a reason for hiding this comment

The 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

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

normalization was already not used a year ago

def __init__(self, criterion, generator, normalization="sents",

"""

def __init__(self, unlikelihood_coeff, ignore_index=-100):
assert 0.0 < unlikelihood_coeff
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add an explicit message here?

target.size(0), target.size(1), target.size(0)
).permute(1, 2, 0)

ctx_cands = (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More explicit variable name? Or at least a comment?

@vince62s
Copy link
Member

vince62s commented Dec 7, 2022

@funboarder13920 @francoishernandez would it be worth updating wrt the v3 and merging or shall we drop ?

@francoishernandez francoishernandez marked this pull request as draft December 19, 2022 17:19
@vince62s vince62s changed the title Unlikelihood token loss [WIP v2 - deprecated] Unlikelihood token loss Jan 19, 2023
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

Successfully merging this pull request may close these issues.

None yet

3 participants