Fix PNP loss to make it work with negatives without related positives#660
Merged
KevinMusgrave merged 10 commits intoKevinMusgrave:devfrom Nov 11, 2023
Merged
Fix PNP loss to make it work with negatives without related positives#660KevinMusgrave merged 10 commits intoKevinMusgrave:devfrom
KevinMusgrave merged 10 commits intoKevinMusgrave:devfrom
Conversation
Adding details to NTXentLoss documentation
Owner
|
@interestingzhuo Any thoughts on this? |
Contributor
for effective training. |
Owner
|
Thanks @Puzer and @interestingzhuo ! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Currently PNP loss returns NaN if you have some negatives examples without related positive examples
labels = torch.tensor([1, 1, 2])Let's say you have anchor, positive and negative.
N_pos (from PNP loss) for labels in this case will be [2, 2, 0]
So in this case you will get devision by 0 and loss will be NaN as result.
This fix keeps only positive instances at the final stage.
I've tested that for my use-case and it works quite well.
However I'm not sure wether it's mathematically correct or not, maybe there is more reasonable fix of this issue.