Commit ·
3b1a864
0
Parent(s):
Duplicate from opensearch-project/opensearch-neural-sparse-encoding-doc-v2-mini
Browse files- .gitattributes +35 -0
- README.md +212 -0
- config.json +25 -0
- config_sentence_transformers.json +14 -0
- document_1_SpladePooling/config.json +5 -0
- generation_config.json +5 -0
- idf.json +0 -0
- model.safetensors +3 -0
- modules.json +8 -0
- pytorch_model.bin +3 -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
- query_token_weights.txt +0 -0
- router_config.json +20 -0
- special_tokens_map.json +7 -0
- tokenizer.json +0 -0
- tokenizer_config.json +13 -0
- vocab.txt +0 -0
.gitattributes
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language: en
|
| 3 |
+
license: apache-2.0
|
| 4 |
+
tags:
|
| 5 |
+
- learned sparse
|
| 6 |
+
- opensearch
|
| 7 |
+
- transformers
|
| 8 |
+
- retrieval
|
| 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-mini
|
| 23 |
+
|
| 24 |
+
## Select the model
|
| 25 |
+
The model should be selected considering search relevance, model inference and retrieval efficiency(FLOPS). We benchmark models' **zero-shot performance** on a subset of BEIR benchmark: TrecCovid,NFCorpus,NQ,HotpotQA,FiQA,ArguAna,Touche,DBPedia,SCIDOCS,FEVER,Climate FEVER,SciFact,Quora.
|
| 26 |
+
|
| 27 |
+
Overall, the v2 series of models have better search relevance, efficiency and inference speed than the v1 series. The specific advantages and disadvantages may vary across different datasets.
|
| 28 |
+
|
| 29 |
+
| Model | Inference-free for Retrieval | Model Parameters | AVG NDCG@10 | AVG FLOPS |
|
| 30 |
+
|-------|------------------------------|------------------|-------------|-----------|
|
| 31 |
+
| [opensearch-neural-sparse-encoding-v1](https://huggingface.co/opensearch-project/opensearch-neural-sparse-encoding-v1) | | 133M | 0.524 | 11.4 |
|
| 32 |
+
| [opensearch-neural-sparse-encoding-v2-distill](https://huggingface.co/opensearch-project/opensearch-neural-sparse-encoding-v2-distill) | | 67M | 0.528 | 8.3 |
|
| 33 |
+
| [opensearch-neural-sparse-encoding-doc-v1](https://huggingface.co/opensearch-project/opensearch-neural-sparse-encoding-doc-v1) | ✔️ | 133M | 0.490 | 2.3 |
|
| 34 |
+
| [opensearch-neural-sparse-encoding-doc-v2-distill](https://huggingface.co/opensearch-project/opensearch-neural-sparse-encoding-doc-v2-distill) | ✔️ | 67M | 0.504 | 1.8 |
|
| 35 |
+
| [opensearch-neural-sparse-encoding-doc-v2-mini](https://huggingface.co/opensearch-project/opensearch-neural-sparse-encoding-doc-v2-mini) | ✔️ | 23M | 0.497 | 1.7 |
|
| 36 |
+
| [opensearch-neural-sparse-encoding-doc-v3-distill](https://huggingface.co/opensearch-project/opensearch-neural-sparse-encoding-doc-v3-distill) | ✔️ | 67M | 0.517 | 1.8 |
|
| 37 |
+
| [opensearch-neural-sparse-encoding-doc-v3-gte](https://huggingface.co/opensearch-project/opensearch-neural-sparse-encoding-doc-v3-gte) | ✔️ | 133M | 0.546 | 1.7 |
|
| 38 |
+
|
| 39 |
+
## Overview
|
| 40 |
+
- **Paper**: [Towards Competitive Search Relevance For Inference-Free Learned Sparse Retrievers](https://arxiv.org/abs/2411.04403)
|
| 41 |
+
- **Fine-tuning sample**: [opensearch-sparse-model-tuning-sample](https://github.com/zhichao-aws/opensearch-sparse-model-tuning-sample)
|
| 42 |
+
|
| 43 |
+
This is a learned sparse retrieval model. It encodes the documents to 30522 dimensional **sparse vectors**. For queries, it just use a tokenizer and a weight look-up table to generate sparse vectors. The non-zero dimension index means the corresponding token in the vocabulary, and the weight means the importance of the token. And the similarity score is the inner product of query/document sparse vectors.
|
| 44 |
+
|
| 45 |
+
The training datasets includes MS MARCO, eli5_question_answer, squad_pairs, WikiAnswers, yahoo_answers_title_question, gooaq_pairs, stackexchange_duplicate_questions_body_body, wikihow, S2ORC_title_abstract, stackexchange_duplicate_questions_title-body_title-body, yahoo_answers_question_answer, searchQA_top5_snippets, stackexchange_duplicate_questions_title_title, yahoo_answers_title_answer.
|
| 46 |
+
|
| 47 |
+
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.
|
| 48 |
+
|
| 49 |
+
## Usage (Sentence Transformers)
|
| 50 |
+
|
| 51 |
+
First install the Sentence Transformers library:
|
| 52 |
+
|
| 53 |
+
```bash
|
| 54 |
+
pip install -U sentence-transformers
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
Then you can load this model and run inference.
|
| 58 |
+
|
| 59 |
+
```python
|
| 60 |
+
|
| 61 |
+
from sentence_transformers.sparse_encoder import SparseEncoder
|
| 62 |
+
|
| 63 |
+
# Download from the 🤗 Hub
|
| 64 |
+
model = SparseEncoder("opensearch-project/opensearch-neural-sparse-encoding-doc-v2-mini")
|
| 65 |
+
|
| 66 |
+
query = "What's the weather in ny now?"
|
| 67 |
+
document = "Currently New York is rainy."
|
| 68 |
+
|
| 69 |
+
query_embed = model.encode_query(query)
|
| 70 |
+
document_embed = model.encode_document(document)
|
| 71 |
+
|
| 72 |
+
sim = model.similarity(query_embed, document_embed)
|
| 73 |
+
print(f"Similarity: {sim}")
|
| 74 |
+
# Similarity: tensor([[13.8444]])
|
| 75 |
+
|
| 76 |
+
decoded_query = model.decode(query_embed)
|
| 77 |
+
decoded_document = model.decode(document_embed)
|
| 78 |
+
|
| 79 |
+
for i in range(len(decoded_query)):
|
| 80 |
+
query_token, query_score = decoded_query[i]
|
| 81 |
+
doc_score = next((score for token, score in decoded_document if token == query_token), 0)
|
| 82 |
+
if doc_score != 0:
|
| 83 |
+
print(f"Token: {query_token}, Query score: {query_score:.4f}, Document score: {doc_score:.4f}")
|
| 84 |
+
|
| 85 |
+
# Token: ny, Query score: 5.7729, Document score: 1.0251
|
| 86 |
+
# Token: weather, Query score: 4.5684, Document score: 1.1145
|
| 87 |
+
# Token: now, Query score: 3.5895, Document score: 0.5356
|
| 88 |
+
# Token: ?, Query score: 3.3313, Document score: 0.2710
|
| 89 |
+
```
|
| 90 |
+
|
| 91 |
+
## Usage (HuggingFace)
|
| 92 |
+
This model is supposed to run inside OpenSearch cluster. But you can also use it outside the cluster, with HuggingFace models API.
|
| 93 |
+
|
| 94 |
+
```python
|
| 95 |
+
import json
|
| 96 |
+
import itertools
|
| 97 |
+
import torch
|
| 98 |
+
|
| 99 |
+
from transformers import AutoModelForMaskedLM, AutoTokenizer
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
# get sparse vector from dense vectors with shape batch_size * seq_len * vocab_size
|
| 103 |
+
def get_sparse_vector(feature, output):
|
| 104 |
+
values, _ = torch.max(output*feature["attention_mask"].unsqueeze(-1), dim=1)
|
| 105 |
+
values = torch.log(1 + torch.relu(values))
|
| 106 |
+
values[:,special_token_ids] = 0
|
| 107 |
+
return values
|
| 108 |
+
|
| 109 |
+
# transform the sparse vector to a dict of (token, weight)
|
| 110 |
+
def transform_sparse_vector_to_dict(sparse_vector):
|
| 111 |
+
sample_indices,token_indices=torch.nonzero(sparse_vector,as_tuple=True)
|
| 112 |
+
non_zero_values = sparse_vector[(sample_indices,token_indices)].tolist()
|
| 113 |
+
number_of_tokens_for_each_sample = torch.bincount(sample_indices).cpu().tolist()
|
| 114 |
+
tokens = [transform_sparse_vector_to_dict.id_to_token[_id] for _id in token_indices.tolist()]
|
| 115 |
+
|
| 116 |
+
output = []
|
| 117 |
+
end_idxs = list(itertools.accumulate([0]+number_of_tokens_for_each_sample))
|
| 118 |
+
for i in range(len(end_idxs)-1):
|
| 119 |
+
token_strings = tokens[end_idxs[i]:end_idxs[i+1]]
|
| 120 |
+
weights = non_zero_values[end_idxs[i]:end_idxs[i+1]]
|
| 121 |
+
output.append(dict(zip(token_strings, weights)))
|
| 122 |
+
return output
|
| 123 |
+
|
| 124 |
+
# download the idf file from model hub. idf is used to give weights for query tokens
|
| 125 |
+
def get_tokenizer_idf(tokenizer):
|
| 126 |
+
from huggingface_hub import hf_hub_download
|
| 127 |
+
local_cached_path = hf_hub_download(repo_id="opensearch-project/opensearch-neural-sparse-encoding-doc-v2-mini", filename="idf.json")
|
| 128 |
+
with open(local_cached_path) as f:
|
| 129 |
+
idf = json.load(f)
|
| 130 |
+
idf_vector = [0]*tokenizer.vocab_size
|
| 131 |
+
for token,weight in idf.items():
|
| 132 |
+
_id = tokenizer._convert_token_to_id_with_added_voc(token)
|
| 133 |
+
idf_vector[_id]=weight
|
| 134 |
+
return torch.tensor(idf_vector)
|
| 135 |
+
|
| 136 |
+
# load the model
|
| 137 |
+
model = AutoModelForMaskedLM.from_pretrained("opensearch-project/opensearch-neural-sparse-encoding-doc-v2-mini")
|
| 138 |
+
tokenizer = AutoTokenizer.from_pretrained("opensearch-project/opensearch-neural-sparse-encoding-doc-v2-mini")
|
| 139 |
+
idf = get_tokenizer_idf(tokenizer)
|
| 140 |
+
|
| 141 |
+
# set the special tokens and id_to_token transform for post-process
|
| 142 |
+
special_token_ids = [tokenizer.vocab[token] for token in tokenizer.special_tokens_map.values()]
|
| 143 |
+
get_sparse_vector.special_token_ids = special_token_ids
|
| 144 |
+
id_to_token = ["" for i in range(tokenizer.vocab_size)]
|
| 145 |
+
for token, _id in tokenizer.vocab.items():
|
| 146 |
+
id_to_token[_id] = token
|
| 147 |
+
transform_sparse_vector_to_dict.id_to_token = id_to_token
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
|
| 151 |
+
query = "What's the weather in ny now?"
|
| 152 |
+
document = "Currently New York is rainy."
|
| 153 |
+
|
| 154 |
+
# encode the query
|
| 155 |
+
feature_query = tokenizer([query], padding=True, truncation=True, return_tensors='pt', return_token_type_ids=False)
|
| 156 |
+
input_ids = feature_query["input_ids"]
|
| 157 |
+
batch_size = input_ids.shape[0]
|
| 158 |
+
query_vector = torch.zeros(batch_size, tokenizer.vocab_size)
|
| 159 |
+
query_vector[torch.arange(batch_size).unsqueeze(-1), input_ids] = 1
|
| 160 |
+
query_sparse_vector = query_vector*idf
|
| 161 |
+
|
| 162 |
+
# encode the document
|
| 163 |
+
feature_document = tokenizer([document], padding=True, truncation=True, return_tensors='pt', return_token_type_ids=False)
|
| 164 |
+
output = model(**feature_document)[0]
|
| 165 |
+
document_sparse_vector = get_sparse_vector(feature_document, output)
|
| 166 |
+
|
| 167 |
+
|
| 168 |
+
# get similarity score
|
| 169 |
+
sim_score = torch.matmul(query_sparse_vector[0],document_sparse_vector[0])
|
| 170 |
+
print(sim_score) # tensor(13.8344, grad_fn=<DotBackward0>)
|
| 171 |
+
|
| 172 |
+
|
| 173 |
+
query_token_weight = transform_sparse_vector_to_dict(query_sparse_vector)[0]
|
| 174 |
+
document_query_token_weight = transform_sparse_vector_to_dict(document_sparse_vector)[0]
|
| 175 |
+
for token in sorted(query_token_weight, key=lambda x:query_token_weight[x], reverse=True):
|
| 176 |
+
if token in document_query_token_weight:
|
| 177 |
+
print("score in query: %.4f, score in document: %.4f, token: %s"%(query_token_weight[token],document_query_token_weight[token],token))
|
| 178 |
+
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
# result:
|
| 182 |
+
# score in query: 5.7729, score in document: 1.0251, token: ny
|
| 183 |
+
# score in query: 4.5684, score in document: 1.1145, token: weather
|
| 184 |
+
# score in query: 3.5895, score in document: 0.5356, token: now
|
| 185 |
+
# score in query: 3.3313, score in document: 0.2710, token: ?
|
| 186 |
+
```
|
| 187 |
+
|
| 188 |
+
The above code sample shows an example of neural sparse search. Although there is no overlap token in original query and document, but this model performs a good match.
|
| 189 |
+
|
| 190 |
+
## Detailed Search Relevance
|
| 191 |
+
|
| 192 |
+
<div style="overflow-x: auto;">
|
| 193 |
+
|
| 194 |
+
| Model | Average | Trec Covid | NFCorpus | NQ | HotpotQA | FiQA | ArguAna | Touche | DBPedia | SCIDOCS | FEVER | Climate FEVER | SciFact | Quora |
|
| 195 |
+
|-------|---------|------------|----------|----|----------|------|---------|--------|---------|---------|-------|---------------|---------|-------|
|
| 196 |
+
| [opensearch-neural-sparse-encoding-v1](https://huggingface.co/opensearch-project/opensearch-neural-sparse-encoding-v1) | 0.524 | 0.771 | 0.360 | 0.553 | 0.697 | 0.376 | 0.508 | 0.278 | 0.447 | 0.164 | 0.821 | 0.263 | 0.723 | 0.856 |
|
| 197 |
+
| [opensearch-neural-sparse-encoding-v2-distill](https://huggingface.co/opensearch-project/opensearch-neural-sparse-encoding-v2-distill) | 0.528 | 0.775 | 0.347 | 0.561 | 0.685 | 0.374 | 0.551 | 0.278 | 0.435 | 0.173 | 0.849 | 0.249 | 0.722 | 0.863 |
|
| 198 |
+
| [opensearch-neural-sparse-encoding-doc-v1](https://huggingface.co/opensearch-project/opensearch-neural-sparse-encoding-doc-v1) | 0.490 | 0.707 | 0.352 | 0.521 | 0.677 | 0.344 | 0.461 | 0.294 | 0.412 | 0.154 | 0.743 | 0.202 | 0.716 | 0.788 |
|
| 199 |
+
| [opensearch-neural-sparse-encoding-doc-v2-distill](https://huggingface.co/opensearch-project/opensearch-neural-sparse-encoding-doc-v2-distill) | 0.504 | 0.690 | 0.343 | 0.528 | 0.675 | 0.357 | 0.496 | 0.287 | 0.418 | 0.166 | 0.818 | 0.224 | 0.715 | 0.841 |
|
| 200 |
+
| [opensearch-neural-sparse-encoding-doc-v2-mini](https://huggingface.co/opensearch-project/opensearch-neural-sparse-encoding-doc-v2-mini) | 0.497 | 0.709 | 0.336 | 0.510 | 0.666 | 0.338 | 0.480 | 0.285 | 0.407 | 0.164 | 0.812 | 0.216 | 0.699 | 0.837 |
|
| 201 |
+
| [opensearch-neural-sparse-encoding-doc-v3-distill](https://huggingface.co/opensearch-project/opensearch-neural-sparse-encoding-doc-v3-distill) | 0.517 | 0.724 | 0.345 | 0.544 | 0.694 | 0.356 | 0.520 | 0.294 | 0.424 | 0.163 | 0.845 | 0.239 | 0.708 | 0.863 |
|
| 202 |
+
| [opensearch-neural-sparse-encoding-doc-v3-gte](https://huggingface.co/opensearch-project/opensearch-neural-sparse-encoding-doc-v3-gte) | 0.546 | 0.734 | 0.360 | 0.582 | 0.716 | 0.407 | 0.520 | 0.389 | 0.455 | 0.167 | 0.860 | 0.312 | 0.725 | 0.873 |
|
| 203 |
+
|
| 204 |
+
</div>
|
| 205 |
+
|
| 206 |
+
## License
|
| 207 |
+
|
| 208 |
+
This project is licensed under the [Apache v2.0 License](https://github.com/opensearch-project/neural-search/blob/main/LICENSE).
|
| 209 |
+
|
| 210 |
+
## Copyright
|
| 211 |
+
|
| 212 |
+
Copyright OpenSearch Contributors. See [NOTICE](https://github.com/opensearch-project/neural-search/blob/main/NOTICE) for details.
|
config.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_name_or_path": "opensearch-project/opensearch-neural-sparse-encoding-v2-mini",
|
| 3 |
+
"architectures": [
|
| 4 |
+
"BertForMaskedLM"
|
| 5 |
+
],
|
| 6 |
+
"attention_probs_dropout_prob": 0.1,
|
| 7 |
+
"classifier_dropout": null,
|
| 8 |
+
"hidden_act": "gelu",
|
| 9 |
+
"hidden_dropout_prob": 0.1,
|
| 10 |
+
"hidden_size": 384,
|
| 11 |
+
"initializer_range": 0.02,
|
| 12 |
+
"intermediate_size": 1536,
|
| 13 |
+
"layer_norm_eps": 1e-12,
|
| 14 |
+
"max_position_embeddings": 512,
|
| 15 |
+
"model_type": "bert",
|
| 16 |
+
"num_attention_heads": 12,
|
| 17 |
+
"num_hidden_layers": 6,
|
| 18 |
+
"pad_token_id": 0,
|
| 19 |
+
"position_embedding_type": "absolute",
|
| 20 |
+
"torch_dtype": "float32",
|
| 21 |
+
"transformers_version": "4.32.0",
|
| 22 |
+
"type_vocab_size": 2,
|
| 23 |
+
"use_cache": true,
|
| 24 |
+
"vocab_size": 30522
|
| 25 |
+
}
|
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 |
+
}
|
generation_config.json
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_from_model_config": true,
|
| 3 |
+
"pad_token_id": 0,
|
| 4 |
+
"transformers_version": "4.32.0"
|
| 5 |
+
}
|
idf.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d90a4233e0ca352cf73d6c3adf3c41fac7fee9a49ccd9ee3e806a86c1e05368a
|
| 3 |
+
size 90990328
|
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 |
+
]
|
pytorch_model.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9907af551ccbcb8080e0c13b9210b5026f1dd7fc018bcb0dceb3e229f2dde7d7
|
| 3 |
+
size 91011309
|
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": "BertTokenizer",
|
| 55 |
+
"unk_token": "[UNK]"
|
| 56 |
+
}
|
query_0_SparseStaticEmbedding/vocab.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
query_token_weights.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 |
+
}
|
special_tokens_map.json
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cls_token": "[CLS]",
|
| 3 |
+
"mask_token": "[MASK]",
|
| 4 |
+
"pad_token": "[PAD]",
|
| 5 |
+
"sep_token": "[SEP]",
|
| 6 |
+
"unk_token": "[UNK]"
|
| 7 |
+
}
|
tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"clean_up_tokenization_spaces": true,
|
| 3 |
+
"cls_token": "[CLS]",
|
| 4 |
+
"do_lower_case": true,
|
| 5 |
+
"mask_token": "[MASK]",
|
| 6 |
+
"model_max_length": 512,
|
| 7 |
+
"pad_token": "[PAD]",
|
| 8 |
+
"sep_token": "[SEP]",
|
| 9 |
+
"strip_accents": null,
|
| 10 |
+
"tokenize_chinese_chars": true,
|
| 11 |
+
"tokenizer_class": "BertTokenizer",
|
| 12 |
+
"unk_token": "[UNK]"
|
| 13 |
+
}
|
vocab.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|