Skip to content

Instantly share code, notes, and snippets.

@rjurney
Created June 13, 2025 02:05
Show Gist options
  • Save rjurney/d0bae5d673ac64aeea943f51eb8af279 to your computer and use it in GitHub Desktop.
Save rjurney/d0bae5d673ac64aeea943f51eb8af279 to your computer and use it in GitHub Desktop.
We all contrastive experience loss at some point in our lives, but which one for your problem and with what hyperparameters?
# This will effectively train the embedding model. MultipleNegativesRankingLoss did not work.
loss: losses.ContrastiveLoss = losses.ContrastiveLoss(model=sbert_model)
# These are default arguments for OnlineContrastiveLoss
loss: losses.OnlineContrastiveLoss = losses.OnlineContrastiveLoss(
model=sbert_model,
margin=0.5, # Margin for contrastive loss
distance_metric=SiameseDistanceMetric.COSINE_DISTANCE,
)
loss: ContextAdaptiveContrastiveLoss = ContextAdaptiveContrastiveLoss(
model=sbert_model,
margin=0.5, # Margin for contrastive loss
gate_scale=5.0, # Scale for the gate function
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment