sentence_transformers_support
#4
by
arthurbresnu
HF Staff
- opened
- 1_SpladePooling/config.json +5 -0
- README.md +64 -0
- config_sentence_transformers.json +14 -0
- modules.json +14 -0
- sentence_bert_config.json +4 -0
1_SpladePooling/config.json
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"pooling_strategy": "max",
|
3 |
+
"activation_function": "relu",
|
4 |
+
"word_embedding_dimension": null
|
5 |
+
}
|
README.md
CHANGED
@@ -10,6 +10,12 @@ tags:
|
|
10 |
- query-expansion
|
11 |
- document-expansion
|
12 |
- bag-of-words
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
---
|
14 |
|
15 |
# opensearch-neural-sparse-encoding-v1
|
@@ -37,6 +43,64 @@ This model is trained on MS MARCO dataset.
|
|
37 |
|
38 |
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.
|
39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
## Usage (HuggingFace)
|
41 |
This model is supposed to run inside OpenSearch cluster. But you can also use it outside the cluster, with HuggingFace models API.
|
42 |
|
|
|
10 |
- query-expansion
|
11 |
- document-expansion
|
12 |
- bag-of-words
|
13 |
+
- sentence-transformers
|
14 |
+
- sparse-encoder
|
15 |
+
- sparse
|
16 |
+
- splade
|
17 |
+
pipeline_tag: feature-extraction
|
18 |
+
library_name: sentence-transformers
|
19 |
---
|
20 |
|
21 |
# opensearch-neural-sparse-encoding-v1
|
|
|
43 |
|
44 |
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.
|
45 |
|
46 |
+
## Usage (Sentence Transformers)
|
47 |
+
|
48 |
+
First install the Sentence Transformers library:
|
49 |
+
|
50 |
+
```bash
|
51 |
+
pip install -U sentence-transformers
|
52 |
+
```
|
53 |
+
|
54 |
+
Then you can load this model and run inference.
|
55 |
+
|
56 |
+
```python
|
57 |
+
from sentence_transformers.sparse_encoder import SparseEncoder
|
58 |
+
|
59 |
+
# Download from the 🤗 Hub
|
60 |
+
model = SparseEncoder("opensearch-project/opensearch-neural-sparse-encoding-v1")
|
61 |
+
|
62 |
+
query = "What's the weather in ny now?"
|
63 |
+
document = "Currently New York is rainy."
|
64 |
+
|
65 |
+
query_embed = model.encode_query(query)
|
66 |
+
document_embed = model.encode_document(document)
|
67 |
+
|
68 |
+
sim = model.similarity(query_embed, document_embed)
|
69 |
+
print(f"Similarity: {sim}")
|
70 |
+
# Similarity: tensor([[22.3299]])
|
71 |
+
|
72 |
+
decoded_query = model.decode(query_embed)
|
73 |
+
decoded_document = model.decode(document_embed)
|
74 |
+
|
75 |
+
for i in range(len(decoded_query)):
|
76 |
+
query_token, query_score = decoded_query[i]
|
77 |
+
doc_score = next((score for token, score in decoded_document if token == query_token), 0)
|
78 |
+
if doc_score != 0:
|
79 |
+
print(f"Token: {query_token}, Query score: {query_score:.4f}, Document score: {doc_score:.4f}")
|
80 |
+
|
81 |
+
# Token: ny, Query score: 2.9262, Document score: 2.1335
|
82 |
+
# Token: weather, Query score: 2.5206, Document score: 1.5277
|
83 |
+
# Token: york, Query score: 2.0373, Document score: 2.3489
|
84 |
+
# Token: cool, Query score: 1.5786, Document score: 0.8752
|
85 |
+
# Token: current, Query score: 1.4636, Document score: 1.5132
|
86 |
+
# Token: season, Query score: 0.7761, Document score: 0.8860
|
87 |
+
# Token: 2020, Query score: 0.7560, Document score: 0.6726
|
88 |
+
# Token: summer, Query score: 0.7222, Document score: 0.6292
|
89 |
+
# Token: nina, Query score: 0.6888, Document score: 0.6419
|
90 |
+
# Token: storm, Query score: 0.6451, Document score: 0.8200
|
91 |
+
# Token: brooklyn, Query score: 0.4698, Document score: 0.7635
|
92 |
+
# Token: julian, Query score: 0.4562, Document score: 0.1208
|
93 |
+
# Token: wow, Query score: 0.3484, Document score: 0.3903
|
94 |
+
# Token: usa, Query score: 0.3439, Document score: 0.4160
|
95 |
+
# Token: manhattan, Query score: 0.2751, Document score: 0.8260
|
96 |
+
# Token: fog, Query score: 0.2013, Document score: 0.7735
|
97 |
+
# Token: mood, Query score: 0.1989, Document score: 0.2961
|
98 |
+
# Token: climate, Query score: 0.1653, Document score: 0.3437
|
99 |
+
# Token: nature, Query score: 0.1191, Document score: 0.1533
|
100 |
+
# Token: temperature, Query score: 0.0665, Document score: 0.0599
|
101 |
+
# Token: windy, Query score: 0.0552, Document score: 0.3396
|
102 |
+
```
|
103 |
+
|
104 |
## Usage (HuggingFace)
|
105 |
This model is supposed to run inside OpenSearch cluster. But you can also use it outside the cluster, with HuggingFace models API.
|
106 |
|
config_sentence_transformers.json
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"model_type": "SparseEncoder",
|
3 |
+
"__version__": {
|
4 |
+
"sentence_transformers": "5.0.0",
|
5 |
+
"transformers": "4.50.3",
|
6 |
+
"pytorch": "2.6.0+cu124"
|
7 |
+
},
|
8 |
+
"prompts": {
|
9 |
+
"query": "",
|
10 |
+
"document": ""
|
11 |
+
},
|
12 |
+
"default_prompt_name": null,
|
13 |
+
"similarity_fn_name": "dot"
|
14 |
+
}
|
modules.json
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[
|
2 |
+
{
|
3 |
+
"idx": 0,
|
4 |
+
"name": "0",
|
5 |
+
"path": "",
|
6 |
+
"type": "sentence_transformers.sparse_encoder.models.MLMTransformer"
|
7 |
+
},
|
8 |
+
{
|
9 |
+
"idx": 1,
|
10 |
+
"name": "1",
|
11 |
+
"path": "1_SpladePooling",
|
12 |
+
"type": "sentence_transformers.sparse_encoder.models.SpladePooling"
|
13 |
+
}
|
14 |
+
]
|
sentence_bert_config.json
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"max_seq_length": 512,
|
3 |
+
"do_lower_case": false
|
4 |
+
}
|