pulkitmehtawork commited on
Commit
b6d36f0
·
verified ·
1 Parent(s): 812c708

Add new SparseEncoder model

Browse files
1_SpladePooling/config.json ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ {
2
+ "pooling_strategy": "max",
3
+ "activation_function": "relu",
4
+ "word_embedding_dimension": 30522
5
+ }
README.md ADDED
@@ -0,0 +1,147 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - en
4
+ license: apache-2.0
5
+ tags:
6
+ - sentence-transformers
7
+ - sparse-encoder
8
+ - sparse
9
+ - splade
10
+ base_model: distilbert/distilbert-base-uncased
11
+ pipeline_tag: feature-extraction
12
+ library_name: sentence-transformers
13
+ ---
14
+
15
+ # SPLADE distilbert-base-uncased trained on python docstring code pairs
16
+
17
+ This is a [SPLADE Sparse Encoder](https://www.sbert.net/docs/sparse_encoder/usage/usage.html) model finetuned from [distilbert/distilbert-base-uncased](https://huggingface.co/distilbert/distilbert-base-uncased) using the [sentence-transformers](https://www.SBERT.net) library. It maps sentences & paragraphs to a 30522-dimensional sparse vector space and can be used for semantic search and sparse retrieval.
18
+ ## Model Details
19
+
20
+ ### Model Description
21
+ - **Model Type:** SPLADE Sparse Encoder
22
+ - **Base model:** [distilbert/distilbert-base-uncased](https://huggingface.co/distilbert/distilbert-base-uncased) <!-- at revision 12040accade4e8a0f71eabdb258fecc2e7e948be -->
23
+ - **Maximum Sequence Length:** 512 tokens
24
+ - **Output Dimensionality:** 30522 dimensions
25
+ - **Similarity Function:** Dot Product
26
+ <!-- - **Training Dataset:** Unknown -->
27
+ - **Language:** en
28
+ - **License:** apache-2.0
29
+
30
+ ### Model Sources
31
+
32
+ - **Documentation:** [Sentence Transformers Documentation](https://sbert.net)
33
+ - **Documentation:** [Sparse Encoder Documentation](https://www.sbert.net/docs/sparse_encoder/usage/usage.html)
34
+ - **Repository:** [Sentence Transformers on GitHub](https://github.com/UKPLab/sentence-transformers)
35
+ - **Hugging Face:** [Sparse Encoders on Hugging Face](https://huggingface.co/models?library=sentence-transformers&other=sparse-encoder)
36
+
37
+ ### Full Model Architecture
38
+
39
+ ```
40
+ SparseEncoder(
41
+ (0): MLMTransformer({'max_seq_length': 512, 'do_lower_case': False, 'architecture': 'DistilBertForMaskedLM'})
42
+ (1): SpladePooling({'pooling_strategy': 'max', 'activation_function': 'relu', 'word_embedding_dimension': 30522})
43
+ )
44
+ ```
45
+
46
+ ## Usage
47
+
48
+ ### Direct 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
+ ```python
58
+ from sentence_transformers import SparseEncoder
59
+
60
+ # Download from the 🤗 Hub
61
+ model = SparseEncoder("pulkitmehtawork/sparse-distilbert-base-uncased-python-code-lightening")
62
+ # Run inference
63
+ sentences = [
64
+ 'The weather is lovely today.',
65
+ "It's so sunny outside!",
66
+ 'He drove to the stadium.',
67
+ ]
68
+ embeddings = model.encode(sentences)
69
+ print(embeddings.shape)
70
+ # [3, 30522]
71
+
72
+ # Get the similarity scores for the embeddings
73
+ similarities = model.similarity(embeddings, embeddings)
74
+ print(similarities)
75
+ # tensor([[2148.8340, 1376.2744, 850.4404],
76
+ # [1376.2744, 2056.9260, 898.0439],
77
+ # [ 850.4404, 898.0439, 2509.7507]])
78
+ ```
79
+
80
+ <!--
81
+ ### Direct Usage (Transformers)
82
+
83
+ <details><summary>Click to see the direct usage in Transformers</summary>
84
+
85
+ </details>
86
+ -->
87
+
88
+ <!--
89
+ ### Downstream Usage (Sentence Transformers)
90
+
91
+ You can finetune this model on your own dataset.
92
+
93
+ <details><summary>Click to expand</summary>
94
+
95
+ </details>
96
+ -->
97
+
98
+ <!--
99
+ ### Out-of-Scope Use
100
+
101
+ *List how the model may foreseeably be misused and address what users ought not to do with the model.*
102
+ -->
103
+
104
+ <!--
105
+ ## Bias, Risks and Limitations
106
+
107
+ *What are the known or foreseeable issues stemming from this model? You could also flag here known failure cases or weaknesses of the model.*
108
+ -->
109
+
110
+ <!--
111
+ ### Recommendations
112
+
113
+ *What are recommendations with respect to the foreseeable issues? For example, filtering explicit content.*
114
+ -->
115
+
116
+ ## Training Details
117
+
118
+ ### Framework Versions
119
+ - Python: 3.10.10
120
+ - Sentence Transformers: 5.0.0
121
+ - Transformers: 4.53.0
122
+ - PyTorch: 2.7.0+cu128
123
+ - Accelerate: 1.8.1
124
+ - Datasets: 3.6.0
125
+ - Tokenizers: 0.21.2
126
+
127
+ ## Citation
128
+
129
+ ### BibTeX
130
+
131
+ <!--
132
+ ## Glossary
133
+
134
+ *Clearly define terms in order to be accessible across audiences.*
135
+ -->
136
+
137
+ <!--
138
+ ## Model Card Authors
139
+
140
+ *Lists the people who create the model card, providing recognition and accountability for the detailed work that goes into its construction.*
141
+ -->
142
+
143
+ <!--
144
+ ## Model Card Contact
145
+
146
+ *Provides a way for people who have updates to the Model Card, suggestions, or questions, to contact the Model Card authors.*
147
+ -->
config.json ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "activation": "gelu",
3
+ "architectures": [
4
+ "DistilBertForMaskedLM"
5
+ ],
6
+ "attention_dropout": 0.1,
7
+ "dim": 768,
8
+ "dropout": 0.1,
9
+ "hidden_dim": 3072,
10
+ "initializer_range": 0.02,
11
+ "max_position_embeddings": 512,
12
+ "model_type": "distilbert",
13
+ "n_heads": 12,
14
+ "n_layers": 6,
15
+ "pad_token_id": 0,
16
+ "qa_dropout": 0.1,
17
+ "seq_classif_dropout": 0.2,
18
+ "sinusoidal_pos_embds": false,
19
+ "tie_weights_": true,
20
+ "torch_dtype": "float32",
21
+ "transformers_version": "4.53.0",
22
+ "vocab_size": 30522
23
+ }
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.53.0",
6
+ "pytorch": "2.7.0+cu128"
7
+ },
8
+ "prompts": {
9
+ "query": "",
10
+ "document": ""
11
+ },
12
+ "default_prompt_name": null,
13
+ "similarity_fn_name": "dot"
14
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5e3f1108e3cb34ee048634875d8482665b65ac713291a7e32396fb18f6ff0063
3
+ size 267954768
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
+ }
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,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": false,
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
+ }
vocab.txt ADDED
The diff for this file is too large to render. See raw diff