arthurbr11
commited on
Commit
·
cf44a30
1
Parent(s):
37f8b09
Update README.md
Browse files
README.md
CHANGED
@@ -9,6 +9,14 @@ tags:
|
|
9 |
- passage-retrieval
|
10 |
- document-expansion
|
11 |
- bag-of-words
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
---
|
13 |
|
14 |
# opensearch-neural-sparse-encoding-doc-v1
|
@@ -36,6 +44,52 @@ This model is trained on MS MARCO dataset.
|
|
36 |
|
37 |
OpenSearch neural sparse feature supports learned sparse retrieval with lucene inverted index. Link: https://opensearch.org/docs/latest/query-dsl/specialized/neural-sparse/. The indexing and search can be performed with OpenSearch high-level API.
|
38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
## Usage (HuggingFace)
|
40 |
This model is supposed to run inside OpenSearch cluster. But you can also use it outside the cluster, with HuggingFace models API.
|
41 |
|
|
|
9 |
- passage-retrieval
|
10 |
- document-expansion
|
11 |
- bag-of-words
|
12 |
+
- sentence-transformers
|
13 |
+
- sparse-encoder
|
14 |
+
- sparse
|
15 |
+
- asymmetric
|
16 |
+
- inference-free
|
17 |
+
- splade
|
18 |
+
pipeline_tag: feature-extraction
|
19 |
+
library_name: sentence-transformers
|
20 |
---
|
21 |
|
22 |
# opensearch-neural-sparse-encoding-doc-v1
|
|
|
44 |
|
45 |
OpenSearch neural sparse feature supports learned sparse retrieval with lucene inverted index. Link: https://opensearch.org/docs/latest/query-dsl/specialized/neural-sparse/. The indexing and search can be performed with OpenSearch high-level API.
|
46 |
|
47 |
+
## Usage (Sentence Transformers)
|
48 |
+
|
49 |
+
First install the Sentence Transformers library:
|
50 |
+
|
51 |
+
```bash
|
52 |
+
pip install -U sentence-transformers
|
53 |
+
```
|
54 |
+
|
55 |
+
Then you can load this model and run inference.
|
56 |
+
|
57 |
+
```python
|
58 |
+
|
59 |
+
from sentence_transformers.sparse_encoder import SparseEncoder
|
60 |
+
|
61 |
+
# Download from the 🤗 Hub
|
62 |
+
model = SparseEncoder("opensearch-project/opensearch-neural-sparse-encoding-doc-v1")
|
63 |
+
|
64 |
+
query = "What's the weather in ny now?"
|
65 |
+
document = "Currently New York is rainy."
|
66 |
+
|
67 |
+
query_embed = model.encode_query(query)
|
68 |
+
document_embed = model.encode_document(document)
|
69 |
+
|
70 |
+
sim = model.similarity(query_embed, document_embed)
|
71 |
+
print(f"Similarity: {sim}")
|
72 |
+
# Similarity: tensor([[12.8465]])
|
73 |
+
|
74 |
+
# Visualize top tokens for each text
|
75 |
+
top_k = 3
|
76 |
+
print(f"\nTop tokens {top_k} for each text:")
|
77 |
+
|
78 |
+
decoded_query = model.decode(query_embed, top_k=top_k)
|
79 |
+
decoded_document = model.decode(document_embed)
|
80 |
+
|
81 |
+
for i in range(top_k):
|
82 |
+
query_token, query_score = decoded_query[i]
|
83 |
+
doc_score = next((score for token, score in decoded_document if token == query_token), 0)
|
84 |
+
if doc_score != 0:
|
85 |
+
print(f"Token: {query_token}, Query score: {query_score:.4f}, Document score: {doc_score:.4f}")
|
86 |
+
|
87 |
+
# Top tokens 3 for each text:
|
88 |
+
# Token: ny, Query score: 5.7729, Document score: 1.0552
|
89 |
+
# Token: weather, Query score: 4.5684, Document score: 1.1697
|
90 |
+
# Token: now, Query score: 3.5895, Document score: 0.3932
|
91 |
+
```
|
92 |
+
|
93 |
## Usage (HuggingFace)
|
94 |
This model is supposed to run inside OpenSearch cluster. But you can also use it outside the cluster, with HuggingFace models API.
|
95 |
|