tformal commited on
Commit
b5e5ebf
·
verified ·
1 Parent(s): 38e53c5

sentence_transformers_support (#2)

Browse files

- Add support for Sentence Transformer (0abe4aafd9afb6244fd6e400d537a013370413f3)

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
@@ -1,5 +1,94 @@
1
  ---
2
  license: cc-by-nc-sa-4.0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  ---
4
 
5
- Also called SPLADE-v2 in some papers
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: cc-by-nc-sa-4.0
3
+ language: "en"
4
+ tags:
5
+ - splade
6
+ - query-expansion
7
+ - document-expansion
8
+ - bag-of-words
9
+ - passage-retrieval
10
+ - knowledge-distillation
11
+ - sentence-transformers
12
+ - sparse-encoder
13
+ - sparse
14
+ pipeline_tag: feature-extraction
15
+ library_name: sentence-transformers
16
+ datasets:
17
+ - ms_marco
18
  ---
19
 
20
+ Also called SPLADE-v2 in some papers
21
+
22
+ ## SPLADE_v2_distill
23
+
24
+ SPLADE model for passage retrieval. For additional details, please visit:
25
+ * paper: https://arxiv.org/abs/2109.10086
26
+ * code: https://github.com/naver/splade
27
+
28
+ ## Model Details
29
+
30
+ This is a [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.
31
+
32
+ ### Model Description
33
+ - **Model Type:** SPLADE Sparse Encoder
34
+ - **Base model:** [distilbert/distilbert-base-uncased](https://huggingface.co/distilbert/distilbert-base-uncased)
35
+ - **Maximum Sequence Length:** 512 tokens (256 for evaluation reproduction)
36
+ - **Output Dimensionality:** 30522 dimensions
37
+ - **Similarity Function:** Dot Product
38
+
39
+ ### Full Model Architecture
40
+
41
+ ```
42
+ SparseEncoder(
43
+ (0): MLMTransformer({'max_seq_length': 512, 'do_lower_case': False}) with MLMTransformer model: BertForMaskedLM
44
+ (1): SpladePooling({'pooling_strategy': 'max', 'activation_function': 'relu', 'word_embedding_dimension': 30522})
45
+ )
46
+ ```
47
+
48
+ ## Usage
49
+
50
+ ### Direct Usage (Sentence Transformers)
51
+
52
+ First install the Sentence Transformers library:
53
+
54
+ ```bash
55
+ pip install -U sentence-transformers
56
+ ```
57
+
58
+ Then you can load this model and run inference.
59
+ ```python
60
+ from sentence_transformers import SparseEncoder
61
+
62
+ # Download from the 🤗 Hub
63
+ model = SparseEncoder("naver/splade_v2_distil")
64
+ # Run inference
65
+ queries = ["what causes aging fast"]
66
+ documents = [
67
+ "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.",
68
+ "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.",
69
+ "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)",
70
+ ]
71
+ query_embeddings = model.encode_query(queries)
72
+ document_embeddings = model.encode_document(documents)
73
+ print(query_embeddings.shape, document_embeddings.shape)
74
+ # [1, 30522] [3, 30522]
75
+
76
+ # Get the similarity scores for the embeddings
77
+ similarities = model.similarity(query_embeddings, document_embeddings)
78
+ print(similarities)
79
+ # tensor([[15.0450, 13.3137, 5.3127]])
80
+
81
+ ```
82
+
83
+ ## Citation
84
+
85
+ If you use our checkpoint, please cite our work:
86
+
87
+ ```
88
+ @article{formal2021splade,
89
+ title={SPLADE v2: Sparse lexical and expansion model for information retrieval},
90
+ author={Formal, Thibault and Lassance, Carlos and Piwowarski, Benjamin and Clinchant, St{\'e}phane},
91
+ journal={arXiv preprint arXiv:2109.10086},
92
+ year={2021}
93
+ }
94
+ ```
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
+ }