UKPLab / sentence-transformers

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

Sentence similarity between 0 and 1 #567

Open sajastu opened 3 years ago

sajastu commented 3 years ago

Hi, thanks for the amazing package!

I saw the examples of semantic similarity in the portal, which gives cosine similarity between [-1, 1]. I'm trying to obtain the similarity between [0, 1] for my special use-case. It might be a bit off-topic question, but I'm wondering if there's functionality that gives this output?

Best, Sajad

nreimers commented 3 years ago

You can simply use:

max(0, cossim(x,y))

Or alternatively:

2*cossim(x,y)-1