Add new SentenceTransformer model.
Browse files- .gitattributes +1 -0
- 1_Pooling/config.json +10 -0
- README.md +463 -0
- config.json +67 -0
- config_sentence_transformers.json +16 -0
- custom_st.py +229 -0
- model.safetensors +3 -0
- modules.json +20 -0
- sentence_bert_config.json +4 -0
- special_tokens_map.json +51 -0
- tokenizer.json +3 -0
- tokenizer_config.json +54 -0
.gitattributes
CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
1_Pooling/config.json
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"word_embedding_dimension": 1024,
|
3 |
+
"pooling_mode_cls_token": false,
|
4 |
+
"pooling_mode_mean_tokens": true,
|
5 |
+
"pooling_mode_max_tokens": false,
|
6 |
+
"pooling_mode_mean_sqrt_len_tokens": false,
|
7 |
+
"pooling_mode_weightedmean_tokens": false,
|
8 |
+
"pooling_mode_lasttoken": false,
|
9 |
+
"include_prompt": true
|
10 |
+
}
|
README.md
ADDED
@@ -0,0 +1,463 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
tags:
|
3 |
+
- sentence-transformers
|
4 |
+
- sentence-similarity
|
5 |
+
- feature-extraction
|
6 |
+
- generated_from_trainer
|
7 |
+
- dataset_size:16000
|
8 |
+
- loss:OnlineContrastiveLoss
|
9 |
+
base_model: jinaai/jina-embeddings-v3
|
10 |
+
widget:
|
11 |
+
- source_sentence: This is absolutely the worst trash I have ever seen. When I saw
|
12 |
+
it in the theater (arghhh!), it took 15 full minutes before I realized that what
|
13 |
+
I was seeing was the feature, not a sick joke!
|
14 |
+
sentences:
|
15 |
+
- negative negative negative negative
|
16 |
+
- negative negative negative negative
|
17 |
+
- positive positive positive positive
|
18 |
+
- source_sentence: I saw this movie years ago in a group tradition of Fast Forward
|
19 |
+
Film Festivals, where we would set out to rent a bunch of B-movies and vote for
|
20 |
+
who picked the worst.<br /><br />The night we watched this, it was voted the best,
|
21 |
+
due to semblance of plot and fun costuming.<br /><br />This is certainly a silly,
|
22 |
+
kitschy, movie, to be watched under the full understanding that you are watching
|
23 |
+
low-budget fluff. Personally, however, I wouldn't recommend additional substances
|
24 |
+
... this movie will leave it's own mark on you.<br /><br />It made enough of an
|
25 |
+
impression on me that I've actually been trying to get my hands on a copy for
|
26 |
+
a few years.<br /><br />A good choice if you are setting out to watch bad movies.
|
27 |
+
This one is fun, and I remember bouncy music ...
|
28 |
+
sentences:
|
29 |
+
- negative negative negative negative
|
30 |
+
- positive positive positive positive
|
31 |
+
- negative negative negative negative
|
32 |
+
- source_sentence: 'Star Wars: Episode 4 .<br /><br />the best Star Wars ever. its
|
33 |
+
the first movie i ever Sean were the bad guys win and its a very good ending.
|
34 |
+
it really had me wait hing for the next star wars because so match stuff comes
|
35 |
+
along in this movie that you just got to find out more in the last one. whit Al
|
36 |
+
lot of movies i always get the feeling that it could be don bedder but not whit
|
37 |
+
this one. and i Will never ever forget the part were wader tels Luke he is his
|
38 |
+
father.way too cool. also love the Bob feat figure a do hes a back ground player.
|
39 |
+
if you never ever Saw a star wars movie you go to she this one.its the best.<br
|
40 |
+
/><br />thanks Lucas'
|
41 |
+
sentences:
|
42 |
+
- negative negative negative negative
|
43 |
+
- positive positive positive positive
|
44 |
+
- positive positive positive positive
|
45 |
+
- source_sentence: Alain Chabat claims this movie as his original idea but the theme
|
46 |
+
of reluctant lovers who finally get it together is as old, if not older, than
|
47 |
+
Shakespeare.<br /><br />Chabat is a "vieux garcon", happily single and not wanting
|
48 |
+
any member of the opposite sex to disturb his life. He has a problem, 5 sisters
|
49 |
+
and a matriarchal mum - the G7 - who decide he should be married. Enter the delightful,
|
50 |
+
charming Charlotte Gainsbourg and what should be a simple plan. Charlotte has
|
51 |
+
to pose as Chabat's girlfriend and then simply not turn up on the day of the wedding.
|
52 |
+
No more talk of marriage from the G7. Of course the best laid plans have a habit
|
53 |
+
of spiralling out of control.<br /><br />There are very strong supporting roles
|
54 |
+
from Lafont as the mother and Osterman as the tight-fisted brother of Gainsbourg.<br
|
55 |
+
/><br />There are some fantastic scenes as first Charlotte has to charm, then
|
56 |
+
revolt the family. French farce with an English.
|
57 |
+
sentences:
|
58 |
+
- positive positive positive positive
|
59 |
+
- negative negative negative negative
|
60 |
+
- negative negative negative negative
|
61 |
+
- source_sentence: Saw this on cable back in the early 90's and loved it. Never saw
|
62 |
+
it again until it showed up on cable again recently. Still find it a great Vietnam
|
63 |
+
movie. Not sure why its not higher rated. I found everything about this film compelling.
|
64 |
+
As a vet (not from Vietnam) I can relate to the situations brought by both Harris
|
65 |
+
and De Niro. I can only imagine this film being more poignant now with our situation
|
66 |
+
in Iraq. I wish this would be offered on cable more often for people to see. The
|
67 |
+
human toll on our soldiers isn't left on the battlefield. Its brought home for
|
68 |
+
the rest of there lives. And this film is one of many that brings that home in
|
69 |
+
a very hard way. Excellent film.
|
70 |
+
sentences:
|
71 |
+
- negative negative negative negative
|
72 |
+
- positive positive positive positive
|
73 |
+
- positive positive positive positive
|
74 |
+
pipeline_tag: sentence-similarity
|
75 |
+
library_name: sentence-transformers
|
76 |
+
---
|
77 |
+
|
78 |
+
# SentenceTransformer based on jinaai/jina-embeddings-v3
|
79 |
+
|
80 |
+
This is a [sentence-transformers](https://www.SBERT.net) model finetuned from [jinaai/jina-embeddings-v3](https://huggingface.co/jinaai/jina-embeddings-v3). It maps sentences & paragraphs to a 1024-dimensional dense vector space and can be used for semantic textual similarity, semantic search, paraphrase mining, text classification, clustering, and more.
|
81 |
+
|
82 |
+
## Model Details
|
83 |
+
|
84 |
+
### Model Description
|
85 |
+
- **Model Type:** Sentence Transformer
|
86 |
+
- **Base model:** [jinaai/jina-embeddings-v3](https://huggingface.co/jinaai/jina-embeddings-v3) <!-- at revision 62a81741b58448ed8f691764cec7aa5d3c045e4c -->
|
87 |
+
- **Maximum Sequence Length:** 8194 tokens
|
88 |
+
- **Output Dimensionality:** 1024 tokens
|
89 |
+
- **Similarity Function:** Cosine Similarity
|
90 |
+
<!-- - **Training Dataset:** Unknown -->
|
91 |
+
<!-- - **Language:** Unknown -->
|
92 |
+
<!-- - **License:** Unknown -->
|
93 |
+
|
94 |
+
### Model Sources
|
95 |
+
|
96 |
+
- **Documentation:** [Sentence Transformers Documentation](https://sbert.net)
|
97 |
+
- **Repository:** [Sentence Transformers on GitHub](https://github.com/UKPLab/sentence-transformers)
|
98 |
+
- **Hugging Face:** [Sentence Transformers on Hugging Face](https://huggingface.co/models?library=sentence-transformers)
|
99 |
+
|
100 |
+
### Full Model Architecture
|
101 |
+
|
102 |
+
```
|
103 |
+
SentenceTransformer(
|
104 |
+
(transformer): Transformer(
|
105 |
+
(auto_model): XLMRobertaLoRA(
|
106 |
+
(roberta): XLMRobertaModel(
|
107 |
+
(embeddings): XLMRobertaEmbeddings(
|
108 |
+
(word_embeddings): ParametrizedEmbedding(
|
109 |
+
250002, 1024, padding_idx=1
|
110 |
+
(parametrizations): ModuleDict(
|
111 |
+
(weight): ParametrizationList(
|
112 |
+
(0): LoRAParametrization()
|
113 |
+
)
|
114 |
+
)
|
115 |
+
)
|
116 |
+
(token_type_embeddings): ParametrizedEmbedding(
|
117 |
+
1, 1024
|
118 |
+
(parametrizations): ModuleDict(
|
119 |
+
(weight): ParametrizationList(
|
120 |
+
(0): LoRAParametrization()
|
121 |
+
)
|
122 |
+
)
|
123 |
+
)
|
124 |
+
)
|
125 |
+
(emb_drop): Dropout(p=0.1, inplace=False)
|
126 |
+
(emb_ln): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)
|
127 |
+
(encoder): XLMRobertaEncoder(
|
128 |
+
(layers): ModuleList(
|
129 |
+
(0-23): 24 x Block(
|
130 |
+
(mixer): MHA(
|
131 |
+
(rotary_emb): RotaryEmbedding()
|
132 |
+
(Wqkv): ParametrizedLinearResidual(
|
133 |
+
in_features=1024, out_features=3072, bias=True
|
134 |
+
(parametrizations): ModuleDict(
|
135 |
+
(weight): ParametrizationList(
|
136 |
+
(0): LoRAParametrization()
|
137 |
+
)
|
138 |
+
)
|
139 |
+
)
|
140 |
+
(inner_attn): FlashSelfAttention(
|
141 |
+
(drop): Dropout(p=0.1, inplace=False)
|
142 |
+
)
|
143 |
+
(inner_cross_attn): FlashCrossAttention(
|
144 |
+
(drop): Dropout(p=0.1, inplace=False)
|
145 |
+
)
|
146 |
+
(out_proj): ParametrizedLinear(
|
147 |
+
in_features=1024, out_features=1024, bias=True
|
148 |
+
(parametrizations): ModuleDict(
|
149 |
+
(weight): ParametrizationList(
|
150 |
+
(0): LoRAParametrization()
|
151 |
+
)
|
152 |
+
)
|
153 |
+
)
|
154 |
+
)
|
155 |
+
(dropout1): Dropout(p=0.1, inplace=False)
|
156 |
+
(drop_path1): StochasticDepth(p=0.0, mode=row)
|
157 |
+
(norm1): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)
|
158 |
+
(mlp): Mlp(
|
159 |
+
(fc1): ParametrizedLinear(
|
160 |
+
in_features=1024, out_features=4096, bias=True
|
161 |
+
(parametrizations): ModuleDict(
|
162 |
+
(weight): ParametrizationList(
|
163 |
+
(0): LoRAParametrization()
|
164 |
+
)
|
165 |
+
)
|
166 |
+
)
|
167 |
+
(fc2): ParametrizedLinear(
|
168 |
+
in_features=4096, out_features=1024, bias=True
|
169 |
+
(parametrizations): ModuleDict(
|
170 |
+
(weight): ParametrizationList(
|
171 |
+
(0): LoRAParametrization()
|
172 |
+
)
|
173 |
+
)
|
174 |
+
)
|
175 |
+
)
|
176 |
+
(dropout2): Dropout(p=0.1, inplace=False)
|
177 |
+
(drop_path2): StochasticDepth(p=0.0, mode=row)
|
178 |
+
(norm2): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)
|
179 |
+
)
|
180 |
+
)
|
181 |
+
)
|
182 |
+
(pooler): XLMRobertaPooler(
|
183 |
+
(dense): ParametrizedLinear(
|
184 |
+
in_features=1024, out_features=1024, bias=True
|
185 |
+
(parametrizations): ModuleDict(
|
186 |
+
(weight): ParametrizationList(
|
187 |
+
(0): LoRAParametrization()
|
188 |
+
)
|
189 |
+
)
|
190 |
+
)
|
191 |
+
(activation): Tanh()
|
192 |
+
)
|
193 |
+
)
|
194 |
+
)
|
195 |
+
)
|
196 |
+
(pooler): Pooling({'word_embedding_dimension': 1024, 'pooling_mode_cls_token': False, 'pooling_mode_mean_tokens': True, 'pooling_mode_max_tokens': False, 'pooling_mode_mean_sqrt_len_tokens': False, 'pooling_mode_weightedmean_tokens': False, 'pooling_mode_lasttoken': False, 'include_prompt': True})
|
197 |
+
(normalizer): Normalize()
|
198 |
+
)
|
199 |
+
```
|
200 |
+
|
201 |
+
## Usage
|
202 |
+
|
203 |
+
### Direct Usage (Sentence Transformers)
|
204 |
+
|
205 |
+
First install the Sentence Transformers library:
|
206 |
+
|
207 |
+
```bash
|
208 |
+
pip install -U sentence-transformers
|
209 |
+
```
|
210 |
+
|
211 |
+
Then you can load this model and run inference.
|
212 |
+
```python
|
213 |
+
from sentence_transformers import SentenceTransformer
|
214 |
+
|
215 |
+
# Download from the 🤗 Hub
|
216 |
+
model = SentenceTransformer("ELVISIO/jina_embeddings_v3_finetuned_online_contrastive_imdb")
|
217 |
+
# Run inference
|
218 |
+
sentences = [
|
219 |
+
"Saw this on cable back in the early 90's and loved it. Never saw it again until it showed up on cable again recently. Still find it a great Vietnam movie. Not sure why its not higher rated. I found everything about this film compelling. As a vet (not from Vietnam) I can relate to the situations brought by both Harris and De Niro. I can only imagine this film being more poignant now with our situation in Iraq. I wish this would be offered on cable more often for people to see. The human toll on our soldiers isn't left on the battlefield. Its brought home for the rest of there lives. And this film is one of many that brings that home in a very hard way. Excellent film.",
|
220 |
+
'positive positive positive positive',
|
221 |
+
'negative negative negative negative',
|
222 |
+
]
|
223 |
+
embeddings = model.encode(sentences)
|
224 |
+
print(embeddings.shape)
|
225 |
+
# [3, 1024]
|
226 |
+
|
227 |
+
# Get the similarity scores for the embeddings
|
228 |
+
similarities = model.similarity(embeddings, embeddings)
|
229 |
+
print(similarities.shape)
|
230 |
+
# [3, 3]
|
231 |
+
```
|
232 |
+
|
233 |
+
<!--
|
234 |
+
### Direct Usage (Transformers)
|
235 |
+
|
236 |
+
<details><summary>Click to see the direct usage in Transformers</summary>
|
237 |
+
|
238 |
+
</details>
|
239 |
+
-->
|
240 |
+
|
241 |
+
<!--
|
242 |
+
### Downstream Usage (Sentence Transformers)
|
243 |
+
|
244 |
+
You can finetune this model on your own dataset.
|
245 |
+
|
246 |
+
<details><summary>Click to expand</summary>
|
247 |
+
|
248 |
+
</details>
|
249 |
+
-->
|
250 |
+
|
251 |
+
<!--
|
252 |
+
### Out-of-Scope Use
|
253 |
+
|
254 |
+
*List how the model may foreseeably be misused and address what users ought not to do with the model.*
|
255 |
+
-->
|
256 |
+
|
257 |
+
<!--
|
258 |
+
## Bias, Risks and Limitations
|
259 |
+
|
260 |
+
*What are the known or foreseeable issues stemming from this model? You could also flag here known failure cases or weaknesses of the model.*
|
261 |
+
-->
|
262 |
+
|
263 |
+
<!--
|
264 |
+
### Recommendations
|
265 |
+
|
266 |
+
*What are recommendations with respect to the foreseeable issues? For example, filtering explicit content.*
|
267 |
+
-->
|
268 |
+
|
269 |
+
## Training Details
|
270 |
+
|
271 |
+
### Training Dataset
|
272 |
+
|
273 |
+
#### Unnamed Dataset
|
274 |
+
|
275 |
+
|
276 |
+
* Size: 16,000 training samples
|
277 |
+
* Columns: <code>sentence1</code>, <code>sentence2</code>, and <code>label</code>
|
278 |
+
* Approximate statistics based on the first 1000 samples:
|
279 |
+
| | sentence1 | sentence2 | label |
|
280 |
+
|:--------|:-------------------------------------------------------------------------------------|:-------------------------------------------------------------------------------|:--------------------------------------------------------------|
|
281 |
+
| type | string | string | float |
|
282 |
+
| details | <ul><li>min: 39 tokens</li><li>mean: 173.59 tokens</li><li>max: 291 tokens</li></ul> | <ul><li>min: 6 tokens</li><li>mean: 6.0 tokens</li><li>max: 6 tokens</li></ul> | <ul><li>min: 0.0</li><li>mean: 0.5</li><li>max: 1.0</li></ul> |
|
283 |
+
* Samples:
|
284 |
+
| sentence1 | sentence2 | label |
|
285 |
+
|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:-------------------------------------------------|:-----------------|
|
286 |
+
| <code>There are two kinds of 1950s musicals. First you have the glossy MGM productions with big names and great music. And then you have the minor league with a less famous cast, less famous music and second rate directors. 'The Girl Can't Help It' belongs to the latter category. Neither Tom Ewell or Edmond O'Brien became famous and Jayne Mansfield was famous for her... well, never mind. Seems like every decade has its share of Bo Dereks or Pamela Andersons. The plot itself is thin as a razorblade and one can't help suspect that it is mostly an attempt to sell records for Fats Domino, Little Richard or others of the 1950s rock acts that appear in the movie. If that music appeals to you this is worth watching. If not, don't bother.</code> | <code>negative negative negative negative</code> | <code>1.0</code> |
|
287 |
+
| <code>There are two kinds of 1950s musicals. First you have the glossy MGM productions with big names and great music. And then you have the minor league with a less famous cast, less famous music and second rate directors. 'The Girl Can't Help It' belongs to the latter category. Neither Tom Ewell or Edmond O'Brien became famous and Jayne Mansfield was famous for her... well, never mind. Seems like every decade has its share of Bo Dereks or Pamela Andersons. The plot itself is thin as a razorblade and one can't help suspect that it is mostly an attempt to sell records for Fats Domino, Little Richard or others of the 1950s rock acts that appear in the movie. If that music appeals to you this is worth watching. If not, don't bother.</code> | <code>positive positive positive positive</code> | <code>0.0</code> |
|
288 |
+
| <code>Thankfully as a student I have been able to watch "Diagnosis Murder" for a number of years now. It is basically about a doctor who solves murders with the help of his LAPD son, a young doctor and a pathologist. DM provided 8 seasons of exceptional entertainment. What made it different from the many other cop shows and worth watching many times over was its cast and quality of writing. The main cast gave good performances and Dick Van Dyke's entertainer roots shone through with the use of magic, dance and humor. The best aspects of DM was the fast pace, witty scripts and of course the toe tapping score. Sadly it has been unfairly compared to "Murder, She Wrote". DM is far superior boasting more difficult mysteries to solve and more variety. Now it is gone TV is a worse place. Gone are the days of feelgood, family friendly cop shows. Now there is just depressing 'gritty' ones.</code> | <code>positive positive positive positive</code> | <code>1.0</code> |
|
289 |
+
* Loss: [<code>OnlineContrastiveLoss</code>](https://sbert.net/docs/package_reference/sentence_transformer/losses.html#onlinecontrastiveloss)
|
290 |
+
|
291 |
+
### Training Hyperparameters
|
292 |
+
#### Non-Default Hyperparameters
|
293 |
+
|
294 |
+
- `per_device_train_batch_size`: 64
|
295 |
+
- `per_device_eval_batch_size`: 64
|
296 |
+
|
297 |
+
#### All Hyperparameters
|
298 |
+
<details><summary>Click to expand</summary>
|
299 |
+
|
300 |
+
- `overwrite_output_dir`: False
|
301 |
+
- `do_predict`: False
|
302 |
+
- `eval_strategy`: no
|
303 |
+
- `prediction_loss_only`: True
|
304 |
+
- `per_device_train_batch_size`: 64
|
305 |
+
- `per_device_eval_batch_size`: 64
|
306 |
+
- `per_gpu_train_batch_size`: None
|
307 |
+
- `per_gpu_eval_batch_size`: None
|
308 |
+
- `gradient_accumulation_steps`: 1
|
309 |
+
- `eval_accumulation_steps`: None
|
310 |
+
- `torch_empty_cache_steps`: None
|
311 |
+
- `learning_rate`: 5e-05
|
312 |
+
- `weight_decay`: 0.0
|
313 |
+
- `adam_beta1`: 0.9
|
314 |
+
- `adam_beta2`: 0.999
|
315 |
+
- `adam_epsilon`: 1e-08
|
316 |
+
- `max_grad_norm`: 1.0
|
317 |
+
- `num_train_epochs`: 3.0
|
318 |
+
- `max_steps`: -1
|
319 |
+
- `lr_scheduler_type`: linear
|
320 |
+
- `lr_scheduler_kwargs`: {}
|
321 |
+
- `warmup_ratio`: 0.0
|
322 |
+
- `warmup_steps`: 0
|
323 |
+
- `log_level`: passive
|
324 |
+
- `log_level_replica`: warning
|
325 |
+
- `log_on_each_node`: True
|
326 |
+
- `logging_nan_inf_filter`: True
|
327 |
+
- `save_safetensors`: True
|
328 |
+
- `save_on_each_node`: False
|
329 |
+
- `save_only_model`: False
|
330 |
+
- `restore_callback_states_from_checkpoint`: False
|
331 |
+
- `no_cuda`: False
|
332 |
+
- `use_cpu`: False
|
333 |
+
- `use_mps_device`: False
|
334 |
+
- `seed`: 42
|
335 |
+
- `data_seed`: None
|
336 |
+
- `jit_mode_eval`: False
|
337 |
+
- `use_ipex`: False
|
338 |
+
- `bf16`: False
|
339 |
+
- `fp16`: False
|
340 |
+
- `fp16_opt_level`: O1
|
341 |
+
- `half_precision_backend`: auto
|
342 |
+
- `bf16_full_eval`: False
|
343 |
+
- `fp16_full_eval`: False
|
344 |
+
- `tf32`: None
|
345 |
+
- `local_rank`: 0
|
346 |
+
- `ddp_backend`: None
|
347 |
+
- `tpu_num_cores`: None
|
348 |
+
- `tpu_metrics_debug`: False
|
349 |
+
- `debug`: []
|
350 |
+
- `dataloader_drop_last`: False
|
351 |
+
- `dataloader_num_workers`: 0
|
352 |
+
- `dataloader_prefetch_factor`: None
|
353 |
+
- `past_index`: -1
|
354 |
+
- `disable_tqdm`: False
|
355 |
+
- `remove_unused_columns`: True
|
356 |
+
- `label_names`: None
|
357 |
+
- `load_best_model_at_end`: False
|
358 |
+
- `ignore_data_skip`: False
|
359 |
+
- `fsdp`: []
|
360 |
+
- `fsdp_min_num_params`: 0
|
361 |
+
- `fsdp_config`: {'min_num_params': 0, 'xla': False, 'xla_fsdp_v2': False, 'xla_fsdp_grad_ckpt': False}
|
362 |
+
- `fsdp_transformer_layer_cls_to_wrap`: None
|
363 |
+
- `accelerator_config`: {'split_batches': False, 'dispatch_batches': None, 'even_batches': True, 'use_seedable_sampler': True, 'non_blocking': False, 'gradient_accumulation_kwargs': None}
|
364 |
+
- `deepspeed`: None
|
365 |
+
- `label_smoothing_factor`: 0.0
|
366 |
+
- `optim`: adamw_torch
|
367 |
+
- `optim_args`: None
|
368 |
+
- `adafactor`: False
|
369 |
+
- `group_by_length`: False
|
370 |
+
- `length_column_name`: length
|
371 |
+
- `ddp_find_unused_parameters`: None
|
372 |
+
- `ddp_bucket_cap_mb`: None
|
373 |
+
- `ddp_broadcast_buffers`: False
|
374 |
+
- `dataloader_pin_memory`: True
|
375 |
+
- `dataloader_persistent_workers`: False
|
376 |
+
- `skip_memory_metrics`: True
|
377 |
+
- `use_legacy_prediction_loop`: False
|
378 |
+
- `push_to_hub`: False
|
379 |
+
- `resume_from_checkpoint`: None
|
380 |
+
- `hub_model_id`: None
|
381 |
+
- `hub_strategy`: every_save
|
382 |
+
- `hub_private_repo`: False
|
383 |
+
- `hub_always_push`: False
|
384 |
+
- `gradient_checkpointing`: False
|
385 |
+
- `gradient_checkpointing_kwargs`: None
|
386 |
+
- `include_inputs_for_metrics`: False
|
387 |
+
- `eval_do_concat_batches`: True
|
388 |
+
- `fp16_backend`: auto
|
389 |
+
- `push_to_hub_model_id`: None
|
390 |
+
- `push_to_hub_organization`: None
|
391 |
+
- `mp_parameters`:
|
392 |
+
- `auto_find_batch_size`: False
|
393 |
+
- `full_determinism`: False
|
394 |
+
- `torchdynamo`: None
|
395 |
+
- `ray_scope`: last
|
396 |
+
- `ddp_timeout`: 1800
|
397 |
+
- `torch_compile`: False
|
398 |
+
- `torch_compile_backend`: None
|
399 |
+
- `torch_compile_mode`: None
|
400 |
+
- `dispatch_batches`: None
|
401 |
+
- `split_batches`: None
|
402 |
+
- `include_tokens_per_second`: False
|
403 |
+
- `include_num_input_tokens_seen`: False
|
404 |
+
- `neftune_noise_alpha`: None
|
405 |
+
- `optim_target_modules`: None
|
406 |
+
- `batch_eval_metrics`: False
|
407 |
+
- `eval_on_start`: False
|
408 |
+
- `use_liger_kernel`: False
|
409 |
+
- `eval_use_gather_object`: False
|
410 |
+
- `batch_sampler`: batch_sampler
|
411 |
+
- `multi_dataset_batch_sampler`: proportional
|
412 |
+
|
413 |
+
</details>
|
414 |
+
|
415 |
+
### Training Logs
|
416 |
+
| Epoch | Step | Training Loss |
|
417 |
+
|:-----:|:----:|:-------------:|
|
418 |
+
| 2.0 | 500 | 0.9466 |
|
419 |
+
|
420 |
+
|
421 |
+
### Framework Versions
|
422 |
+
- Python: 3.10.12
|
423 |
+
- Sentence Transformers: 3.1.1
|
424 |
+
- Transformers: 4.45.2
|
425 |
+
- PyTorch: 2.5.1+cu121
|
426 |
+
- Accelerate: 1.1.1
|
427 |
+
- Datasets: 2.21.0
|
428 |
+
- Tokenizers: 0.20.3
|
429 |
+
|
430 |
+
## Citation
|
431 |
+
|
432 |
+
### BibTeX
|
433 |
+
|
434 |
+
#### Sentence Transformers
|
435 |
+
```bibtex
|
436 |
+
@inproceedings{reimers-2019-sentence-bert,
|
437 |
+
title = "Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks",
|
438 |
+
author = "Reimers, Nils and Gurevych, Iryna",
|
439 |
+
booktitle = "Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing",
|
440 |
+
month = "11",
|
441 |
+
year = "2019",
|
442 |
+
publisher = "Association for Computational Linguistics",
|
443 |
+
url = "https://arxiv.org/abs/1908.10084",
|
444 |
+
}
|
445 |
+
```
|
446 |
+
|
447 |
+
<!--
|
448 |
+
## Glossary
|
449 |
+
|
450 |
+
*Clearly define terms in order to be accessible across audiences.*
|
451 |
+
-->
|
452 |
+
|
453 |
+
<!--
|
454 |
+
## Model Card Authors
|
455 |
+
|
456 |
+
*Lists the people who create the model card, providing recognition and accountability for the detailed work that goes into its construction.*
|
457 |
+
-->
|
458 |
+
|
459 |
+
<!--
|
460 |
+
## Model Card Contact
|
461 |
+
|
462 |
+
*Provides a way for people who have updates to the Model Card, suggestions, or questions, to contact the Model Card authors.*
|
463 |
+
-->
|
config.json
ADDED
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_name_or_path": "jinaai/jina-embeddings-v3",
|
3 |
+
"architectures": [
|
4 |
+
"XLMRobertaLoRA"
|
5 |
+
],
|
6 |
+
"attention_probs_dropout_prob": 0.1,
|
7 |
+
"auto_map": {
|
8 |
+
"AutoConfig": "jinaai/xlm-roberta-flash-implementation--configuration_xlm_roberta.XLMRobertaFlashConfig",
|
9 |
+
"AutoModel": "jinaai/xlm-roberta-flash-implementation--modeling_lora.XLMRobertaLoRA",
|
10 |
+
"AutoModelForMaskedLM": "jinaai/xlm-roberta-flash-implementation--modeling_xlm_roberta.XLMRobertaForMaskedLM",
|
11 |
+
"AutoModelForPreTraining": "jinaai/xlm-roberta-flash-implementation--modeling_xlm_roberta.XLMRobertaForPreTraining"
|
12 |
+
},
|
13 |
+
"bos_token_id": 0,
|
14 |
+
"classifier_dropout": null,
|
15 |
+
"emb_pooler": null,
|
16 |
+
"eos_token_id": 2,
|
17 |
+
"hidden_act": "gelu",
|
18 |
+
"hidden_dropout_prob": 0.1,
|
19 |
+
"hidden_size": 1024,
|
20 |
+
"initializer_range": 0.02,
|
21 |
+
"intermediate_size": 4096,
|
22 |
+
"layer_norm_eps": 1e-05,
|
23 |
+
"load_trained_adapters": true,
|
24 |
+
"lora_adaptations": [
|
25 |
+
"retrieval.query",
|
26 |
+
"retrieval.passage",
|
27 |
+
"separation",
|
28 |
+
"classification",
|
29 |
+
"text-matching"
|
30 |
+
],
|
31 |
+
"lora_alpha": 1,
|
32 |
+
"lora_dropout_p": 0.0,
|
33 |
+
"lora_main_params_trainable": false,
|
34 |
+
"lora_rank": 4,
|
35 |
+
"matryoshka_dimensions": [
|
36 |
+
32,
|
37 |
+
64,
|
38 |
+
128,
|
39 |
+
256,
|
40 |
+
512,
|
41 |
+
768,
|
42 |
+
1024
|
43 |
+
],
|
44 |
+
"max_position_embeddings": 8194,
|
45 |
+
"model_type": "xlm-roberta",
|
46 |
+
"num_attention_heads": 16,
|
47 |
+
"num_hidden_layers": 24,
|
48 |
+
"output_past": true,
|
49 |
+
"pad_token_id": 1,
|
50 |
+
"position_embedding_type": "rotary",
|
51 |
+
"rotary_emb_base": 20000.0,
|
52 |
+
"task_instructions": {
|
53 |
+
"classification": "",
|
54 |
+
"retrieval.passage": "Represent the document for retrieval: ",
|
55 |
+
"retrieval.query": "Represent the query for retrieving evidence documents: ",
|
56 |
+
"separation": "",
|
57 |
+
"text-matching": ""
|
58 |
+
},
|
59 |
+
"torch_dtype": "bfloat16",
|
60 |
+
"transformers_version": "4.45.2",
|
61 |
+
"truncate_dim": null,
|
62 |
+
"type_vocab_size": 1,
|
63 |
+
"use_cache": true,
|
64 |
+
"use_flash_attn": true,
|
65 |
+
"use_reentrant": false,
|
66 |
+
"vocab_size": 250002
|
67 |
+
}
|
config_sentence_transformers.json
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"__version__": {
|
3 |
+
"sentence_transformers": "3.1.1",
|
4 |
+
"transformers": "4.45.2",
|
5 |
+
"pytorch": "2.5.1+cu121"
|
6 |
+
},
|
7 |
+
"prompts": {
|
8 |
+
"retrieval.query": "Represent the query for retrieving evidence documents: ",
|
9 |
+
"retrieval.passage": "Represent the document for retrieval: ",
|
10 |
+
"separation": "",
|
11 |
+
"classification": "",
|
12 |
+
"text-matching": ""
|
13 |
+
},
|
14 |
+
"default_prompt_name": null,
|
15 |
+
"similarity_fn_name": "cosine"
|
16 |
+
}
|
custom_st.py
ADDED
@@ -0,0 +1,229 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
import logging
|
3 |
+
import os
|
4 |
+
from io import BytesIO
|
5 |
+
from typing import Any, Dict, List, Optional, Tuple, Union
|
6 |
+
|
7 |
+
import torch
|
8 |
+
from torch import nn
|
9 |
+
from transformers import AutoConfig, AutoModel, AutoTokenizer
|
10 |
+
|
11 |
+
logger = logging.getLogger(__name__)
|
12 |
+
|
13 |
+
|
14 |
+
class Transformer(nn.Module):
|
15 |
+
"""Huggingface AutoModel to generate token embeddings.
|
16 |
+
Loads the correct class, e.g. BERT / RoBERTa etc.
|
17 |
+
|
18 |
+
Args:
|
19 |
+
model_name_or_path: Huggingface models name
|
20 |
+
(https://huggingface.co/models)
|
21 |
+
max_seq_length: Truncate any inputs longer than max_seq_length
|
22 |
+
model_args: Keyword arguments passed to the Huggingface
|
23 |
+
Transformers model
|
24 |
+
tokenizer_args: Keyword arguments passed to the Huggingface
|
25 |
+
Transformers tokenizer
|
26 |
+
config_args: Keyword arguments passed to the Huggingface
|
27 |
+
Transformers config
|
28 |
+
cache_dir: Cache dir for Huggingface Transformers to store/load
|
29 |
+
models
|
30 |
+
do_lower_case: If true, lowercases the input (independent if the
|
31 |
+
model is cased or not)
|
32 |
+
tokenizer_name_or_path: Name or path of the tokenizer. When
|
33 |
+
None, then model_name_or_path is used
|
34 |
+
"""
|
35 |
+
|
36 |
+
save_in_root: bool = True
|
37 |
+
|
38 |
+
def __init__(
|
39 |
+
self,
|
40 |
+
model_name_or_path: str,
|
41 |
+
max_seq_length: int = None,
|
42 |
+
model_args: Dict[str, Any] = None,
|
43 |
+
tokenizer_args: Dict[str, Any] = None,
|
44 |
+
config_args: Dict[str, Any] = None,
|
45 |
+
cache_dir: str = None,
|
46 |
+
do_lower_case: bool = False,
|
47 |
+
tokenizer_name_or_path: str = None,
|
48 |
+
**kwargs,
|
49 |
+
) -> None:
|
50 |
+
super().__init__()
|
51 |
+
self.config_keys = ["max_seq_length", "do_lower_case"]
|
52 |
+
self.do_lower_case = do_lower_case
|
53 |
+
if model_args is None:
|
54 |
+
model_args = {}
|
55 |
+
if tokenizer_args is None:
|
56 |
+
tokenizer_args = {}
|
57 |
+
if config_args is None:
|
58 |
+
config_args = {}
|
59 |
+
|
60 |
+
if kwargs.get("backend", "torch") != "torch":
|
61 |
+
logger.warning(
|
62 |
+
f'"jinaai/jina-embeddings-v3" is currently not compatible with the {kwargs["backend"]} backend. '
|
63 |
+
'Continuing with the "torch" backend.'
|
64 |
+
)
|
65 |
+
|
66 |
+
self.config = AutoConfig.from_pretrained(model_name_or_path, **config_args, cache_dir=cache_dir)
|
67 |
+
|
68 |
+
self._lora_adaptations = self.config.lora_adaptations
|
69 |
+
if (
|
70 |
+
not isinstance(self._lora_adaptations, list)
|
71 |
+
or len(self._lora_adaptations) < 1
|
72 |
+
):
|
73 |
+
raise ValueError(
|
74 |
+
f"`lora_adaptations` must be a list and contain at least one element"
|
75 |
+
)
|
76 |
+
self._adaptation_map = {
|
77 |
+
name: idx for idx, name in enumerate(self._lora_adaptations)
|
78 |
+
}
|
79 |
+
|
80 |
+
self.default_task = model_args.pop('default_task', None)
|
81 |
+
|
82 |
+
self.auto_model = AutoModel.from_pretrained(model_name_or_path, config=self.config, cache_dir=cache_dir, **model_args)
|
83 |
+
|
84 |
+
if max_seq_length is not None and "model_max_length" not in tokenizer_args:
|
85 |
+
tokenizer_args["model_max_length"] = max_seq_length
|
86 |
+
self.tokenizer = AutoTokenizer.from_pretrained(
|
87 |
+
tokenizer_name_or_path if tokenizer_name_or_path is not None else model_name_or_path,
|
88 |
+
cache_dir=cache_dir,
|
89 |
+
**tokenizer_args,
|
90 |
+
)
|
91 |
+
|
92 |
+
# No max_seq_length set. Try to infer from model
|
93 |
+
if max_seq_length is None:
|
94 |
+
if (
|
95 |
+
hasattr(self.auto_model, "config")
|
96 |
+
and hasattr(self.auto_model.config, "max_position_embeddings")
|
97 |
+
and hasattr(self.tokenizer, "model_max_length")
|
98 |
+
):
|
99 |
+
max_seq_length = min(self.auto_model.config.max_position_embeddings, self.tokenizer.model_max_length)
|
100 |
+
|
101 |
+
self.max_seq_length = max_seq_length
|
102 |
+
|
103 |
+
if tokenizer_name_or_path is not None:
|
104 |
+
self.auto_model.config.tokenizer_class = self.tokenizer.__class__.__name__
|
105 |
+
|
106 |
+
|
107 |
+
@property
|
108 |
+
def default_task(self):
|
109 |
+
return self._default_task
|
110 |
+
|
111 |
+
@default_task.setter
|
112 |
+
def default_task(self, task: Union[None, str]):
|
113 |
+
self._validate_task(task)
|
114 |
+
self._default_task = task
|
115 |
+
|
116 |
+
|
117 |
+
def _validate_task(self, task: str):
|
118 |
+
if task and task not in self._lora_adaptations:
|
119 |
+
raise ValueError(
|
120 |
+
f"Unsupported task '{task}'. "
|
121 |
+
f"Supported tasks are: {', '.join(self.config.lora_adaptations)}. "
|
122 |
+
f"Alternatively, don't pass the `task` argument to disable LoRA."
|
123 |
+
)
|
124 |
+
|
125 |
+
def forward(
|
126 |
+
self, features: Dict[str, torch.Tensor], task: Optional[str] = None
|
127 |
+
) -> Dict[str, torch.Tensor]:
|
128 |
+
"""Returns token_embeddings, cls_token"""
|
129 |
+
self._validate_task(task)
|
130 |
+
task = task or self.default_task
|
131 |
+
adapter_mask = None
|
132 |
+
if task:
|
133 |
+
task_id = self._adaptation_map[task]
|
134 |
+
num_examples = features['input_ids'].size(0)
|
135 |
+
adapter_mask = torch.full(
|
136 |
+
(num_examples,), task_id, dtype=torch.int32, device=features['input_ids'].device
|
137 |
+
)
|
138 |
+
|
139 |
+
lora_arguments = (
|
140 |
+
{"adapter_mask": adapter_mask} if adapter_mask is not None else {}
|
141 |
+
)
|
142 |
+
features.pop('prompt_length', None)
|
143 |
+
output_states = self.auto_model.forward(**features, **lora_arguments, return_dict=False)
|
144 |
+
output_tokens = output_states[0]
|
145 |
+
features.update({"token_embeddings": output_tokens, "attention_mask": features["attention_mask"]})
|
146 |
+
return features
|
147 |
+
|
148 |
+
def get_word_embedding_dimension(self) -> int:
|
149 |
+
return self.auto_model.config.hidden_size
|
150 |
+
|
151 |
+
def tokenize(
|
152 |
+
self,
|
153 |
+
texts: Union[List[str], List[dict], List[Tuple[str, str]]],
|
154 |
+
padding: Union[str, bool] = True
|
155 |
+
) -> Dict[str, torch.Tensor]:
|
156 |
+
"""Tokenizes a text and maps tokens to token-ids"""
|
157 |
+
output = {}
|
158 |
+
if isinstance(texts[0], str):
|
159 |
+
to_tokenize = [texts]
|
160 |
+
elif isinstance(texts[0], dict):
|
161 |
+
to_tokenize = []
|
162 |
+
output["text_keys"] = []
|
163 |
+
for lookup in texts:
|
164 |
+
text_key, text = next(iter(lookup.items()))
|
165 |
+
to_tokenize.append(text)
|
166 |
+
output["text_keys"].append(text_key)
|
167 |
+
to_tokenize = [to_tokenize]
|
168 |
+
else:
|
169 |
+
batch1, batch2 = [], []
|
170 |
+
for text_tuple in texts:
|
171 |
+
batch1.append(text_tuple[0])
|
172 |
+
batch2.append(text_tuple[1])
|
173 |
+
to_tokenize = [batch1, batch2]
|
174 |
+
|
175 |
+
# strip
|
176 |
+
to_tokenize = [[str(s).strip() for s in col] for col in to_tokenize]
|
177 |
+
|
178 |
+
# Lowercase
|
179 |
+
if self.do_lower_case:
|
180 |
+
to_tokenize = [[s.lower() for s in col] for col in to_tokenize]
|
181 |
+
|
182 |
+
output.update(
|
183 |
+
self.tokenizer(
|
184 |
+
*to_tokenize,
|
185 |
+
padding=padding,
|
186 |
+
truncation="longest_first",
|
187 |
+
return_tensors="pt",
|
188 |
+
max_length=self.max_seq_length,
|
189 |
+
)
|
190 |
+
)
|
191 |
+
return output
|
192 |
+
|
193 |
+
def get_config_dict(self) -> Dict[str, Any]:
|
194 |
+
return {key: self.__dict__[key] for key in self.config_keys}
|
195 |
+
|
196 |
+
def save(self, output_path: str, safe_serialization: bool = True) -> None:
|
197 |
+
self.auto_model.save_pretrained(output_path, safe_serialization=safe_serialization)
|
198 |
+
self.tokenizer.save_pretrained(output_path)
|
199 |
+
|
200 |
+
with open(os.path.join(output_path, "sentence_bert_config.json"), "w") as fOut:
|
201 |
+
json.dump(self.get_config_dict(), fOut, indent=2)
|
202 |
+
|
203 |
+
|
204 |
+
@classmethod
|
205 |
+
def load(cls, input_path: str) -> "Transformer":
|
206 |
+
# Old classes used other config names than 'sentence_bert_config.json'
|
207 |
+
for config_name in [
|
208 |
+
"sentence_bert_config.json",
|
209 |
+
"sentence_roberta_config.json",
|
210 |
+
"sentence_distilbert_config.json",
|
211 |
+
"sentence_camembert_config.json",
|
212 |
+
"sentence_albert_config.json",
|
213 |
+
"sentence_xlm-roberta_config.json",
|
214 |
+
"sentence_xlnet_config.json",
|
215 |
+
]:
|
216 |
+
sbert_config_path = os.path.join(input_path, config_name)
|
217 |
+
if os.path.exists(sbert_config_path):
|
218 |
+
break
|
219 |
+
|
220 |
+
with open(sbert_config_path) as fIn:
|
221 |
+
config = json.load(fIn)
|
222 |
+
# Don't allow configs to set trust_remote_code
|
223 |
+
if "model_args" in config and "trust_remote_code" in config["model_args"]:
|
224 |
+
config["model_args"].pop("trust_remote_code")
|
225 |
+
if "tokenizer_args" in config and "trust_remote_code" in config["tokenizer_args"]:
|
226 |
+
config["tokenizer_args"].pop("trust_remote_code")
|
227 |
+
if "config_args" in config and "trust_remote_code" in config["config_args"]:
|
228 |
+
config["config_args"].pop("trust_remote_code")
|
229 |
+
return cls(model_name_or_path=input_path, **config)
|
model.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f7b468d9b78995ae0e85410e421b2c00e24cb6028f15dbde2dd36c1e8c214ae9
|
3 |
+
size 1144685320
|
modules.json
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[
|
2 |
+
{
|
3 |
+
"idx": 0,
|
4 |
+
"name": "transformer",
|
5 |
+
"path": "",
|
6 |
+
"type": "custom_st.Transformer"
|
7 |
+
},
|
8 |
+
{
|
9 |
+
"idx": 1,
|
10 |
+
"name": "pooler",
|
11 |
+
"path": "1_Pooling",
|
12 |
+
"type": "sentence_transformers.models.Pooling"
|
13 |
+
},
|
14 |
+
{
|
15 |
+
"idx": 2,
|
16 |
+
"name": "normalizer",
|
17 |
+
"path": "2_Normalize",
|
18 |
+
"type": "sentence_transformers.models.Normalize"
|
19 |
+
}
|
20 |
+
]
|
sentence_bert_config.json
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"max_seq_length": 8194,
|
3 |
+
"do_lower_case": false
|
4 |
+
}
|
special_tokens_map.json
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"bos_token": {
|
3 |
+
"content": "<s>",
|
4 |
+
"lstrip": false,
|
5 |
+
"normalized": false,
|
6 |
+
"rstrip": false,
|
7 |
+
"single_word": false
|
8 |
+
},
|
9 |
+
"cls_token": {
|
10 |
+
"content": "<s>",
|
11 |
+
"lstrip": false,
|
12 |
+
"normalized": false,
|
13 |
+
"rstrip": false,
|
14 |
+
"single_word": false
|
15 |
+
},
|
16 |
+
"eos_token": {
|
17 |
+
"content": "</s>",
|
18 |
+
"lstrip": false,
|
19 |
+
"normalized": false,
|
20 |
+
"rstrip": false,
|
21 |
+
"single_word": false
|
22 |
+
},
|
23 |
+
"mask_token": {
|
24 |
+
"content": "<mask>",
|
25 |
+
"lstrip": true,
|
26 |
+
"normalized": false,
|
27 |
+
"rstrip": false,
|
28 |
+
"single_word": false
|
29 |
+
},
|
30 |
+
"pad_token": {
|
31 |
+
"content": "<pad>",
|
32 |
+
"lstrip": false,
|
33 |
+
"normalized": false,
|
34 |
+
"rstrip": false,
|
35 |
+
"single_word": false
|
36 |
+
},
|
37 |
+
"sep_token": {
|
38 |
+
"content": "</s>",
|
39 |
+
"lstrip": false,
|
40 |
+
"normalized": false,
|
41 |
+
"rstrip": false,
|
42 |
+
"single_word": false
|
43 |
+
},
|
44 |
+
"unk_token": {
|
45 |
+
"content": "<unk>",
|
46 |
+
"lstrip": false,
|
47 |
+
"normalized": false,
|
48 |
+
"rstrip": false,
|
49 |
+
"single_word": false
|
50 |
+
}
|
51 |
+
}
|
tokenizer.json
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:3e19cd8c08f528b481e909f73dbd1fd62b1e8b1117579ba205e477801237f9e0
|
3 |
+
size 17082988
|
tokenizer_config.json
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"added_tokens_decoder": {
|
3 |
+
"0": {
|
4 |
+
"content": "<s>",
|
5 |
+
"lstrip": false,
|
6 |
+
"normalized": false,
|
7 |
+
"rstrip": false,
|
8 |
+
"single_word": false,
|
9 |
+
"special": true
|
10 |
+
},
|
11 |
+
"1": {
|
12 |
+
"content": "<pad>",
|
13 |
+
"lstrip": false,
|
14 |
+
"normalized": false,
|
15 |
+
"rstrip": false,
|
16 |
+
"single_word": false,
|
17 |
+
"special": true
|
18 |
+
},
|
19 |
+
"2": {
|
20 |
+
"content": "</s>",
|
21 |
+
"lstrip": false,
|
22 |
+
"normalized": false,
|
23 |
+
"rstrip": false,
|
24 |
+
"single_word": false,
|
25 |
+
"special": true
|
26 |
+
},
|
27 |
+
"3": {
|
28 |
+
"content": "<unk>",
|
29 |
+
"lstrip": false,
|
30 |
+
"normalized": false,
|
31 |
+
"rstrip": false,
|
32 |
+
"single_word": false,
|
33 |
+
"special": true
|
34 |
+
},
|
35 |
+
"250001": {
|
36 |
+
"content": "<mask>",
|
37 |
+
"lstrip": true,
|
38 |
+
"normalized": false,
|
39 |
+
"rstrip": false,
|
40 |
+
"single_word": false,
|
41 |
+
"special": true
|
42 |
+
}
|
43 |
+
},
|
44 |
+
"bos_token": "<s>",
|
45 |
+
"clean_up_tokenization_spaces": true,
|
46 |
+
"cls_token": "<s>",
|
47 |
+
"eos_token": "</s>",
|
48 |
+
"mask_token": "<mask>",
|
49 |
+
"model_max_length": 8194,
|
50 |
+
"pad_token": "<pad>",
|
51 |
+
"sep_token": "</s>",
|
52 |
+
"tokenizer_class": "XLMRobertaTokenizer",
|
53 |
+
"unk_token": "<unk>"
|
54 |
+
}
|