Contrastive Loss API

Bases: Module

Hyperbolic InfoNCE loss operating directly on Lorentz-model embeddings.

The encoder now returns hyperbolic embeddings directly, so this loss function works with them without additional projection.

forward(anchor_emb, positive_emb, negative_embs, batch_size, k_negatives, false_negative_mask=None, adaptive_margins=None)

Compute Hyperbolic InfoNCE loss.

Parameters:

Name Type Description Default
anchor_emb Tensor

Anchor hyperbolic embeddings (batch_size, embedding_dim+1)

required
positive_emb Tensor

Positive hyperbolic embeddings (batch_size, embedding_dim+1)

required
negative_embs Tensor

Negative hyperbolic embeddings (batch_size * k_negatives, embedding_dim+1)

required
batch_size int

Batch size

required
k_negatives int

Number of negatives per anchor

required
false_negative_mask Optional[Tensor]

Optional mask for false negatives (batch_size, k_negatives)

None
adaptive_margins Optional[Tensor]

Optional per-anchor adaptive margins (batch_size,)

None

Returns:

Type Description
Tensor

Loss scalar