The miner you’ve written is designed with the usual metric learning assumption that “positives” are pairs of samples with the same class label and “negatives” are those with different labels. In your code, the function
a1, p, a2, n = lmu.get_all_pairs_indices(labels, ref_labels)
relies on comparing labels (and/or ref_labels) to decide which pairs are positive and which are negative. Therefore, if you have positives coming from different classes (or if your dataset has lots of false negatives where samples that should be similar are marked as different), the miner will not “know” about that extra structure. It will treat mismatched-label pairs as negatives even if (in your application) they should be considered positive.
Similarly, the way negatives are mined is based solely on fixed thresholds (a lower and “upper” negative margin) applied to the pairwise distances. When you have many false negatives, you might end up mining negatives that are actually very similar (or even semantically “positive” pairs) if they fall within that window. There’s no mechanism here to differentiate hard negatives that are truly negatives from false negatives that should ideally be treated as positive pairs.
So, to answer your question directly:
-
Positives from different classes: The miner assumes that positives have matching labels. If you expect positive pairs to sometimes come from different classes, you’d need to change the way you define positive pairs (perhaps by adding an extra notion of similarity beyond simple label equality).
-
A large amount of false negatives: The fixed margins may not be sufficient. If many negatives are actually “false negatives” (i.e. semantically similar despite label differences), the miner will still pick them if they lie within the margin window. This might hurt training stability and performance.
In short: as currently implemented, the miner is not ideally suited for cases where positive pairs come from multiple classes or where there is a significant number of false negatives. You would likely need to adjust the logic (or the thresholds) and possibly incorporate additional similarity criteria to handle these scenarios properly.