tomaarsen HF Staff commited on
Commit
8defca1
·
verified ·
1 Parent(s): 54aa3ff

Integrate with Sentence Transformers via MultiVectorEncoder

Browse files
1_Dense/config.json ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "in_features": 3072,
3
+ "out_features": 128,
4
+ "bias": false,
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:805e2f4dd1ecfbeea26036c69e88e9714f1a633f42d1dfd3370056ce70f85f11
3
+ size 786520
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
@@ -20,6 +20,7 @@ tags:
20
  - mistral
21
  - mteb
22
  - vidore
 
23
  base_model: mistralai/Ministral-3B-Instruct
24
  pipeline_tag: image-text-to-text
25
  datasets:
@@ -132,6 +133,42 @@ Traditional OCR-based retrieval **loses layout, tables, and visual context**. Ou
132
 
133
  ## Installation & Usage
134
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135
  > ⚠️ **Important**: Install our package first (requires transformers 5.0.0+):
136
 
137
  ```bash
@@ -139,7 +176,6 @@ pip install "sauerkrautlm-colpali[ministral]"
139
  # Or: pip install git+https://github.com/VAGOsolutions/sauerkrautlm-colpali && pip install transformers>=5.0.0rc0
140
  ```
141
 
142
- ## Usage
143
 
144
  ```python
145
  import torch
 
20
  - mistral
21
  - mteb
22
  - vidore
23
+ - sentence-transformers
24
  base_model: mistralai/Ministral-3B-Instruct
25
  pipeline_tag: image-text-to-text
26
  datasets:
 
133
 
134
  ## Installation & Usage
135
 
136
+ ### Sentence Transformers
137
+
138
+ This model can be used with [Sentence Transformers](https://www.sbert.net/) as a multi-vector (ColBERT-style late interaction) retriever via the `MultiVectorEncoder`:
139
+
140
+ ```bash
141
+ pip install "sentence-transformers[image]>=6.0.0"
142
+ ```
143
+
144
+ ```python
145
+ from sentence_transformers import MultiVectorEncoder
146
+
147
+ model = MultiVectorEncoder("VAGOsolutions/SauerkrautLM-ColMinistral3-3b-v0.1")
148
+
149
+ queries = [
150
+ "What is the variable represented on the y-axis of the graph?",
151
+ "Total outlay is maximum in which year?",
152
+ ]
153
+ images = [
154
+ "https://huggingface.co/datasets/sentence-transformers/example-documents/resolve/main/doc1.jpg",
155
+ "https://huggingface.co/datasets/sentence-transformers/example-documents/resolve/main/doc2.jpg",
156
+ ]
157
+
158
+ query_embeddings = model.encode_query(queries)
159
+ image_embeddings = model.encode_document(images)
160
+ print(query_embeddings[0].shape, image_embeddings[0].shape)
161
+ # torch.Size([24, 128]) torch.Size([427, 128])
162
+
163
+ # Diagonal should have higher scores
164
+ scores = model.similarity(query_embeddings, image_embeddings)
165
+ print(scores)
166
+ # tensor([[24.0039, 24.0000],
167
+ # [19.2227, 19.5508]], device='cuda:0')
168
+ ```
169
+
170
+ ### SauerkrautLM ColPali
171
+
172
  > ⚠️ **Important**: Install our package first (requires transformers 5.0.0+):
173
 
174
  ```bash
 
176
  # Or: pip install git+https://github.com/VAGOsolutions/sauerkrautlm-colpali && pip install transformers>=5.0.0rc0
177
  ```
178
 
 
179
 
180
  ```python
181
  import torch
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
+ {{- ns.text + '</s></s></s></s></s></s></s></s></s></s>' -}}
14
+ {%- else -%}
15
+ {{- '<s><s>[SYSTEM_PROMPT]# HOW YOU SHOULD THINK AND ANSWER\n\nFirst draft your thinking process (inner monologue) until you arrive at a response. Format your response using Markdown, and use LaTeX for any mathematical equations. Write both your thoughts and the response in the same language as the input.\n\nYour thinking process must follow the template below:[THINK]Your thoughts or/and draft, like working through an exercise on scratch paper. Be as casual and as long as you want until you are confident to generate the response to the user.[/THINK]Here, provide a self-contained response.[/SYSTEM_PROMPT][INST][IMG][/INST]' -}}
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 CHANGED
@@ -3,7 +3,7 @@
3
  "image_end_token": "[IMG_END]",
4
  "image_token": "[IMG]",
5
  "patch_size": 14,
6
- "processor_class": "ColMinistral3Processor",
7
  "spatial_merge_size": 2,
8
  "image_processor": {
9
  "crop_size": null,
 
3
  "image_end_token": "[IMG_END]",
4
  "image_token": "[IMG]",
5
  "patch_size": 14,
6
+ "processor_class": "PixtralProcessor",
7
  "spatial_merge_size": 2,
8
  "image_processor": {
9
  "crop_size": null,
sentence_bert_config.json ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ },
24
+ "model_kwargs": {
25
+ "key_mapping": {
26
+ "^model\\.": ""
27
+ }
28
+ }
29
+ }
tokenizer_config.json CHANGED
@@ -2017,5 +2017,6 @@
2017
  "processor_class": "PixtralProcessor",
2018
  "tokenizer_class": "LlamaTokenizer",
2019
  "unk_token": "<unk>",
2020
- "use_default_system_prompt": false
 
2021
  }
 
2017
  "processor_class": "PixtralProcessor",
2018
  "tokenizer_class": "LlamaTokenizer",
2019
  "unk_token": "<unk>",
2020
+ "use_default_system_prompt": false,
2021
+ "padding_side": "left"
2022
  }