tformal commited on
Commit
6c9c7be
·
verified ·
1 Parent(s): 86552fa

sentence_transformers_support (#2)

Browse files

- Add support for Sentence Transformer (fded1f0c72d5d4ebc7346f2ede9135c6f7c0cfab)

.gitattributes CHANGED
@@ -25,3 +25,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
25
  *.zip filter=lfs diff=lfs merge=lfs -text
26
  *.zstandard filter=lfs diff=lfs merge=lfs -text
27
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
25
  *.zip filter=lfs diff=lfs merge=lfs -text
26
  *.zstandard filter=lfs diff=lfs merge=lfs -text
27
  *tfevents* filter=lfs diff=lfs merge=lfs -text
28
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
README.md CHANGED
@@ -9,6 +9,12 @@ tags:
9
  - passage-retrieval
10
  - knowledge-distillation
11
  - document encoder
 
 
 
 
 
 
12
  datasets:
13
  - ms_marco
14
  ---
@@ -20,6 +26,66 @@ Efficient SPLADE model for passage retrieval. This architecture uses two distinc
20
  | --- | --- | --- | --- | --- |
21
  | `naver/efficient-splade-V-large` | 38.8 | 98.0 | 29.0 | 45.3
22
  | `naver/efficient-splade-VI-BT-large` | 38.0 | 97.8 | 31.1 | 0.7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  ## Citation
24
  If you use our checkpoint, please cite our work:
25
  ```
 
9
  - passage-retrieval
10
  - knowledge-distillation
11
  - document encoder
12
+ - sentence-transformers
13
+ - sparse-encoder
14
+ - sparse
15
+ - asymmetric
16
+ pipeline_tag: feature-extraction
17
+ library_name: sentence-transformers
18
  datasets:
19
  - ms_marco
20
  ---
 
26
  | --- | --- | --- | --- | --- |
27
  | `naver/efficient-splade-V-large` | 38.8 | 98.0 | 29.0 | 45.3
28
  | `naver/efficient-splade-VI-BT-large` | 38.0 | 97.8 | 31.1 | 0.7
29
+
30
+
31
+ ## Model Details
32
+
33
+ This is a [Asymmetric SPLADE Sparse Encoder](https://www.sbert.net/docs/sparse_encoder/usage/usage.html) model. It maps sentences & paragraphs to a 30522-dimensional sparse vector space and can be used for semantic search and sparse retrieval.
34
+
35
+ ### Model Description
36
+ - **Model Type:** SPLADE Sparse Encoder
37
+ - **Maximum Sequence Length:** 512 tokens (256 for evaluation reproduction)
38
+ - **Output Dimensionality:** 30522 dimensions
39
+ - **Similarity Function:** Dot Product
40
+
41
+ ### Full Model Architecture
42
+
43
+ ```
44
+ SparseEncoder(
45
+ (0): Router(
46
+ (query_0_MLMTransformer): MLMTransformer({'max_seq_length': 512, 'do_lower_case': False}) with MLMTransformer model: BertForMaskedLM
47
+ (query_1_SpladePooling): SpladePooling({'pooling_strategy': 'max', 'activation_function': 'relu', 'word_embedding_dimension': 30522})
48
+ (document_0_MLMTransformer): MLMTransformer({'max_seq_length': 512, 'do_lower_case': False}) with MLMTransformer model: DistilBertForMaskedLM
49
+ (document_1_SpladePooling): SpladePooling({'pooling_strategy': 'max', 'activation_function': 'relu', 'word_embedding_dimension': 30522})
50
+ )
51
+ )
52
+ ```
53
+
54
+ ## Usage
55
+
56
+ ### Direct Usage (Sentence Transformers)
57
+
58
+ First install the Sentence Transformers library:
59
+
60
+ ```bash
61
+ pip install -U sentence-transformers
62
+ ```
63
+
64
+ Then you can load this model and run inference. Note that with Sentence Transformers you load the entire model, i.e. the doc and query part.
65
+ ```python
66
+ from sentence_transformers import SparseEncoder
67
+
68
+ # Download from the 🤗 Hub
69
+ model = SparseEncoder("naver/efficient-splade-VI-BT-large-doc")
70
+ # Run inference
71
+ queries = ["what causes aging fast"]
72
+ documents = [
73
+ "UV-A light, specifically, is what mainly causes tanning, skin aging, and cataracts, UV-B causes sunburn, skin aging and skin cancer, and UV-C is the strongest, and therefore most effective at killing microorganisms. Again â\x80\x93 single words and multiple bullets.",
74
+ "Answers from Ronald Petersen, M.D. Yes, Alzheimer's disease usually worsens slowly. But its speed of progression varies, depending on a person's genetic makeup, environmental factors, age at diagnosis and other medical conditions. Still, anyone diagnosed with Alzheimer's whose symptoms seem to be progressing quickly â\x80\x94 or who experiences a sudden decline â\x80\x94 should see his or her doctor.",
75
+ "Bell's palsy and Extreme tiredness and Extreme fatigue (2 causes) Bell's palsy and Extreme tiredness and Hepatitis (2 causes) Bell's palsy and Extreme tiredness and Liver pain (2 causes) Bell's palsy and Extreme tiredness and Lymph node swelling in children (2 causes)",
76
+ ]
77
+ query_embeddings = model.encode_query(queries)
78
+ document_embeddings = model.encode_document(documents)
79
+ print(query_embeddings.shape, document_embeddings.shape)
80
+ # [1, 30522] [3, 30522]
81
+
82
+ # Get the similarity scores for the embeddings
83
+ similarities = model.similarity(query_embeddings, document_embeddings)
84
+ print(similarities)
85
+ # tensor([[8.4781, 8.9038, 2.4770]])
86
+
87
+ ```
88
+
89
  ## Citation
90
  If you use our checkpoint, please cite our work:
91
  ```
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_MLMTransformer/config.json ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "BertForMaskedLM"
4
+ ],
5
+ "attention_probs_dropout_prob": 0.1,
6
+ "classifier_dropout": null,
7
+ "hidden_act": "gelu",
8
+ "hidden_dropout_prob": 0.1,
9
+ "hidden_size": 128,
10
+ "initializer_range": 0.02,
11
+ "intermediate_size": 512,
12
+ "layer_norm_eps": 1e-12,
13
+ "max_position_embeddings": 512,
14
+ "model_type": "bert",
15
+ "num_attention_heads": 2,
16
+ "num_hidden_layers": 2,
17
+ "pad_token_id": 0,
18
+ "position_embedding_type": "absolute",
19
+ "torch_dtype": "float32",
20
+ "transformers_version": "4.50.3",
21
+ "type_vocab_size": 2,
22
+ "use_cache": true,
23
+ "vocab_size": 30522
24
+ }
query_0_MLMTransformer/model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8db9bd0090b6b48deed3e7b952d268974a3a157441f19cbde4cd90b6a8afb334
3
+ size 17671560
query_0_MLMTransformer/sentence_bert_config.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {
2
+ "max_seq_length": 512,
3
+ "do_lower_case": false
4
+ }
query_0_MLMTransformer/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_MLMTransformer/tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
query_0_MLMTransformer/tokenizer_config.json ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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": false,
45
+ "cls_token": "[CLS]",
46
+ "do_basic_tokenize": true,
47
+ "do_lower_case": true,
48
+ "extra_special_tokens": {},
49
+ "mask_token": "[MASK]",
50
+ "model_max_length": 1000000000000000019884624838656,
51
+ "never_split": null,
52
+ "pad_token": "[PAD]",
53
+ "sep_token": "[SEP]",
54
+ "strip_accents": null,
55
+ "tokenize_chinese_chars": true,
56
+ "tokenizer_class": "BertTokenizer",
57
+ "unk_token": "[UNK]"
58
+ }
query_0_MLMTransformer/vocab.txt ADDED
The diff for this file is too large to render. See raw diff
 
query_1_SpladePooling/config.json ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ {
2
+ "pooling_strategy": "max",
3
+ "activation_function": "relu",
4
+ "word_embedding_dimension": null
5
+ }
router_config.json ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "types": {
3
+ "query_0_MLMTransformer": "sentence_transformers.sparse_encoder.models.MLMTransformer.MLMTransformer",
4
+ "query_1_SpladePooling": "sentence_transformers.sparse_encoder.models.SpladePooling.SpladePooling",
5
+ "": "sentence_transformers.sparse_encoder.models.MLMTransformer.MLMTransformer",
6
+ "document_1_SpladePooling": "sentence_transformers.sparse_encoder.models.SpladePooling.SpladePooling"
7
+ },
8
+ "structure": {
9
+ "query": [
10
+ "query_0_MLMTransformer",
11
+ "query_1_SpladePooling"
12
+ ],
13
+ "document": [
14
+ "",
15
+ "document_1_SpladePooling"
16
+ ]
17
+ },
18
+ "parameters": {
19
+ "default_route": "document",
20
+ "allow_empty_key": true
21
+ }
22
+ }