-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Add triplet margin for distance functions in TripletEvaluator #2862
Add triplet margin for distance functions in TripletEvaluator #2862
Conversation
Hello! Thanks for this PR. I made some changes as I noticed that cosine, manhattan, and Euclidean were based on "distance", but dot was based on similarity instead. I've now updated all to use similarity, so that higher is always better regardless of which similarity function is used. I've also renamed the parameter to I also added a test. Please let me know what you think @zivicmilos!
|
Hey @tomaarsen! Thanks for reviewing the PR and adding the improvements. Everything looks good to me, I just added a few more changes:
|
Hello! Apologies for the delay - I still wanted to add d8f4c3d to ensure that there's no backwards incompatibility when people could previously use What do you think?
|
Hi @tomaarsen, This looks awesome, great catch, thanks for the help! |
Thanks a bunch for raising this & for dealing with my slowness, I appreciate it.
|
Problem:
Triplet margin exists in TripletLoss but does not exist in TripletEvaluator.
Motivation:
When evaluating the model using TripletEvaluator during, for example, the training it would be a nice thing to have a piece of information not only if the negative is further away from the anchor than the positive, but also if it is further away from the anchor by some predefined margin. Because the triplet evaluator uses 4 different distance metrics, we would need an option for each one, so 4 different margins for each of them.
Solution:
In the commit, I implemented exactly that, option for setting the margin for each distance function (or any subset of them). It is an optional argument to the class constructor, so it can be called perfectly the same as previously, with the difference that now you have more flexibility in setting how far away you want your negative and positive to be for evaluation.
PS. I can also write some evaluator tests, both for TripletEvaluator with and without the margin.
PPS. I ran a make check, so the code follows coding guidelines.