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

multiple negative for MNRL #3139

Open
OnAnd0n opened this issue Dec 19, 2024 · 5 comments
Open

multiple negative for MNRL #3139

OnAnd0n opened this issue Dec 19, 2024 · 5 comments

Comments

@OnAnd0n
Copy link

OnAnd0n commented Dec 19, 2024

@tomaarsen
where can i read it in your code, positive + multiple negative to n_columns.
I can't find it...

image

and I have questions following

  • should all data samples have same length of negatives for MNRL ?

  • how to garantee for sampling Hard-negative ?
    : {a1, p1, n1-1, n1-2, n1-3}, {a2, p2, n2-1, n2-2, n2-3} => a train_sample in batch : {a1, p1, n1-1, n1-2, n1-3, n2-2, n3-1, ....}

    i read your explanation from Understanding how (hard) negatives in MNRL are used #3097

@Jakobhenningjensen
Copy link

All your hard-negatives are used for all your positives i.e say you have 10 (anchor, positives) then each (anchor, positive) would use all the other "positives" as negatives.

You can then decide to add negatives aswell but they are used for all (anchor, positives) pair i.e if you have 10 (anchor, positives) and 5 negatives then you would (for each (anchor, positive) pair) have 9 + 5 = 14 negatives.

That means that your negatives are not specific to an (anchor, positive) pair (if you want that you should use the TripletLoss).

@OnAnd0n
Copy link
Author

OnAnd0n commented Dec 20, 2024

@Jakobhenningjensen
thank you for your kind explanation.

You can then decide to add negatives aswell but they are used for all (anchor, positives) pair i.e if you have 10 (anchor, positives) and 5 negatives then you would (for each (anchor, positive) pair) have 9 + 5 = 14 negatives.

=> you mean, If I train with 32 data samples, each consisting of {anchor, positive, and 3 negatives},
there are 127(= 31 positives + 96 negatives) negatives for each anchor.
so, {anchor, positive, 127 negatives} is in-batch sample in MNRL. Is it right?


          "data shape"                                                                   "In-batch input"
{a1, p1, n1-1, n1-2, n1-3}                                             {a1, p1,  [127 negatives for anchor1] }
{a2, p2, n2-1, n2-2, n2-3}                                             {a2, p2,  [127 negatives for anchor2] }
                      ...                        =>                                       ...
{a32, p32, n32-1, n32-2, n32-3}                                     {a32, p32,  [127 negatives for anchor32] }

@Jakobhenningjensen
Copy link

In the MNRL (if I'm correct) you don't have negatives for each anchor/positives but you just provide a list of general hard negatives i.e if your "negative" column has 5 elements then you would have additional 5 negatives (which are all the same) for each sample, since you would just add those 5 elements to your "hard-negatives" for each batch

@Jakobhenningjensen
Copy link

I thought it worked as if you provided hard negatives for that specific anchor/positive pairs, but you don't. Im currently looking a implementing a loss that does exactly that

@OnAnd0n
Copy link
Author

OnAnd0n commented Dec 23, 2024

@Jakobhenningjensen
thank you for your kind explanation.

But in docs, input shape for MNRL is (anchor, positive, negative_1, …, negative_n)
So, Are [hard negatives for that specific anchor/positive pairs] used in loss respectively?

image
Loss-overview

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

No branches or pull requests

2 participants