Feature Extraction
sentence-transformers
PyTorch
Safetensors
Transformers
English
distilbert
fill-mask
learned sparse
opensearch
retrieval
passage-retrieval
document-expansion
bag-of-words
sparse-encoder
sparse
asymmetric
inference-free
splade
text-embeddings-inference
Instructions to use opensearch-project/opensearch-neural-sparse-encoding-doc-v2-distill with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use opensearch-project/opensearch-neural-sparse-encoding-doc-v2-distill with sentence-transformers:
from sentence_transformers import SparseEncoder model = SparseEncoder("opensearch-project/opensearch-neural-sparse-encoding-doc-v2-distill") queries = ["Which planet is known as the Red Planet?"] documents = [ "Venus is often called Earth's twin because of its similar size and proximity.", "Mars, known for its reddish appearance, is often referred to as the Red Planet.", "Jupiter, the largest planet in our solar system, has a prominent red spot.", ] query_embeddings = model.encode_query(queries) document_embeddings = model.encode_document(documents) similarities = model.similarity(query_embeddings, document_embeddings) print(similarities) - Transformers
How to use opensearch-project/opensearch-neural-sparse-encoding-doc-v2-distill with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("feature-extraction", model="opensearch-project/opensearch-neural-sparse-encoding-doc-v2-distill")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForMaskedLM tokenizer = AutoTokenizer.from_pretrained("opensearch-project/opensearch-neural-sparse-encoding-doc-v2-distill") model = AutoModelForMaskedLM.from_pretrained("opensearch-project/opensearch-neural-sparse-encoding-doc-v2-distill", device_map="auto") - Inference
- Notebooks
- Google Colab
- Kaggle
sentence_transformers_support
#5
by arthurbresnu - opened
- README.md +48 -0
- config_sentence_transformers.json +14 -0
- document_1_SpladePooling/config.json +5 -0
- modules.json +8 -0
- query_0_SparseStaticEmbedding/config.json +3 -0
- query_0_SparseStaticEmbedding/model.safetensors +3 -0
- query_0_SparseStaticEmbedding/special_tokens_map.json +37 -0
- query_0_SparseStaticEmbedding/tokenizer.json +0 -0
- query_0_SparseStaticEmbedding/tokenizer_config.json +56 -0
- query_0_SparseStaticEmbedding/vocab.txt +0 -0
- router_config.json +20 -0
- sentence_bert_config.json +4 -0
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-v2-distill
|
|
@@ -37,6 +45,46 @@ The training datasets includes MS MARCO, eli5_question_answer, squad_pairs, Wiki
|
|
| 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 |
|
| 41 |
## Usage (HuggingFace)
|
| 42 |
This model is supposed to run inside OpenSearch cluster. But you can also use it outside the cluster, with HuggingFace models API.
|
|
|
|
| 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-v2-distill
|
|
|
|
| 45 |
|
| 46 |
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.
|
| 47 |
|
| 48 |
+
## Usage (Sentence Transformers)
|
| 49 |
+
|
| 50 |
+
First install the Sentence Transformers library:
|
| 51 |
+
|
| 52 |
+
```bash
|
| 53 |
+
pip install -U sentence-transformers
|
| 54 |
+
```
|
| 55 |
+
|
| 56 |
+
Then you can load this model and run inference.
|
| 57 |
+
|
| 58 |
+
```python
|
| 59 |
+
from sentence_transformers.sparse_encoder import SparseEncoder
|
| 60 |
+
|
| 61 |
+
# Download from the 🤗 Hub
|
| 62 |
+
model = SparseEncoder("opensearch-project/opensearch-neural-sparse-encoding-doc-v2-distill")
|
| 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([[17.5307]])
|
| 73 |
+
|
| 74 |
+
decoded_query = model.decode(query_embed)
|
| 75 |
+
decoded_document = model.decode(document_embed)
|
| 76 |
+
|
| 77 |
+
for i in range(len(decoded_query)):
|
| 78 |
+
query_token, query_score = decoded_query[i]
|
| 79 |
+
doc_score = next((score for token, score in decoded_document if token == query_token), 0)
|
| 80 |
+
if doc_score != 0:
|
| 81 |
+
print(f"Token: {query_token}, Query score: {query_score:.4f}, Document score: {doc_score:.4f}")
|
| 82 |
+
|
| 83 |
+
# Similarity: tensor([[17.5307]], device='cuda:0')
|
| 84 |
+
# Token: ny, Query score: 5.7729, Document score: 1.4109
|
| 85 |
+
# Token: weather, Query score: 4.5684, Document score: 1.4673
|
| 86 |
+
# Token: now, Query score: 3.5895, Document score: 0.7473
|
| 87 |
+
```
|
| 88 |
|
| 89 |
## Usage (HuggingFace)
|
| 90 |
This model is supposed to run inside OpenSearch cluster. But you can also use it outside the cluster, with HuggingFace models API.
|
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 |
+
}
|
document_1_SpladePooling/config.json
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"pooling_strategy": "max",
|
| 3 |
+
"activation_function": "relu",
|
| 4 |
+
"word_embedding_dimension": null
|
| 5 |
+
}
|
modules.json
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
{
|
| 3 |
+
"idx": 0,
|
| 4 |
+
"name": "0",
|
| 5 |
+
"path": "",
|
| 6 |
+
"type": "sentence_transformers.models.Router"
|
| 7 |
+
}
|
| 8 |
+
]
|
query_0_SparseStaticEmbedding/config.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"frozen": true
|
| 3 |
+
}
|
query_0_SparseStaticEmbedding/model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:711ec64837a7962d2ae106996079782b7ee87860089a0b2348bf7cb840f252d3
|
| 3 |
+
size 122168
|
query_0_SparseStaticEmbedding/special_tokens_map.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cls_token": {
|
| 3 |
+
"content": "[CLS]",
|
| 4 |
+
"lstrip": false,
|
| 5 |
+
"normalized": false,
|
| 6 |
+
"rstrip": false,
|
| 7 |
+
"single_word": false
|
| 8 |
+
},
|
| 9 |
+
"mask_token": {
|
| 10 |
+
"content": "[MASK]",
|
| 11 |
+
"lstrip": false,
|
| 12 |
+
"normalized": false,
|
| 13 |
+
"rstrip": false,
|
| 14 |
+
"single_word": false
|
| 15 |
+
},
|
| 16 |
+
"pad_token": {
|
| 17 |
+
"content": "[PAD]",
|
| 18 |
+
"lstrip": false,
|
| 19 |
+
"normalized": false,
|
| 20 |
+
"rstrip": false,
|
| 21 |
+
"single_word": false
|
| 22 |
+
},
|
| 23 |
+
"sep_token": {
|
| 24 |
+
"content": "[SEP]",
|
| 25 |
+
"lstrip": false,
|
| 26 |
+
"normalized": false,
|
| 27 |
+
"rstrip": false,
|
| 28 |
+
"single_word": false
|
| 29 |
+
},
|
| 30 |
+
"unk_token": {
|
| 31 |
+
"content": "[UNK]",
|
| 32 |
+
"lstrip": false,
|
| 33 |
+
"normalized": false,
|
| 34 |
+
"rstrip": false,
|
| 35 |
+
"single_word": false
|
| 36 |
+
}
|
| 37 |
+
}
|
query_0_SparseStaticEmbedding/tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
query_0_SparseStaticEmbedding/tokenizer_config.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"added_tokens_decoder": {
|
| 3 |
+
"0": {
|
| 4 |
+
"content": "[PAD]",
|
| 5 |
+
"lstrip": false,
|
| 6 |
+
"normalized": false,
|
| 7 |
+
"rstrip": false,
|
| 8 |
+
"single_word": false,
|
| 9 |
+
"special": true
|
| 10 |
+
},
|
| 11 |
+
"100": {
|
| 12 |
+
"content": "[UNK]",
|
| 13 |
+
"lstrip": false,
|
| 14 |
+
"normalized": false,
|
| 15 |
+
"rstrip": false,
|
| 16 |
+
"single_word": false,
|
| 17 |
+
"special": true
|
| 18 |
+
},
|
| 19 |
+
"101": {
|
| 20 |
+
"content": "[CLS]",
|
| 21 |
+
"lstrip": false,
|
| 22 |
+
"normalized": false,
|
| 23 |
+
"rstrip": false,
|
| 24 |
+
"single_word": false,
|
| 25 |
+
"special": true
|
| 26 |
+
},
|
| 27 |
+
"102": {
|
| 28 |
+
"content": "[SEP]",
|
| 29 |
+
"lstrip": false,
|
| 30 |
+
"normalized": false,
|
| 31 |
+
"rstrip": false,
|
| 32 |
+
"single_word": false,
|
| 33 |
+
"special": true
|
| 34 |
+
},
|
| 35 |
+
"103": {
|
| 36 |
+
"content": "[MASK]",
|
| 37 |
+
"lstrip": false,
|
| 38 |
+
"normalized": false,
|
| 39 |
+
"rstrip": false,
|
| 40 |
+
"single_word": false,
|
| 41 |
+
"special": true
|
| 42 |
+
}
|
| 43 |
+
},
|
| 44 |
+
"clean_up_tokenization_spaces": true,
|
| 45 |
+
"cls_token": "[CLS]",
|
| 46 |
+
"do_lower_case": true,
|
| 47 |
+
"extra_special_tokens": {},
|
| 48 |
+
"mask_token": "[MASK]",
|
| 49 |
+
"model_max_length": 512,
|
| 50 |
+
"pad_token": "[PAD]",
|
| 51 |
+
"sep_token": "[SEP]",
|
| 52 |
+
"strip_accents": null,
|
| 53 |
+
"tokenize_chinese_chars": true,
|
| 54 |
+
"tokenizer_class": "DistilBertTokenizer",
|
| 55 |
+
"unk_token": "[UNK]"
|
| 56 |
+
}
|
query_0_SparseStaticEmbedding/vocab.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
router_config.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"types": {
|
| 3 |
+
"query_0_SparseStaticEmbedding": "sentence_transformers.sparse_encoder.models.SparseStaticEmbedding.SparseStaticEmbedding",
|
| 4 |
+
"": "sentence_transformers.sparse_encoder.models.MLMTransformer.MLMTransformer",
|
| 5 |
+
"document_1_SpladePooling": "sentence_transformers.sparse_encoder.models.SpladePooling.SpladePooling"
|
| 6 |
+
},
|
| 7 |
+
"structure": {
|
| 8 |
+
"query": [
|
| 9 |
+
"query_0_SparseStaticEmbedding"
|
| 10 |
+
],
|
| 11 |
+
"document": [
|
| 12 |
+
"",
|
| 13 |
+
"document_1_SpladePooling"
|
| 14 |
+
]
|
| 15 |
+
},
|
| 16 |
+
"parameters": {
|
| 17 |
+
"default_route": "document",
|
| 18 |
+
"allow_empty_key": true
|
| 19 |
+
}
|
| 20 |
+
}
|
sentence_bert_config.json
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"max_seq_length": 512,
|
| 3 |
+
"do_lower_case": false
|
| 4 |
+
}
|