tformal commited on
Commit
2db06b8
·
verified ·
1 Parent(s): 0f2ad0e

sentence_transformers_support (#2)

Browse files

- Add support for Sentence Transformer (9c499e1779c8bab7a1c43bc4b48c2d97b2077724)

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
@@ -4,6 +4,11 @@ language:
4
  - en
5
  tags:
6
  - splade
 
 
 
 
 
7
  ---
8
 
9
  ## SPLADE-v3-DistilBERT
@@ -19,6 +24,61 @@ To use SPLADE, please visit our GitHub repository: https://github.com/naver/spla
19
  | --- | --- | --- |
20
  | `naver/splade-v3-distilbert` | 38.7 | 50.0 |
21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  ## Citation
23
 
24
  If you use our checkpoint, please cite our work:
 
4
  - en
5
  tags:
6
  - splade
7
+ - sentence-transformers
8
+ - sparse-encoder
9
+ - sparse
10
+ pipeline_tag: feature-extraction
11
+ library_name: sentence-transformers
12
  ---
13
 
14
  ## SPLADE-v3-DistilBERT
 
24
  | --- | --- | --- |
25
  | `naver/splade-v3-distilbert` | 38.7 | 50.0 |
26
 
27
+ ## Model Details
28
+
29
+ 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.
30
+
31
+ ### Model Description
32
+ - **Model Type:** SPLADE Sparse Encoder
33
+ - **Base model:** [distilbert/distilbert-base-uncased](https://huggingface.co/distilbert/distilbert-base-uncased)
34
+ - **Maximum Sequence Length:** 512 tokens (256 for evaluation reproduction)
35
+ - **Output Dimensionality:** 30522 dimensions
36
+ - **Similarity Function:** Dot Product
37
+
38
+ ### Full Model Architecture
39
+
40
+ ```
41
+ SparseEncoder(
42
+ (0): MLMTransformer({'max_seq_length': 512, 'do_lower_case': False}) with MLMTransformer model: BertForMaskedLM
43
+ (1): SpladePooling({'pooling_strategy': 'max', 'activation_function': 'relu', 'word_embedding_dimension': 30522})
44
+ )
45
+ ```
46
+
47
+ ## Usage
48
+
49
+ ### Direct 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
+ ```python
59
+ from sentence_transformers import SparseEncoder
60
+
61
+ # Download from the 🤗 Hub
62
+ model = SparseEncoder("naver/splade-v3-distilbert")
63
+ # Run inference
64
+ queries = ["what causes aging fast"]
65
+ documents = [
66
+ "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.",
67
+ "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.",
68
+ "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)",
69
+ ]
70
+ query_embeddings = model.encode_query(queries)
71
+ document_embeddings = model.encode_document(documents)
72
+ print(query_embeddings.shape, document_embeddings.shape)
73
+ # [1, 30522] [3, 30522]
74
+
75
+ # Get the similarity scores for the embeddings
76
+ similarities = model.similarity(query_embeddings, document_embeddings)
77
+ print(similarities)
78
+ # tensor([[14.4726, 9.4432, 5.6896]])
79
+
80
+ ```
81
+
82
  ## Citation
83
 
84
  If you use our checkpoint, please cite our work:
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
+ }