elsayedissa
commited on
Commit
•
bc9f394
1
Parent(s):
4cc90f9
Update README.md
Browse files
README.md
CHANGED
@@ -24,12 +24,30 @@ pip install -U sentence-transformers
|
|
24 |
Then you can use the model like this:
|
25 |
|
26 |
```python
|
27 |
-
from sentence_transformers import SentenceTransformer
|
28 |
-
sentences = ["This is an example sentence", "Each sentence is converted"]
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
```
|
34 |
|
35 |
|
|
|
24 |
Then you can use the model like this:
|
25 |
|
26 |
```python
|
27 |
+
from sentence_transformers import SentenceTransformer, util
|
|
|
28 |
|
29 |
+
query = "What is the large instrument the man is playing?"
|
30 |
+
docs = ["A man is playing a large flute.", "A man is playing a flute."]
|
31 |
+
|
32 |
+
#Load the model
|
33 |
+
model = SentenceTransformer('clu-ling/roberta-finetuned-stsbenchmark')
|
34 |
+
|
35 |
+
#Encode query and documents
|
36 |
+
query_emb = model.encode(query)
|
37 |
+
doc_emb = model.encode(docs)
|
38 |
+
|
39 |
+
#Compute dot score between query and all document embeddings
|
40 |
+
scores = util.dot_score(query_emb, doc_emb)[0].cpu().tolist()
|
41 |
+
|
42 |
+
#Combine docs & scores
|
43 |
+
doc_score_pairs = list(zip(docs, scores))
|
44 |
+
|
45 |
+
#Sort by decreasing score
|
46 |
+
doc_score_pairs = sorted(doc_score_pairs, key=lambda x: x[1], reverse=True)
|
47 |
+
|
48 |
+
#Output passages & scores
|
49 |
+
for doc, score in doc_score_pairs:
|
50 |
+
print(score, doc)
|
51 |
```
|
52 |
|
53 |
|