Skip to content

Question about ref_labels, ref_emb and computing training pairs for different sets of embeddings #495

Answered by KevinMusgrave
jsalbert asked this question in Q&A
Discussion options

You must be logged in to vote

I was looking at ref_labels and ref_emb but I am not sure it does what I need by looking at the loss dictionary (without reducer).

What about it looks incorrect?

I would also want to know easy would it be an integration with miners if this is the only way of generating pairs.

These approaches should work:

from pytorch_metric_learning.utils import loss_and_miner_utils as lmu
from pytorch_metric_learning.miners import TripletMarginMiner

ref_labels = torch.clone(labels)

# All pairs (which get converted to triplets if you're using TripletMarginLoss)
pairs = lmu.get_all_pairs_indices(labels, ref_labels=ref_labels)
loss = loss_fn(query_embeddings, indices_tuple=pairs, ref_emb=doc_embeddings

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@KevinMusgrave
Comment options

@jsalbert
Comment options

Answer selected by jsalbert
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants