UKPLab / sentence-transformers

State-of-the-Art Text Embeddings
https://www.sbert.net
Apache License 2.0
14.78k stars 2.43k forks source link

Issue with triplet loss #1183

Open AlansoG opened 2 years ago

AlansoG commented 2 years ago

Hi , I trained sbert with triplet loss with default distance_metric --> Euclidian distance got descent embeddings and cosine score between relevant/irrelevant sentences. But when i tried with TripletDistanceMetric.COSINE cosine score between any 2 sentances are around 0.9999 even through they are relevent or not. I just changed distance_metric in training script , everything is similar. Could you please help me for understanding why I am getting 0.999 cosine score for all sentance pairs ?

nreimers commented 2 years ago

Cosine similarity can just produce scores between -1 and 1. Hence, using the right margin is quite important.

Also note that MultipleNegativesRankingLoss works usually a lot better than triplet loss and also allows to take tripets.

jaideep11061982 commented 1 year ago

@nreimers how do I interpret this Triplet Loss ,could you please help. Also If i want to view my loss progress during training,how I can do ?

epoch | steps | accuracy_cosinus | accuracy_manhattan | accuracy_euclidean -- | -- | -- | -- | -- 0.72 | 0.72 | 0.70 -- | -- | --