tomaarsen HF Staff commited on
Commit
50583fa
·
verified ·
1 Parent(s): 48f6997

Integrate with Sentence Transformers via MultiVectorEncoder

Browse files
1_Dense/config.json ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "in_features": 2048,
3
+ "out_features": 128,
4
+ "bias": true,
5
+ "activation_function": "torch.nn.modules.linear.Identity",
6
+ "module_input_name": "token_embeddings",
7
+ "module_output_name": "token_embeddings"
8
+ }
1_Dense/model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:463e9e5cfa139168184f1b419fd83ad5e3e3375780d2d9b8089fb96437800c8f
3
+ size 1049248
2_Normalize/config.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {
2
+ "module_input_name": "token_embeddings",
3
+ "module_output_name": "token_embeddings"
4
+ }
3_MultiVectorMask/config.json ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ {
2
+ "skiplist_words": [],
3
+ "skiplist_tasks": [],
4
+ "keep_only_token_ids": null
5
+ }
README.md CHANGED
@@ -18,6 +18,7 @@ tags:
18
  - qwen3-vl
19
  - mteb
20
  - vidore
 
21
  base_model: Qwen/Qwen3-VL-2B
22
  pipeline_tag: image-text-to-text
23
  datasets:
@@ -194,6 +195,45 @@ Traditional OCR-based retrieval **loses layout, tables, and visual context**. Ou
194
 
195
  ## Installation & Usage
196
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
197
  > ⚠️ **Important**: Install our package first before loading the model:
198
 
199
  ```bash
 
18
  - qwen3-vl
19
  - mteb
20
  - vidore
21
+ - sentence-transformers
22
  base_model: Qwen/Qwen3-VL-2B
23
  pipeline_tag: image-text-to-text
24
  datasets:
 
195
 
196
  ## Installation & Usage
197
 
198
+ ### Sentence Transformers
199
+
200
+ This model can be used with [Sentence Transformers](https://www.sbert.net/) as a multi-vector (ColBERT-style late interaction) retriever via the `MultiVectorEncoder`:
201
+
202
+ ```bash
203
+ pip install "sentence-transformers[image]>=6.0.0"
204
+ ```
205
+
206
+ ```python
207
+ from sentence_transformers import MultiVectorEncoder
208
+
209
+ model = MultiVectorEncoder(
210
+ "VAGOsolutions/SauerkrautLM-ColQwen3-2b-v0.1",
211
+ model_kwargs={"dtype": "bfloat16"},
212
+ )
213
+
214
+ queries = [
215
+ "What is the variable represented on the y-axis of the graph?",
216
+ "Total outlay is maximum in which year?",
217
+ ]
218
+ images = [
219
+ "https://huggingface.co/datasets/sentence-transformers/example-documents/resolve/main/doc1.jpg",
220
+ "https://huggingface.co/datasets/sentence-transformers/example-documents/resolve/main/doc2.jpg",
221
+ ]
222
+
223
+ query_embeddings = model.encode_query(queries)
224
+ image_embeddings = model.encode_document(images)
225
+ print(query_embeddings[0].shape, image_embeddings[0].shape)
226
+ # torch.Size([25, 128]) torch.Size([1251, 128])
227
+
228
+ # Diagonal should have higher scores
229
+ scores = model.similarity(query_embeddings, image_embeddings)
230
+ print(scores)
231
+ # tensor([[15.1758, 9.4717],
232
+ # [ 4.1470, 14.3262]], device='cuda:0')
233
+ ```
234
+
235
+ ### SauerkrautLM ColPali
236
+
237
  > ⚠️ **Important**: Install our package first before loading the model:
238
 
239
  ```bash
additional_chat_templates/sentence_transformers.jinja ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {%- for message in messages -%}
2
+ {%- set ns = namespace(text='') -%}
3
+ {%- if message['content'] is string -%}
4
+ {%- set ns.text = message['content'] -%}
5
+ {%- else -%}
6
+ {%- for item in message['content'] -%}
7
+ {%- if 'text' in item -%}
8
+ {%- set ns.text = ns.text + item.text -%}
9
+ {%- endif -%}
10
+ {%- endfor -%}
11
+ {%- endif -%}
12
+ {%- if task is defined and task == 'query' -%}
13
+ {{- 'Query: ' + ns.text + '<|endoftext|>' * 10 -}}
14
+ {%- else -%}
15
+ {{- '<|im_start|>user\n<|vision_start|><|image_pad|><|vision_end|>Describe the image.<|im_end|><|endoftext|>' -}}
16
+ {%- endif -%}
17
+ {%- endfor -%}
config_sentence_transformers.json ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "model_type": "MultiVectorEncoder",
3
+ "similarity_fn_name": "maxsim",
4
+ "prompts": {},
5
+ "default_prompt_name": null,
6
+ "__version__": {
7
+ "sentence_transformers": "6.0.0"
8
+ }
9
+ }
modules.json ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "idx": 0,
4
+ "name": "0",
5
+ "path": "",
6
+ "type": "sentence_transformers.base.modules.transformer.Transformer"
7
+ },
8
+ {
9
+ "idx": 1,
10
+ "name": "1",
11
+ "path": "1_Dense",
12
+ "type": "sentence_transformers.base.modules.dense.Dense"
13
+ },
14
+ {
15
+ "idx": 2,
16
+ "name": "2",
17
+ "path": "2_Normalize",
18
+ "type": "sentence_transformers.base.modules.normalize.Normalize"
19
+ },
20
+ {
21
+ "idx": 3,
22
+ "name": "3",
23
+ "path": "3_MultiVectorMask",
24
+ "type": "sentence_transformers.multi_vector_encoder.modules.multi_vector_mask.MultiVectorMask"
25
+ }
26
+ ]
processor_config.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ {
2
+ "processor_class": "Qwen3VLProcessor"
3
+ }
sentence_bert_config.json ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "transformer_task": "feature-extraction",
3
+ "modality_config": {
4
+ "text": {
5
+ "method": "forward",
6
+ "method_output_name": "last_hidden_state"
7
+ },
8
+ "image": {
9
+ "method": "forward",
10
+ "method_output_name": "last_hidden_state"
11
+ },
12
+ "message": {
13
+ "method": "forward",
14
+ "method_output_name": "last_hidden_state",
15
+ "format": "structured"
16
+ }
17
+ },
18
+ "module_output_name": "token_embeddings",
19
+ "processing_kwargs": {
20
+ "chat_template": {
21
+ "chat_template": "sentence_transformers"
22
+ },
23
+ "text": {
24
+ "return_mm_token_type_ids": true
25
+ }
26
+ }
27
+ }
tokenizer_config.json CHANGED
@@ -237,5 +237,6 @@
237
  "processor_class": "ColQwen3Processor",
238
  "split_special_tokens": false,
239
  "tokenizer_class": "Qwen2Tokenizer",
240
- "unk_token": null
 
241
  }
 
237
  "processor_class": "ColQwen3Processor",
238
  "split_special_tokens": false,
239
  "tokenizer_class": "Qwen2Tokenizer",
240
+ "unk_token": null,
241
+ "padding_side": "left"
242
  }