Upload folder using huggingface_hub
Browse files- 1_TokenPooling/config.json +3 -0
- README.md +97 -155
- config.json +52 -0
- config_sentence_transformers.json +10 -0
- modules.json +20 -0
- quantize_config.json +13 -0
- sentence_bert_config.json +3 -0
- token_pooling.py +59 -0
1_TokenPooling/config.json
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"dimension": 4096
|
3 |
+
}
|
README.md
CHANGED
@@ -1,199 +1,141 @@
|
|
1 |
---
|
2 |
-
|
3 |
-
|
|
|
|
|
|
|
|
|
4 |
---
|
5 |
|
6 |
-
#
|
7 |
-
|
8 |
-
<!-- Provide a quick summary of what the model is/does. -->
|
9 |
-
|
10 |
|
|
|
11 |
|
12 |
## Model Details
|
13 |
|
14 |
### Model Description
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
|
19 |
-
|
20 |
-
- **Developed by:** [More Information Needed]
|
21 |
-
- **Funded by [optional]:** [More Information Needed]
|
22 |
-
- **Shared by [optional]:** [More Information Needed]
|
23 |
-
- **Model type:** [More Information Needed]
|
24 |
-
- **Language(s) (NLP):** [More Information Needed]
|
25 |
-
- **License:** [More Information Needed]
|
26 |
-
- **Finetuned from model [optional]:** [More Information Needed]
|
27 |
|
28 |
-
|
|
|
|
|
29 |
|
30 |
-
|
31 |
|
32 |
-
|
33 |
-
|
34 |
-
-
|
|
|
|
|
|
|
|
|
35 |
|
36 |
-
##
|
37 |
|
38 |
-
|
39 |
|
40 |
-
|
41 |
|
42 |
-
|
|
|
|
|
43 |
|
44 |
-
|
|
|
|
|
45 |
|
46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
|
48 |
-
|
|
|
|
|
|
|
|
|
49 |
|
50 |
-
|
|
|
51 |
|
52 |
-
|
53 |
|
54 |
-
|
|
|
55 |
|
56 |
-
|
|
|
57 |
|
58 |
-
|
59 |
|
60 |
-
|
61 |
|
62 |
-
|
|
|
63 |
|
64 |
-
|
|
|
65 |
|
66 |
-
|
|
|
67 |
|
68 |
-
|
|
|
69 |
|
70 |
-
|
|
|
71 |
|
72 |
-
|
|
|
73 |
|
74 |
-
|
|
|
75 |
|
76 |
## Training Details
|
77 |
|
78 |
-
###
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
<!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
|
87 |
-
|
88 |
-
#### Preprocessing [optional]
|
89 |
-
|
90 |
-
[More Information Needed]
|
91 |
-
|
92 |
-
|
93 |
-
#### Training Hyperparameters
|
94 |
-
|
95 |
-
- **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
|
96 |
-
|
97 |
-
#### Speeds, Sizes, Times [optional]
|
98 |
-
|
99 |
-
<!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
|
100 |
-
|
101 |
-
[More Information Needed]
|
102 |
-
|
103 |
-
## Evaluation
|
104 |
-
|
105 |
-
<!-- This section describes the evaluation protocols and provides the results. -->
|
106 |
-
|
107 |
-
### Testing Data, Factors & Metrics
|
108 |
-
|
109 |
-
#### Testing Data
|
110 |
-
|
111 |
-
<!-- This should link to a Dataset Card if possible. -->
|
112 |
-
|
113 |
-
[More Information Needed]
|
114 |
-
|
115 |
-
#### Factors
|
116 |
-
|
117 |
-
<!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
|
118 |
-
|
119 |
-
[More Information Needed]
|
120 |
-
|
121 |
-
#### Metrics
|
122 |
-
|
123 |
-
<!-- These are the evaluation metrics being used, ideally with a description of why. -->
|
124 |
-
|
125 |
-
[More Information Needed]
|
126 |
-
|
127 |
-
### Results
|
128 |
-
|
129 |
-
[More Information Needed]
|
130 |
-
|
131 |
-
#### Summary
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
## Model Examination [optional]
|
136 |
-
|
137 |
-
<!-- Relevant interpretability work for the model goes here -->
|
138 |
-
|
139 |
-
[More Information Needed]
|
140 |
-
|
141 |
-
## Environmental Impact
|
142 |
-
|
143 |
-
<!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
|
144 |
-
|
145 |
-
Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
|
146 |
-
|
147 |
-
- **Hardware Type:** [More Information Needed]
|
148 |
-
- **Hours used:** [More Information Needed]
|
149 |
-
- **Cloud Provider:** [More Information Needed]
|
150 |
-
- **Compute Region:** [More Information Needed]
|
151 |
-
- **Carbon Emitted:** [More Information Needed]
|
152 |
-
|
153 |
-
## Technical Specifications [optional]
|
154 |
-
|
155 |
-
### Model Architecture and Objective
|
156 |
-
|
157 |
-
[More Information Needed]
|
158 |
-
|
159 |
-
### Compute Infrastructure
|
160 |
-
|
161 |
-
[More Information Needed]
|
162 |
-
|
163 |
-
#### Hardware
|
164 |
-
|
165 |
-
[More Information Needed]
|
166 |
-
|
167 |
-
#### Software
|
168 |
-
|
169 |
-
[More Information Needed]
|
170 |
-
|
171 |
-
## Citation [optional]
|
172 |
-
|
173 |
-
<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
|
174 |
-
|
175 |
-
**BibTeX:**
|
176 |
-
|
177 |
-
[More Information Needed]
|
178 |
-
|
179 |
-
**APA:**
|
180 |
-
|
181 |
-
[More Information Needed]
|
182 |
-
|
183 |
-
## Glossary [optional]
|
184 |
|
185 |
-
|
186 |
|
187 |
-
|
188 |
|
189 |
-
|
|
|
190 |
|
191 |
-
|
|
|
192 |
|
193 |
-
|
|
|
194 |
|
195 |
-
|
|
|
196 |
|
|
|
197 |
## Model Card Contact
|
198 |
|
199 |
-
|
|
|
|
1 |
---
|
2 |
+
tags:
|
3 |
+
- sentence-transformers
|
4 |
+
- sentence-similarity
|
5 |
+
- feature-extraction
|
6 |
+
pipeline_tag: sentence-similarity
|
7 |
+
library_name: sentence-transformers
|
8 |
---
|
9 |
|
10 |
+
# SentenceTransformer
|
|
|
|
|
|
|
11 |
|
12 |
+
This is a [sentence-transformers](https://www.SBERT.net) model trained. It maps sentences & paragraphs to a 4096-dimensional dense vector space and can be used for semantic textual similarity, semantic search, paraphrase mining, text classification, clustering, and more.
|
13 |
|
14 |
## Model Details
|
15 |
|
16 |
### Model Description
|
17 |
+
- **Model Type:** Sentence Transformer
|
18 |
+
<!-- - **Base model:** [Unknown](https://huggingface.co/unknown) -->
|
19 |
+
- **Maximum Sequence Length:** 4096 tokens
|
20 |
+
- **Output Dimensionality:** 4096 tokens
|
21 |
+
- **Similarity Function:** Cosine Similarity
|
22 |
+
<!-- - **Training Dataset:** Unknown -->
|
23 |
+
<!-- - **Language:** Unknown -->
|
24 |
+
<!-- - **License:** Unknown -->
|
25 |
|
26 |
+
### Model Sources
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
+
- **Documentation:** [Sentence Transformers Documentation](https://sbert.net)
|
29 |
+
- **Repository:** [Sentence Transformers on GitHub](https://github.com/UKPLab/sentence-transformers)
|
30 |
+
- **Hugging Face:** [Sentence Transformers on Hugging Face](https://huggingface.co/models?library=sentence-transformers)
|
31 |
|
32 |
+
### Full Model Architecture
|
33 |
|
34 |
+
```
|
35 |
+
SentenceTransformer(
|
36 |
+
(0): Transformer({'model_name_or_path': 'lamarr-llm-development/elbedding'}) with Transformer model: LlamaModel
|
37 |
+
(1): TokenPooling()
|
38 |
+
(2): Normalize()
|
39 |
+
)
|
40 |
+
```
|
41 |
|
42 |
+
## Usage
|
43 |
|
44 |
+
### Direct Usage (Sentence Transformers)
|
45 |
|
46 |
+
First install the Sentence Transformers library:
|
47 |
|
48 |
+
```bash
|
49 |
+
pip install -U sentence-transformers
|
50 |
+
```
|
51 |
|
52 |
+
Then you can load this model and run inference.
|
53 |
+
```python
|
54 |
+
from sentence_transformers import SentenceTransformer
|
55 |
|
56 |
+
# Download from the 🤗 Hub
|
57 |
+
model = SentenceTransformer("sentence_transformers_model_id")
|
58 |
+
# Run inference
|
59 |
+
sentences = [
|
60 |
+
'The weather is lovely today.',
|
61 |
+
"It's so sunny outside!",
|
62 |
+
'He drove to the stadium.',
|
63 |
+
]
|
64 |
+
embeddings = model.encode(sentences)
|
65 |
+
print(embeddings.shape)
|
66 |
+
# [3, 4096]
|
67 |
|
68 |
+
# Get the similarity scores for the embeddings
|
69 |
+
similarities = model.similarity(embeddings, embeddings)
|
70 |
+
print(similarities.shape)
|
71 |
+
# [3, 3]
|
72 |
+
```
|
73 |
|
74 |
+
<!--
|
75 |
+
### Direct Usage (Transformers)
|
76 |
|
77 |
+
<details><summary>Click to see the direct usage in Transformers</summary>
|
78 |
|
79 |
+
</details>
|
80 |
+
-->
|
81 |
|
82 |
+
<!--
|
83 |
+
### Downstream Usage (Sentence Transformers)
|
84 |
|
85 |
+
You can finetune this model on your own dataset.
|
86 |
|
87 |
+
<details><summary>Click to expand</summary>
|
88 |
|
89 |
+
</details>
|
90 |
+
-->
|
91 |
|
92 |
+
<!--
|
93 |
+
### Out-of-Scope Use
|
94 |
|
95 |
+
*List how the model may foreseeably be misused and address what users ought not to do with the model.*
|
96 |
+
-->
|
97 |
|
98 |
+
<!--
|
99 |
+
## Bias, Risks and Limitations
|
100 |
|
101 |
+
*What are the known or foreseeable issues stemming from this model? You could also flag here known failure cases or weaknesses of the model.*
|
102 |
+
-->
|
103 |
|
104 |
+
<!--
|
105 |
+
### Recommendations
|
106 |
|
107 |
+
*What are recommendations with respect to the foreseeable issues? For example, filtering explicit content.*
|
108 |
+
-->
|
109 |
|
110 |
## Training Details
|
111 |
|
112 |
+
### Framework Versions
|
113 |
+
- Python: 3.10.12
|
114 |
+
- Sentence Transformers: 3.2.1
|
115 |
+
- Transformers: 4.48.3
|
116 |
+
- PyTorch: 2.4.0+cu121
|
117 |
+
- Accelerate: 1.4.0
|
118 |
+
- Datasets: 3.5.0
|
119 |
+
- Tokenizers: 0.21.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
120 |
|
121 |
+
## Citation
|
122 |
|
123 |
+
### BibTeX
|
124 |
|
125 |
+
<!--
|
126 |
+
## Glossary
|
127 |
|
128 |
+
*Clearly define terms in order to be accessible across audiences.*
|
129 |
+
-->
|
130 |
|
131 |
+
<!--
|
132 |
+
## Model Card Authors
|
133 |
|
134 |
+
*Lists the people who create the model card, providing recognition and accountability for the detailed work that goes into its construction.*
|
135 |
+
-->
|
136 |
|
137 |
+
<!--
|
138 |
## Model Card Contact
|
139 |
|
140 |
+
*Provides a way for people who have updates to the Model Card, suggestions, or questions, to contact the Model Card authors.*
|
141 |
+
-->
|
config.json
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_attn_implementation_autoset": true,
|
3 |
+
"_name_or_path": "lamarr-llm-development/elbedding-v2-AutoGPTQ-4bit",
|
4 |
+
"architectures": [
|
5 |
+
"LlamaForSequenceEmbedding"
|
6 |
+
],
|
7 |
+
"attention_bias": false,
|
8 |
+
"attention_dropout": 0.0,
|
9 |
+
"auto_map": {
|
10 |
+
"AutoTokenizer": [
|
11 |
+
"openGPT-X/Teuken-7B-base-v0.6--gptx_tokenizer.SPTokenizer",
|
12 |
+
null
|
13 |
+
]
|
14 |
+
},
|
15 |
+
"bos_token_id": 1,
|
16 |
+
"eos_token_id": 4,
|
17 |
+
"head_dim": 128,
|
18 |
+
"hidden_act": "silu",
|
19 |
+
"hidden_size": 4096,
|
20 |
+
"initializer_range": 0.0158,
|
21 |
+
"intermediate_size": 13440,
|
22 |
+
"max_position_embeddings": 4096,
|
23 |
+
"mlp_bias": false,
|
24 |
+
"model_type": "llama",
|
25 |
+
"num_attention_heads": 32,
|
26 |
+
"num_hidden_layers": 32,
|
27 |
+
"num_key_value_heads": 2,
|
28 |
+
"pad_token_id": 3,
|
29 |
+
"pretraining_tp": 1,
|
30 |
+
"quantization_config": {
|
31 |
+
"bits": 4,
|
32 |
+
"damp_percent": 0.01,
|
33 |
+
"desc_act": false,
|
34 |
+
"group_size": 128,
|
35 |
+
"is_marlin_format": false,
|
36 |
+
"model_file_base_name": null,
|
37 |
+
"model_name_or_path": null,
|
38 |
+
"quant_method": "gptq",
|
39 |
+
"static_groups": false,
|
40 |
+
"sym": true,
|
41 |
+
"true_sequential": true
|
42 |
+
},
|
43 |
+
"rms_norm_eps": 1e-05,
|
44 |
+
"rope_scaling": null,
|
45 |
+
"rope_theta": 10000.0,
|
46 |
+
"tie_word_embeddings": true,
|
47 |
+
"tokenizer_class": "SPTokenizer",
|
48 |
+
"torch_dtype": "float16",
|
49 |
+
"transformers_version": "4.48.3",
|
50 |
+
"use_cache": true,
|
51 |
+
"vocab_size": 250880
|
52 |
+
}
|
config_sentence_transformers.json
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"__version__": {
|
3 |
+
"sentence_transformers": "3.2.1",
|
4 |
+
"transformers": "4.48.3",
|
5 |
+
"pytorch": "2.4.0+cu121"
|
6 |
+
},
|
7 |
+
"prompts": {},
|
8 |
+
"default_prompt_name": null,
|
9 |
+
"similarity_fn_name": null
|
10 |
+
}
|
modules.json
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[
|
2 |
+
{
|
3 |
+
"idx": 0,
|
4 |
+
"name": "0",
|
5 |
+
"path": "",
|
6 |
+
"type": "embedding_model.EmbeddingModel"
|
7 |
+
},
|
8 |
+
{
|
9 |
+
"idx": 1,
|
10 |
+
"name": "1",
|
11 |
+
"path": "1_TokenPooling",
|
12 |
+
"type": "token_pooling.TokenPooling"
|
13 |
+
},
|
14 |
+
{
|
15 |
+
"idx": 2,
|
16 |
+
"name": "2",
|
17 |
+
"path": "2_Normalize",
|
18 |
+
"type": "sentence_transformers.models.Normalize"
|
19 |
+
}
|
20 |
+
]
|
quantize_config.json
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"bits": 4,
|
3 |
+
"group_size": 128,
|
4 |
+
"damp_percent": 0.01,
|
5 |
+
"desc_act": false,
|
6 |
+
"static_groups": false,
|
7 |
+
"sym": true,
|
8 |
+
"true_sequential": true,
|
9 |
+
"model_name_or_path": null,
|
10 |
+
"model_file_base_name": null,
|
11 |
+
"is_marlin_format": false,
|
12 |
+
"quant_method": "gptq"
|
13 |
+
}
|
sentence_bert_config.json
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"model_name_or_path": "lamarr-llm-development/elbedding-v2-AutoGPTQ-4bit"
|
3 |
+
}
|
token_pooling.py
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
import os
|
3 |
+
import torch
|
4 |
+
import torch.nn as nn
|
5 |
+
|
6 |
+
|
7 |
+
class TokenPooling(nn.Module):
|
8 |
+
def __init__(self, dimension: int = 4096) -> None:
|
9 |
+
super(TokenPooling, self).__init__()
|
10 |
+
self.dimension = dimension
|
11 |
+
|
12 |
+
def forward(
|
13 |
+
self, features: dict[str, torch.Tensor], **kwargs
|
14 |
+
) -> dict[str, torch.Tensor]:
|
15 |
+
token_embeddings = features["token_embeddings"]
|
16 |
+
attention_mask = features["attention_mask"]
|
17 |
+
|
18 |
+
embeddings = self.pool(
|
19 |
+
last_hidden_state=token_embeddings, attention_mask=attention_mask
|
20 |
+
)
|
21 |
+
features["sentence_embedding"] = embeddings
|
22 |
+
return features
|
23 |
+
|
24 |
+
def pool(
|
25 |
+
self, last_hidden_state: torch.Tensor, attention_mask: torch.Tensor
|
26 |
+
) -> torch.Tensor:
|
27 |
+
"""
|
28 |
+
Here, we take the embedding of the last token from the last layer
|
29 |
+
"""
|
30 |
+
left_padding = attention_mask[:, -1].sum() == attention_mask.shape[0]
|
31 |
+
if left_padding:
|
32 |
+
return last_hidden_state[:, -1]
|
33 |
+
else:
|
34 |
+
sequence_lengths = attention_mask.sum(dim=1) - 1
|
35 |
+
batch_size = last_hidden_state.shape[0]
|
36 |
+
return last_hidden_state[
|
37 |
+
torch.arange(batch_size, device=last_hidden_state.device).long(),
|
38 |
+
sequence_lengths.long(),
|
39 |
+
]
|
40 |
+
|
41 |
+
def get_sentence_embedding_dimension(self) -> int:
|
42 |
+
return self.dimension
|
43 |
+
|
44 |
+
def get_config_dict(self) -> dict[str, float]:
|
45 |
+
return {"dimension": self.dimension}
|
46 |
+
|
47 |
+
def save(self, save_dir: str, **kwargs) -> None:
|
48 |
+
pooling_path = os.path.join(save_dir)
|
49 |
+
if not os.path.exists(pooling_path):
|
50 |
+
os.makedirs(pooling_path)
|
51 |
+
|
52 |
+
with open(f"{pooling_path}/config.json", "w+") as f:
|
53 |
+
json.dump(self.get_config_dict(), f, indent=4)
|
54 |
+
|
55 |
+
@staticmethod
|
56 |
+
def load(load_dir: str, **kwargs) -> "TokenPooling":
|
57 |
+
with open(os.path.join(load_dir, "config.json")) as fIn:
|
58 |
+
config = json.load(fIn)
|
59 |
+
return TokenPooling(**config)
|