Sentence Similarity
sentence-transformers
PyTorch
English
distilbert
sentence similarity
text-embeddings-inference
Instructions to use Sakil/sentence_similarity_semantic_search with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use Sakil/sentence_similarity_semantic_search with sentence-transformers:
from sentence_transformers import SentenceTransformer model = SentenceTransformer("Sakil/sentence_similarity_semantic_search") sentences = [ "That is a happy person", "That is a happy dog", "That is a very happy person", "Today is a sunny day" ] embeddings = model.encode(sentences) similarities = model.similarity(embeddings, embeddings) print(similarities.shape) # [4, 4] - Notebooks
- Google Colab
- Kaggle
Update README.md
Browse files
README.md
CHANGED
|
@@ -58,16 +58,23 @@ cos_sim = util.cos_sim(embeddings, embeddings)
|
|
| 58 |
|
| 59 |
#Add all pairs to a list with their cosine similarity score
|
| 60 |
all_sentence_combinations = []
|
|
|
|
| 61 |
for i in range(len(cos_sim)-1):
|
|
|
|
| 62 |
for j in range(i+1, len(cos_sim)):
|
|
|
|
| 63 |
all_sentence_combinations.append([cos_sim[i][j], i, j])
|
| 64 |
|
| 65 |
#Sort list by the highest cosine similarity score
|
|
|
|
| 66 |
all_sentence_combinations = sorted(all_sentence_combinations, key=lambda x: x[0], reverse=True)
|
| 67 |
|
| 68 |
print("Top-5 most similar pairs:")
|
|
|
|
| 69 |
for score, i, j in all_sentence_combinations[0:5]:
|
|
|
|
| 70 |
print("{} \t {} \t {:.4f}".format(sentences[i], sentences[j], cos_sim[i][j]))
|
| 71 |
|
| 72 |
|
|
|
|
| 73 |
# Github: [Sakil Ansari](https://github.com/Sakil786/hate_speech_detection_pretrained_model)
|
|
|
|
| 58 |
|
| 59 |
#Add all pairs to a list with their cosine similarity score
|
| 60 |
all_sentence_combinations = []
|
| 61 |
+
|
| 62 |
for i in range(len(cos_sim)-1):
|
| 63 |
+
|
| 64 |
for j in range(i+1, len(cos_sim)):
|
| 65 |
+
|
| 66 |
all_sentence_combinations.append([cos_sim[i][j], i, j])
|
| 67 |
|
| 68 |
#Sort list by the highest cosine similarity score
|
| 69 |
+
|
| 70 |
all_sentence_combinations = sorted(all_sentence_combinations, key=lambda x: x[0], reverse=True)
|
| 71 |
|
| 72 |
print("Top-5 most similar pairs:")
|
| 73 |
+
|
| 74 |
for score, i, j in all_sentence_combinations[0:5]:
|
| 75 |
+
|
| 76 |
print("{} \t {} \t {:.4f}".format(sentences[i], sentences[j], cos_sim[i][j]))
|
| 77 |
|
| 78 |
|
| 79 |
+
|
| 80 |
# Github: [Sakil Ansari](https://github.com/Sakil786/hate_speech_detection_pretrained_model)
|