Add triplet margin for distance functions in TripletEvaluator #2862
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.
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.