Upload README.md
Browse files
README.md
CHANGED
@@ -117,30 +117,26 @@ embeddings = model.encode(sentences, convert_to_tensor=True)
|
|
117 |
def find_closest_sentence(query_embedding, sentence_embeddings, sentences):
|
118 |
# Compute cosine similarities
|
119 |
cosine_scores = util.pytorch_cos_sim(query_embedding, sentence_embeddings)[0]
|
120 |
-
|
121 |
# Find the position of the highest score
|
122 |
best_match_index = torch.argmax(cosine_scores).item()
|
123 |
-
|
124 |
return sentences[best_match_index], cosine_scores[best_match_index].item()
|
125 |
|
126 |
query = "Kini olu ilu England"
|
127 |
query_embedding = model.encode(query, convert_to_tensor=True)
|
128 |
-
|
129 |
closest_sentence, similarity_score = find_closest_sentence(query_embedding, embeddings, sentences)
|
130 |
|
131 |
-
print(f"
|
132 |
-
print(f"
|
133 |
-
print(f"
|
134 |
|
135 |
# You can also try with a new sentence not in the original list
|
136 |
new_query = "Kini oruko oba to wa ni ilu Oyo?"
|
137 |
new_query_embedding = model.encode(new_query, convert_to_tensor=True)
|
138 |
-
|
139 |
closest_sentence, similarity_score = find_closest_sentence(new_query_embedding, embeddings, sentences)
|
140 |
|
141 |
-
print(f"\
|
142 |
-
print(f"
|
143 |
-
print(f"
|
144 |
```
|
145 |
|
146 |
### License
|
|
|
117 |
def find_closest_sentence(query_embedding, sentence_embeddings, sentences):
|
118 |
# Compute cosine similarities
|
119 |
cosine_scores = util.pytorch_cos_sim(query_embedding, sentence_embeddings)[0]
|
|
|
120 |
# Find the position of the highest score
|
121 |
best_match_index = torch.argmax(cosine_scores).item()
|
|
|
122 |
return sentences[best_match_index], cosine_scores[best_match_index].item()
|
123 |
|
124 |
query = "Kini olu ilu England"
|
125 |
query_embedding = model.encode(query, convert_to_tensor=True)
|
|
|
126 |
closest_sentence, similarity_score = find_closest_sentence(query_embedding, embeddings, sentences)
|
127 |
|
128 |
+
print(f"Ibeere: {query}")
|
129 |
+
print(f"Gbolohun ti o jọ mọ julọ: {closest_sentence}")
|
130 |
+
print(f"Iwọn ijọra: {similarity_score:.4f}")
|
131 |
|
132 |
# You can also try with a new sentence not in the original list
|
133 |
new_query = "Kini oruko oba to wa ni ilu Oyo?"
|
134 |
new_query_embedding = model.encode(new_query, convert_to_tensor=True)
|
|
|
135 |
closest_sentence, similarity_score = find_closest_sentence(new_query_embedding, embeddings, sentences)
|
136 |
|
137 |
+
print(f"\nIbeere Tuntun: {new_query}")
|
138 |
+
print(f"Gbolohun ti o jọ mọ julọ: {closest_sentence}")
|
139 |
+
print(f"Iwọn ijọra: {similarity_score:.4f}")
|
140 |
```
|
141 |
|
142 |
### License
|