Visual Document Retrieval
Transformers
Safetensors
ColPali
English
ultravbert
fill-mask
ultrabert
vision-language
multimodal
document-retrieval
vidore
custom_code
Instructions to use hf-internal-testing/testing-dummy-UltraVBERT with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use hf-internal-testing/testing-dummy-UltraVBERT with Transformers:
# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModelForMaskedLM processor = AutoProcessor.from_pretrained("hf-internal-testing/testing-dummy-UltraVBERT", trust_remote_code=True) model = AutoModelForMaskedLM.from_pretrained("hf-internal-testing/testing-dummy-UltraVBERT", trust_remote_code=True, device_map="auto") - ColPali
How to use hf-internal-testing/testing-dummy-UltraVBERT with ColPali:
# No code snippets available yet for this library. # To use this model, check the repository files and the library's documentation. # Want to help? PRs adding snippets are welcome at: # https://github.com/huggingface/huggingface.js
- Notebooks
- Google Colab
- Kaggle
Commit ·
214d44d
0
Parent(s):
Duplicate from athrael-soju/UltraVBERT
Browse filesCo-authored-by: Athrael Soju <athrael-soju@users.noreply.huggingface.co>
- .gitattributes +36 -0
- LICENSE +21 -0
- LICENSE-APACHE +201 -0
- README.md +164 -0
- config.json +103 -0
- configuration_ultravbert.py +29 -0
- image_processing_ultravbert.py +73 -0
- model.safetensors +3 -0
- modeling_ultravbert.py +126 -0
- processor_config.json +35 -0
- tokenizer.json +0 -0
- tokenizer_config.json +23 -0
- ultravbert-hero.png +3 -0
.gitattributes
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.xz 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 |
+
ultravbert-hero.png filter=lfs diff=lfs merge=lfs -text
|
LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MIT License
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2026 Athrael Soju
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 6 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 7 |
+
in the Software without restriction, including without limitation the rights
|
| 8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 9 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 10 |
+
furnished to do so, subject to the following conditions:
|
| 11 |
+
|
| 12 |
+
The above copyright notice and this permission notice shall be included in all
|
| 13 |
+
copies or substantial portions of the Software.
|
| 14 |
+
|
| 15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 17 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 18 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 19 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 20 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 21 |
+
SOFTWARE.
|
LICENSE-APACHE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Apache License
|
| 2 |
+
Version 2.0, January 2004
|
| 3 |
+
http://www.apache.org/licenses/
|
| 4 |
+
|
| 5 |
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
| 6 |
+
|
| 7 |
+
1. Definitions.
|
| 8 |
+
|
| 9 |
+
"License" shall mean the terms and conditions for use, reproduction,
|
| 10 |
+
and distribution as defined by Sections 1 through 9 of this document.
|
| 11 |
+
|
| 12 |
+
"Licensor" shall mean the copyright owner or entity authorized by
|
| 13 |
+
the copyright owner that is granting the License.
|
| 14 |
+
|
| 15 |
+
"Legal Entity" shall mean the union of the acting entity and all
|
| 16 |
+
other entities that control, are controlled by, or are under common
|
| 17 |
+
control with that entity. For the purposes of this definition,
|
| 18 |
+
"control" means (i) the power, direct or indirect, to cause the
|
| 19 |
+
direction or management of such entity, whether by contract or
|
| 20 |
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
| 21 |
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
| 22 |
+
|
| 23 |
+
"You" (or "Your") shall mean an individual or Legal Entity
|
| 24 |
+
exercising permissions granted by this License.
|
| 25 |
+
|
| 26 |
+
"Source" form shall mean the preferred form for making modifications,
|
| 27 |
+
including but not limited to software source code, documentation
|
| 28 |
+
source, and configuration files.
|
| 29 |
+
|
| 30 |
+
"Object" form shall mean any form resulting from mechanical
|
| 31 |
+
transformation or translation of a Source form, including but
|
| 32 |
+
not limited to compiled object code, generated documentation,
|
| 33 |
+
and conversions to other media types.
|
| 34 |
+
|
| 35 |
+
"Work" shall mean the work of authorship, whether in Source or
|
| 36 |
+
Object form, made available under the License, as indicated by a
|
| 37 |
+
copyright notice that is included in or attached to the work
|
| 38 |
+
(an example is provided in the Appendix below).
|
| 39 |
+
|
| 40 |
+
"Derivative Works" shall mean any work, whether in Source or Object
|
| 41 |
+
form, that is based on (or derived from) the Work and for which the
|
| 42 |
+
editorial revisions, annotations, elaborations, or other modifications
|
| 43 |
+
represent, as a whole, an original work of authorship. For the purposes
|
| 44 |
+
of this License, Derivative Works shall not include works that remain
|
| 45 |
+
separable from, or merely link (or bind by name) to the interfaces of,
|
| 46 |
+
the Work and Derivative Works thereof.
|
| 47 |
+
|
| 48 |
+
"Contribution" shall mean any work of authorship, including
|
| 49 |
+
the original version of the Work and any modifications or additions
|
| 50 |
+
to that Work or Derivative Works thereof, that is intentionally
|
| 51 |
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
| 52 |
+
or by an individual or Legal Entity authorized to submit on behalf of
|
| 53 |
+
the copyright owner. For the purposes of this definition, "submitted"
|
| 54 |
+
means any form of electronic, verbal, or written communication sent
|
| 55 |
+
to the Licensor or its representatives, including but not limited to
|
| 56 |
+
communication on electronic mailing lists, source code control systems,
|
| 57 |
+
and issue tracking systems that are managed by, or on behalf of, the
|
| 58 |
+
Licensor for the purpose of discussing and improving the Work, but
|
| 59 |
+
excluding communication that is conspicuously marked or otherwise
|
| 60 |
+
designated in writing by the copyright owner as "Not a Contribution."
|
| 61 |
+
|
| 62 |
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
| 63 |
+
on behalf of whom a Contribution has been received by Licensor and
|
| 64 |
+
subsequently incorporated within the Work.
|
| 65 |
+
|
| 66 |
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
| 67 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 68 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 69 |
+
copyright license to reproduce, prepare Derivative Works of,
|
| 70 |
+
publicly display, publicly perform, sublicense, and distribute the
|
| 71 |
+
Work and such Derivative Works in Source or Object form.
|
| 72 |
+
|
| 73 |
+
3. Grant of Patent License. Subject to the terms and conditions of
|
| 74 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 75 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 76 |
+
(except as stated in this section) patent license to make, have made,
|
| 77 |
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
| 78 |
+
where such license applies only to those patent claims licensable
|
| 79 |
+
by such Contributor that are necessarily infringed by their
|
| 80 |
+
Contribution(s) alone or by combination of their Contribution(s)
|
| 81 |
+
with the Work to which such Contribution(s) was submitted. If You
|
| 82 |
+
institute patent litigation against any entity (including a
|
| 83 |
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
| 84 |
+
or a Contribution incorporated within the Work constitutes direct
|
| 85 |
+
or contributory patent infringement, then any patent licenses
|
| 86 |
+
granted to You under this License for that Work shall terminate
|
| 87 |
+
as of the date such litigation is filed.
|
| 88 |
+
|
| 89 |
+
4. Redistribution. You may reproduce and distribute copies of the
|
| 90 |
+
Work or Derivative Works thereof in any medium, with or without
|
| 91 |
+
modifications, and in Source or Object form, provided that You
|
| 92 |
+
meet the following conditions:
|
| 93 |
+
|
| 94 |
+
(a) You must give any other recipients of the Work or
|
| 95 |
+
Derivative Works a copy of this License; and
|
| 96 |
+
|
| 97 |
+
(b) You must cause any modified files to carry prominent notices
|
| 98 |
+
stating that You changed the files; and
|
| 99 |
+
|
| 100 |
+
(c) You must retain, in the Source form of any Derivative Works
|
| 101 |
+
that You distribute, all copyright, patent, trademark, and
|
| 102 |
+
attribution notices from the Source form of the Work,
|
| 103 |
+
excluding those notices that do not pertain to any part of
|
| 104 |
+
the Derivative Works; and
|
| 105 |
+
|
| 106 |
+
(d) If the Work includes a "NOTICE" text file as part of its
|
| 107 |
+
distribution, then any Derivative Works that You distribute must
|
| 108 |
+
include a readable copy of the attribution notices contained
|
| 109 |
+
within such NOTICE file, excluding those notices that do not
|
| 110 |
+
pertain to any part of the Derivative Works, in at least one
|
| 111 |
+
of the following places: within a NOTICE text file distributed
|
| 112 |
+
as part of the Derivative Works; within the Source form or
|
| 113 |
+
documentation, if provided along with the Derivative Works; or,
|
| 114 |
+
within a display generated by the Derivative Works, if and
|
| 115 |
+
wherever such third-party notices normally appear. The contents
|
| 116 |
+
of the NOTICE file are for informational purposes only and
|
| 117 |
+
do not modify the License. You may add Your own attribution
|
| 118 |
+
notices within Derivative Works that You distribute, alongside
|
| 119 |
+
or as an addendum to the NOTICE text from the Work, provided
|
| 120 |
+
that such additional attribution notices cannot be construed
|
| 121 |
+
as modifying the License.
|
| 122 |
+
|
| 123 |
+
You may add Your own copyright statement to Your modifications and
|
| 124 |
+
may provide additional or different license terms and conditions
|
| 125 |
+
for use, reproduction, or distribution of Your modifications, or
|
| 126 |
+
for any such Derivative Works as a whole, provided Your use,
|
| 127 |
+
reproduction, and distribution of the Work otherwise complies with
|
| 128 |
+
the conditions stated in this License.
|
| 129 |
+
|
| 130 |
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
| 131 |
+
any Contribution intentionally submitted for inclusion in the Work
|
| 132 |
+
by You to the Licensor shall be under the terms and conditions of
|
| 133 |
+
this License, without any additional terms or conditions.
|
| 134 |
+
Notwithstanding the above, nothing herein shall supersede or modify
|
| 135 |
+
the terms of any separate license agreement you may have executed
|
| 136 |
+
with Licensor regarding such Contributions.
|
| 137 |
+
|
| 138 |
+
6. Trademarks. This License does not grant permission to use the trade
|
| 139 |
+
names, trademarks, service marks, or product names of the Licensor,
|
| 140 |
+
except as required for reasonable and customary use in describing the
|
| 141 |
+
origin of the Work and reproducing the content of the NOTICE file.
|
| 142 |
+
|
| 143 |
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
| 144 |
+
agreed to in writing, Licensor provides the Work (and each
|
| 145 |
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
| 146 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
| 147 |
+
implied, including, without limitation, any warranties or conditions
|
| 148 |
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
| 149 |
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
| 150 |
+
appropriateness of using or redistributing the Work and assume any
|
| 151 |
+
risks associated with Your exercise of permissions under this License.
|
| 152 |
+
|
| 153 |
+
8. Limitation of Liability. In no event and under no legal theory,
|
| 154 |
+
whether in tort (including negligence), contract, or otherwise,
|
| 155 |
+
unless required by applicable law (such as deliberate and grossly
|
| 156 |
+
negligent acts) or agreed to in writing, shall any Contributor be
|
| 157 |
+
liable to You for damages, including any direct, indirect, special,
|
| 158 |
+
incidental, or consequential damages of any character arising as a
|
| 159 |
+
result of this License or out of the use or inability to use the
|
| 160 |
+
Work (including but not limited to damages for loss of goodwill,
|
| 161 |
+
work stoppage, computer failure or malfunction, or any and all
|
| 162 |
+
other commercial damages or losses), even if such Contributor
|
| 163 |
+
has been advised of the possibility of such damages.
|
| 164 |
+
|
| 165 |
+
9. Accepting Warranty or Additional Liability. While redistributing
|
| 166 |
+
the Work or Derivative Works thereof, You may choose to offer,
|
| 167 |
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
| 168 |
+
or other liability obligations and/or rights consistent with this
|
| 169 |
+
License. However, in accepting such obligations, You may act only
|
| 170 |
+
on Your own behalf and on Your sole responsibility, not on behalf
|
| 171 |
+
of any other Contributor, and only if You agree to indemnify,
|
| 172 |
+
defend, and hold each Contributor harmless for any liability
|
| 173 |
+
incurred by, or claims asserted against, such Contributor by reason
|
| 174 |
+
of your accepting any such warranty or additional liability.
|
| 175 |
+
|
| 176 |
+
END OF TERMS AND CONDITIONS
|
| 177 |
+
|
| 178 |
+
APPENDIX: How to apply the Apache License to your work.
|
| 179 |
+
|
| 180 |
+
To apply the Apache License to your work, attach the following
|
| 181 |
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
| 182 |
+
replaced with your own identifying information. (Don't include
|
| 183 |
+
the brackets!) The text should be enclosed in the appropriate
|
| 184 |
+
comment syntax for the file format. We also recommend that a
|
| 185 |
+
file or class name and description of purpose be included on the
|
| 186 |
+
same "printed page" as the copyright notice for easier
|
| 187 |
+
identification within third-party archives.
|
| 188 |
+
|
| 189 |
+
Copyright [yyyy] [name of copyright owner]
|
| 190 |
+
|
| 191 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
| 192 |
+
you may not use this file except in compliance with the License.
|
| 193 |
+
You may obtain a copy of the License at
|
| 194 |
+
|
| 195 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 196 |
+
|
| 197 |
+
Unless required by applicable law or agreed to in writing, software
|
| 198 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
| 199 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 200 |
+
See the License for the specific language governing permissions and
|
| 201 |
+
limitations under the License.
|
README.md
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
language:
|
| 4 |
+
- en
|
| 5 |
+
base_model:
|
| 6 |
+
- dmis-lab/UltraBERT-150M
|
| 7 |
+
base_model_relation: finetune
|
| 8 |
+
datasets:
|
| 9 |
+
- HuggingFaceM4/Docmatix
|
| 10 |
+
- HuggingFaceM4/FineVision
|
| 11 |
+
- HuggingFaceM4/the_cauldron
|
| 12 |
+
- rlhn/rlhn-680K
|
| 13 |
+
tags:
|
| 14 |
+
- ultravbert
|
| 15 |
+
- ultrabert
|
| 16 |
+
- vision-language
|
| 17 |
+
- multimodal
|
| 18 |
+
- document-retrieval
|
| 19 |
+
- colpali
|
| 20 |
+
- vidore
|
| 21 |
+
pipeline_tag: visual-document-retrieval
|
| 22 |
+
library_name: transformers
|
| 23 |
+
---
|
| 24 |
+
|
| 25 |
+
<img src="ultravbert-hero.png" width="100%" alt="UltraVBERT">
|
| 26 |
+
|
| 27 |
+
# UltraVBERT
|
| 28 |
+
|
| 29 |
+
UltraVBERT is a 293M-parameter vision-language encoder built as a base for visual document retrievers. It combines the
|
| 30 |
+
[UltraBERT-150M](https://huggingface.co/dmis-lab/UltraBERT-150M) text encoder with the
|
| 31 |
+
[SigLIP2-B/16-512](https://huggingface.co/google/siglip2-base-patch16-512) vision encoder and produces a contextual
|
| 32 |
+
embedding for every text and image token.
|
| 33 |
+
|
| 34 |
+
## Models
|
| 35 |
+
|
| 36 |
+
<table style="display: table; width: 100%;">
|
| 37 |
+
<thead>
|
| 38 |
+
<tr><th align="left">Model</th><th align="left">Role</th><th align="left">Status</th></tr>
|
| 39 |
+
</thead>
|
| 40 |
+
<tbody>
|
| 41 |
+
<tr><td><a href="https://huggingface.co/athrael-soju/UltraVBERT">UltraVBERT</a></td><td>Base encoder aligned to page images</td><td>Available</td></tr>
|
| 42 |
+
<tr><td><a href="https://huggingface.co/athrael-soju/BiUltraVBERT">BiUltraVBERT</a></td><td>Single-vector retriever for visual documents</td><td>Available</td></tr>
|
| 43 |
+
<tr><td><a href="https://huggingface.co/athrael-soju/ColUltraVBERT">ColUltraVBERT</a></td><td>Late-interaction retriever for visual documents</td><td>Available · <a href="https://huggingface.co/spaces/athrael-soju/ColUltraVBERT">Demo</a></td></tr>
|
| 44 |
+
</tbody>
|
| 45 |
+
</table>
|
| 46 |
+
|
| 47 |
+
## Architecture
|
| 48 |
+
|
| 49 |
+
SigLIP2 encodes each 512 px tile of a page into 1,024 patches. The connector merges each 4 x 4 block of patches into
|
| 50 |
+
one token, giving 64 tokens per tile, then projects each token to UltraBERT's hidden size and RMS-normalizes it.
|
| 51 |
+
UltraBERT then attends over image and text tokens together.
|
| 52 |
+
|
| 53 |
+
UltraVBERT builds on [ModernVBERT](https://huggingface.co/ModernVBERT/modernvbert)
|
| 54 |
+
([arXiv 2510.01149](https://arxiv.org/abs/2510.01149)). It replaces the Ettin-150M text encoder with UltraBERT
|
| 55 |
+
([arXiv 2610.15028](https://arxiv.org/abs/2610.15028)), normalizes the connector output, raises the page limit from
|
| 56 |
+
2,048 px and 16 tiles to 3,072 px and 27 tiles, and adds a training stage on rendered text pages.
|
| 57 |
+
|
| 58 |
+
| Component | Configuration | Parameters |
|
| 59 |
+
| --- | --- | ---: |
|
| 60 |
+
| Text encoder | UltraBERT-150M: 24 layers, hidden size 768, 6 heads; local attention over ±128 tokens in 2 of every 3 layers; 40 added special tokens | 151,130,880 |
|
| 61 |
+
| Vision encoder | SigLIP2-B/16-512: 12 layers, 16 px patches, 512 px tiles | 93,520,128 |
|
| 62 |
+
| Connector | 4 x 4 pixel shuffle, linear 12,288 to 768, RMSNorm | 9,437,952 |
|
| 63 |
+
| MLM head | UltraBERT's released head: two 768 x 768 layers and an output layer extended to 49,280 tokens | 39,026,688 |
|
| 64 |
+
| Total | | 293,115,648 |
|
| 65 |
+
|
| 66 |
+
The encoder without the MLM head has 254M parameters. Weights are stored in bfloat16.
|
| 67 |
+
|
| 68 |
+
The processor scales a page to 3,072 px on its longest edge, reduces that in 512 px steps until the page fits in 27
|
| 69 |
+
tiles, and adds a downscaled view of the whole page. A grid holds at most six tiles per side, so the largest that
|
| 70 |
+
fits is 5 x 5, for at most 26 x 64 = 1,664 image tokens per page. For shorter
|
| 71 |
+
sequences, set
|
| 72 |
+
`processor.image_processor.size = {"longest_edge": 2048}` (at most 1,088 image tokens) or lower
|
| 73 |
+
`processor.image_processor.max_image_tiles`.
|
| 74 |
+
|
| 75 |
+
## Usage
|
| 76 |
+
|
| 77 |
+
Requires `transformers>=5.20`.
|
| 78 |
+
|
| 79 |
+
```python
|
| 80 |
+
import torch
|
| 81 |
+
from PIL import Image
|
| 82 |
+
from transformers import AutoModel, AutoModelForMaskedLM, AutoProcessor
|
| 83 |
+
|
| 84 |
+
processor = AutoProcessor.from_pretrained("athrael-soju/UltraVBERT", trust_remote_code=True)
|
| 85 |
+
page = Image.open("page.png")
|
| 86 |
+
|
| 87 |
+
# Predict a masked word from the page.
|
| 88 |
+
model = AutoModelForMaskedLM.from_pretrained(
|
| 89 |
+
"athrael-soju/UltraVBERT", trust_remote_code=True, dtype=torch.bfloat16, device_map="auto"
|
| 90 |
+
)
|
| 91 |
+
inputs = processor(text="<image>The table reports revenue in <|mask|>.", images=[page], return_tensors="pt").to(model.device)
|
| 92 |
+
with torch.no_grad():
|
| 93 |
+
logits = model(**inputs).logits
|
| 94 |
+
masked_logits = logits[inputs.input_ids == processor.tokenizer.mask_token_id]
|
| 95 |
+
print(processor.tokenizer.batch_decode(masked_logits.argmax(dim=-1)[:, None]))
|
| 96 |
+
|
| 97 |
+
# One 768-d embedding per text and image token.
|
| 98 |
+
encoder = AutoModel.from_pretrained(
|
| 99 |
+
"athrael-soju/UltraVBERT", trust_remote_code=True, dtype=torch.bfloat16, device_map="auto"
|
| 100 |
+
)
|
| 101 |
+
inputs = processor(text="<image>", images=[page], return_tensors="pt").to(encoder.device)
|
| 102 |
+
with torch.no_grad():
|
| 103 |
+
states = encoder(**inputs).last_hidden_state
|
| 104 |
+
```
|
| 105 |
+
|
| 106 |
+
`AutoModelForSequenceClassification` and `AutoModelForTokenClassification` add task heads on the same encoder.
|
| 107 |
+
|
| 108 |
+
## Training
|
| 109 |
+
|
| 110 |
+
UltraVBERT is trained with masked language modelling on the answers in image-grounded conversations, with half of the
|
| 111 |
+
answer tokens masked (80% `<|mask|>`, 10% random token, 10% unchanged).
|
| 112 |
+
|
| 113 |
+
- DoRA adapters (rank 64, alpha 16) on both encoders and the MLM head, peak learning rate 1e-4
|
| 114 |
+
- Connector trained in full at 1e-3; image tokens start at 10x the RMS of UltraBERT's word embeddings
|
| 115 |
+
- The 40 added token embeddings trained directly
|
| 116 |
+
- AdamW (beta2 0.95), weight decay 0.1, gradient clipping 1.0, bfloat16 autocast
|
| 117 |
+
|
| 118 |
+
| Stage | Steps | Text tokens | Data |
|
| 119 |
+
| --- | ---: | ---: | --- |
|
| 120 |
+
| Reading | 3,600 | 0.36B | Docmatix pages and rendered RLHN-680K passages, half each |
|
| 121 |
+
| Mixture | 34,206 | 8.9B | The mix below |
|
| 122 |
+
|
| 123 |
+
The mixture stage uses a warmup-stable-decay schedule with a 1 - sqrt decay over the last 20% of steps. Pages are
|
| 124 |
+
resized to a 1,024 px longest edge until the decay begins, then to random longest edges from 1,024 to 3,072 px.
|
| 125 |
+
|
| 126 |
+
| Category | Share of text tokens | Sources |
|
| 127 |
+
| --- | ---: | --- |
|
| 128 |
+
| Text instructions | 48.18% | 16 FineVision text subsets |
|
| 129 |
+
| OCR and documents | 16.21% | Docmatix and 9 FineVision subsets |
|
| 130 |
+
| Screenshot to code | 16.71% | 4 FineVision subsets |
|
| 131 |
+
| Rendered text pages | 5.00% | RLHN-680K passages |
|
| 132 |
+
| Charts | 5.00% | 8 FineVision subsets |
|
| 133 |
+
| Captioning | 3.13% | 2 FineVision subsets |
|
| 134 |
+
| Tables | 3.00% | 6 FineVision subsets |
|
| 135 |
+
| Reasoning and math | 1.61% | 7 FineVision subsets |
|
| 136 |
+
| Real-world VQA | 1.16% | 2 FineVision subsets and The Cauldron's TallyQA |
|
| 137 |
+
|
| 138 |
+
Datasets: [Docmatix](https://huggingface.co/datasets/HuggingFaceM4/Docmatix),
|
| 139 |
+
[FineVision](https://huggingface.co/datasets/HuggingFaceM4/FineVision),
|
| 140 |
+
[The Cauldron](https://huggingface.co/datasets/HuggingFaceM4/the_cauldron) and
|
| 141 |
+
[RLHN-680K](https://huggingface.co/datasets/rlhn/rlhn-680K). Subsets used:
|
| 142 |
+
|
| 143 |
+
| Category | Subsets |
|
| 144 |
+
| --- | --- |
|
| 145 |
+
| Text instructions | `text_code_feedback`, `text_codefeedback_filtered_instruction`, `text_infinitymath`, `text_mathinstruct`, `text_mathqa`, `text_mathstepdpo10k`, `text_numinamath_cot`, `text_openhermes_2_5`, `text_OpenMathInstruct-2`, `text_openorca`, `text_orcamath`, `text_pythoncode25k`, `text_pythoncodealpaca`, `text_ruozhiba`, `text_theoremqa`, `text_wizardlm_evol` |
|
| 146 |
+
| OCR and documents | Docmatix, `olmOCR-mix-0225-documents`, `CoSyn_400k_document`, `CoSyn_400k_diagram`, `SynthFormulaNet`, `latexformulas`, `k12_printing`, `tal_ocr_eng`, `ocrvqa`, `DoclingMatix` |
|
| 147 |
+
| Screenshot to code | `SynthCodeNet`, `datik`, `datikz`, `websight` |
|
| 148 |
+
| Charts | `CoSyn_400k_chart`, `Unichart`, `SynthChartNet`, `figureqa`, `mapqa`, `chart2text`, `mmc_instruct`, `plotqa` |
|
| 149 |
+
| Captioning | `densefusion_1m`, `localized_narratives` |
|
| 150 |
+
| Tables | `CoSyn_400k_table`, `vqaonbd`, `robut_wikisql`, `robut_wtq`, `finqa`, `robut_sqa` |
|
| 151 |
+
| Reasoning and math | `CoSyn_400k_math`, `mavis_math_metagen`, `geomverse`, `geo170k(qa)`, `geo170k(align)`, `CoSyn_400k_circuit`, `CoSyn_400k_chemical` |
|
| 152 |
+
| Real-world VQA | `CoSyn_400k_graphic`, `mmevol`, The Cauldron `tallyqa` |
|
| 153 |
+
|
| 154 |
+
## Limits
|
| 155 |
+
|
| 156 |
+
- English only.
|
| 157 |
+
- Trained on inputs of up to 7,000 tokens and 3 images.
|
| 158 |
+
- Pages larger than the tile cap are downscaled, which can blur small print.
|
| 159 |
+
|
| 160 |
+
## License
|
| 161 |
+
|
| 162 |
+
`MIT`. The UltraBERT-150M and SigLIP2-B/16-512 components are Apache-2.0, with their license text in
|
| 163 |
+
`LICENSE-APACHE`. Training used passages from
|
| 164 |
+
RLHN-680K (CC-BY-SA-4.0).
|
config.json
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"UltraVBertForMaskedLM"
|
| 4 |
+
],
|
| 5 |
+
"auto_map": {
|
| 6 |
+
"AutoConfig": "configuration_ultravbert.UltraVBertConfig",
|
| 7 |
+
"AutoModel": "modeling_ultravbert.UltraVBertModel",
|
| 8 |
+
"AutoModelForMaskedLM": "modeling_ultravbert.UltraVBertForMaskedLM",
|
| 9 |
+
"AutoModelForSequenceClassification": "modeling_ultravbert.UltraVBertForSequenceClassification",
|
| 10 |
+
"AutoModelForTokenClassification": "modeling_ultravbert.UltraVBertForTokenClassification"
|
| 11 |
+
},
|
| 12 |
+
"classifier_dropout": 0.0,
|
| 13 |
+
"classifier_pooling": "cls",
|
| 14 |
+
"connector_norm": true,
|
| 15 |
+
"dtype": "bfloat16",
|
| 16 |
+
"image_token_id": 49191,
|
| 17 |
+
"initializer_cutoff_factor": 2.0,
|
| 18 |
+
"initializer_range": 0.02,
|
| 19 |
+
"model_type": "ultravbert",
|
| 20 |
+
"pixel_shuffle_factor": 4,
|
| 21 |
+
"text_config": {
|
| 22 |
+
"architectures": [
|
| 23 |
+
"UltrabertForMaskedLM"
|
| 24 |
+
],
|
| 25 |
+
"attention_bias": false,
|
| 26 |
+
"attention_dropout": 0.0,
|
| 27 |
+
"bos_token_id": 0,
|
| 28 |
+
"classifier_dropout": 0.0,
|
| 29 |
+
"classifier_pooling": "cls",
|
| 30 |
+
"dtype": "float32",
|
| 31 |
+
"eos_token_id": 0,
|
| 32 |
+
"head_dim": 128,
|
| 33 |
+
"hidden_act": "silu",
|
| 34 |
+
"hidden_size": 768,
|
| 35 |
+
"initializer_range": 0.02,
|
| 36 |
+
"intermediate_size": 1024,
|
| 37 |
+
"layer_types": [
|
| 38 |
+
"sliding_attention",
|
| 39 |
+
"sliding_attention",
|
| 40 |
+
"full_attention",
|
| 41 |
+
"sliding_attention",
|
| 42 |
+
"sliding_attention",
|
| 43 |
+
"full_attention",
|
| 44 |
+
"sliding_attention",
|
| 45 |
+
"sliding_attention",
|
| 46 |
+
"full_attention",
|
| 47 |
+
"sliding_attention",
|
| 48 |
+
"sliding_attention",
|
| 49 |
+
"full_attention",
|
| 50 |
+
"sliding_attention",
|
| 51 |
+
"sliding_attention",
|
| 52 |
+
"full_attention",
|
| 53 |
+
"sliding_attention",
|
| 54 |
+
"sliding_attention",
|
| 55 |
+
"full_attention",
|
| 56 |
+
"sliding_attention",
|
| 57 |
+
"sliding_attention",
|
| 58 |
+
"full_attention",
|
| 59 |
+
"sliding_attention",
|
| 60 |
+
"sliding_attention",
|
| 61 |
+
"full_attention"
|
| 62 |
+
],
|
| 63 |
+
"max_position_embeddings": 32768,
|
| 64 |
+
"mlp_bias": false,
|
| 65 |
+
"model_type": "ultrabert",
|
| 66 |
+
"num_attention_heads": 6,
|
| 67 |
+
"num_hidden_layers": 24,
|
| 68 |
+
"num_key_value_heads": 6,
|
| 69 |
+
"pad_token_id": 0,
|
| 70 |
+
"prediction_head_size": 768,
|
| 71 |
+
"rms_norm_eps": 1e-06,
|
| 72 |
+
"rope_parameters": {
|
| 73 |
+
"full_attention": {
|
| 74 |
+
"rope_theta": 2560000.0,
|
| 75 |
+
"rope_type": "default"
|
| 76 |
+
},
|
| 77 |
+
"sliding_attention": {
|
| 78 |
+
"rope_theta": 10000.0,
|
| 79 |
+
"rope_type": "default"
|
| 80 |
+
}
|
| 81 |
+
},
|
| 82 |
+
"sliding_window": 128,
|
| 83 |
+
"tie_word_embeddings": false,
|
| 84 |
+
"use_cache": false,
|
| 85 |
+
"vocab_size": 49280
|
| 86 |
+
},
|
| 87 |
+
"tie_word_embeddings": false,
|
| 88 |
+
"transformers_version": "5.21.0.dev0",
|
| 89 |
+
"vision_config": {
|
| 90 |
+
"attention_dropout": 0.0,
|
| 91 |
+
"hidden_act": "gelu_pytorch_tanh",
|
| 92 |
+
"hidden_size": 768,
|
| 93 |
+
"image_size": 512,
|
| 94 |
+
"intermediate_size": 3072,
|
| 95 |
+
"layer_norm_eps": 1e-06,
|
| 96 |
+
"model_type": "siglip_vision_model",
|
| 97 |
+
"num_attention_heads": 12,
|
| 98 |
+
"num_channels": 3,
|
| 99 |
+
"num_hidden_layers": 12,
|
| 100 |
+
"patch_size": 16,
|
| 101 |
+
"vision_use_head": false
|
| 102 |
+
}
|
| 103 |
+
}
|
configuration_ultravbert.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Literal
|
| 2 |
+
|
| 3 |
+
from huggingface_hub.dataclasses import strict
|
| 4 |
+
from transformers import AutoConfig
|
| 5 |
+
from transformers.configuration_utils import PreTrainedConfig, SubConfigSpec
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
@strict
|
| 9 |
+
class UltraVBertConfig(PreTrainedConfig):
|
| 10 |
+
model_type = "ultravbert"
|
| 11 |
+
sub_configs_defaults = {
|
| 12 |
+
"text_config": SubConfigSpec(config_class=AutoConfig, model_type="ultrabert"),
|
| 13 |
+
"vision_config": SubConfigSpec(config_class=AutoConfig, model_type="siglip_vision_model"),
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
text_config: PreTrainedConfig | dict | None = None
|
| 17 |
+
vision_config: PreTrainedConfig | dict | None = None
|
| 18 |
+
|
| 19 |
+
image_token_id: int = 49191
|
| 20 |
+
pixel_shuffle_factor: int = 4
|
| 21 |
+
initializer_range: float = 0.02
|
| 22 |
+
initializer_cutoff_factor: float = 2.0
|
| 23 |
+
classifier_pooling: Literal["cls", "mean"] = "cls"
|
| 24 |
+
classifier_dropout: float | int = 0.0
|
| 25 |
+
tie_word_embeddings: bool = False
|
| 26 |
+
connector_norm: bool = True
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
__all__ = ["UltraVBertConfig"]
|
image_processing_ultravbert.py
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import math
|
| 2 |
+
|
| 3 |
+
from transformers.image_utils import SizeDict
|
| 4 |
+
from transformers.models.idefics3.image_processing_idefics3 import (
|
| 5 |
+
MAX_IMAGE_SIZE,
|
| 6 |
+
Idefics3ImageProcessor,
|
| 7 |
+
Idefics3ImageProcessorKwargs,
|
| 8 |
+
_resize_output_size_rescale_to_max_len,
|
| 9 |
+
_resize_output_size_scale_below_upper_bound,
|
| 10 |
+
)
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def get_capped_longest_edge(height: int, width: int, longest_edge: int, tile_size: int, max_image_tiles: int) -> int:
|
| 14 |
+
for edge in range(longest_edge, tile_size - 1, -tile_size):
|
| 15 |
+
resized_height, resized_width = _resize_output_size_rescale_to_max_len(height, width, max_len=edge)
|
| 16 |
+
resized_height, resized_width = _resize_output_size_scale_below_upper_bound(
|
| 17 |
+
resized_height, resized_width, max_len=MAX_IMAGE_SIZE
|
| 18 |
+
)
|
| 19 |
+
aspect_ratio = resized_width / resized_height
|
| 20 |
+
if resized_width >= resized_height:
|
| 21 |
+
cols = math.ceil(resized_width / tile_size)
|
| 22 |
+
rows = math.ceil(int(cols * tile_size / aspect_ratio) / tile_size)
|
| 23 |
+
else:
|
| 24 |
+
rows = math.ceil(resized_height / tile_size)
|
| 25 |
+
cols = math.ceil(int(rows * tile_size * aspect_ratio) / tile_size)
|
| 26 |
+
if rows * cols <= max_image_tiles:
|
| 27 |
+
return edge
|
| 28 |
+
return tile_size
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
class UltraVBertImageProcessorKwargs(Idefics3ImageProcessorKwargs, total=False):
|
| 32 |
+
max_image_tiles: int | None
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
class UltraVBertImageProcessor(Idefics3ImageProcessor):
|
| 36 |
+
max_image_tiles = None
|
| 37 |
+
valid_kwargs = UltraVBertImageProcessorKwargs
|
| 38 |
+
|
| 39 |
+
def _preprocess(self, images, *, do_resize, size, resample, do_image_splitting, max_image_size,
|
| 40 |
+
max_image_tiles=None, **kwargs):
|
| 41 |
+
if do_resize and do_image_splitting and max_image_tiles is not None:
|
| 42 |
+
tile_size = max_image_size["longest_edge"]
|
| 43 |
+
images = [
|
| 44 |
+
[
|
| 45 |
+
self.resize(
|
| 46 |
+
image,
|
| 47 |
+
SizeDict(
|
| 48 |
+
longest_edge=get_capped_longest_edge(
|
| 49 |
+
*image.shape[-2:], size.longest_edge, tile_size, max_image_tiles
|
| 50 |
+
)
|
| 51 |
+
),
|
| 52 |
+
resample=resample,
|
| 53 |
+
)
|
| 54 |
+
for image in batch_images
|
| 55 |
+
]
|
| 56 |
+
for batch_images in images
|
| 57 |
+
]
|
| 58 |
+
do_resize = False
|
| 59 |
+
return super()._preprocess(images, do_resize=do_resize, size=size, resample=resample,
|
| 60 |
+
do_image_splitting=do_image_splitting, max_image_size=max_image_size, **kwargs)
|
| 61 |
+
|
| 62 |
+
def get_number_of_image_patches(self, height: int, width: int, images_kwargs: dict | None = None):
|
| 63 |
+
images_kwargs = dict(images_kwargs or {})
|
| 64 |
+
max_image_tiles = images_kwargs.get("max_image_tiles", self.max_image_tiles)
|
| 65 |
+
if max_image_tiles is not None:
|
| 66 |
+
size = images_kwargs.get("size", self.size)
|
| 67 |
+
tile_size = images_kwargs.get("max_image_size", self.max_image_size)["longest_edge"]
|
| 68 |
+
longest_edge = get_capped_longest_edge(height, width, size["longest_edge"], tile_size, max_image_tiles)
|
| 69 |
+
images_kwargs["size"] = {"longest_edge": longest_edge}
|
| 70 |
+
return super().get_number_of_image_patches(height, width, images_kwargs)
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
__all__ = ["UltraVBertImageProcessor"]
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:29512ca01cbdae4b0ba9e45d7a36a30dc6a28506ecba8a583afa2b9cf53ad3af
|
| 3 |
+
size 586285080
|
modeling_ultravbert.py
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from torch import nn
|
| 2 |
+
from torch.nn import CrossEntropyLoss
|
| 3 |
+
from transformers import AutoModel
|
| 4 |
+
from transformers.models.modernvbert.modeling_modernvbert import (
|
| 5 |
+
ModernVBertConnector,
|
| 6 |
+
ModernVBertForSequenceClassification,
|
| 7 |
+
ModernVBertForTokenClassification,
|
| 8 |
+
ModernVBertMaskedLMOutput,
|
| 9 |
+
ModernVBertModel,
|
| 10 |
+
ModernVBertPreTrainedModel,
|
| 11 |
+
)
|
| 12 |
+
from transformers.models.ultrabert.modeling_ultrabert import UltrabertPredictionHead, UltrabertRMSNorm
|
| 13 |
+
|
| 14 |
+
from .configuration_ultravbert import UltraVBertConfig
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
class UltraVBertConnector(ModernVBertConnector):
|
| 18 |
+
def __init__(self, config: UltraVBertConfig):
|
| 19 |
+
super().__init__(config)
|
| 20 |
+
# UltraBERT's first layer takes embeddings unnormalized; raw projections would swamp its token embeddings.
|
| 21 |
+
self.norm = (
|
| 22 |
+
UltrabertRMSNorm(config.text_config.hidden_size, eps=config.text_config.rms_norm_eps)
|
| 23 |
+
if config.connector_norm
|
| 24 |
+
else nn.Identity()
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
def forward(self, image_hidden_states):
|
| 28 |
+
return self.norm(super().forward(image_hidden_states))
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
class UltraVBertModel(ModernVBertModel):
|
| 32 |
+
config_class = UltraVBertConfig
|
| 33 |
+
_keys_to_ignore_on_load_unexpected = [r"vision_model\.head\."]
|
| 34 |
+
|
| 35 |
+
def __init__(self, config: UltraVBertConfig):
|
| 36 |
+
# ModernVBertModel.__init__ builds ModernVBertConnector; the rest of its body follows unchanged.
|
| 37 |
+
ModernVBertPreTrainedModel.__init__(self, config)
|
| 38 |
+
self.padding_idx = config.text_config.pad_token_id
|
| 39 |
+
self.vocab_size = config.text_config.vocab_size
|
| 40 |
+
self.vision_model = AutoModel.from_config(config.vision_config)
|
| 41 |
+
self.connector = UltraVBertConnector(config)
|
| 42 |
+
self.text_model = AutoModel.from_config(config.text_config)
|
| 43 |
+
self.image_seq_len = int(
|
| 44 |
+
((config.vision_config.image_size // config.vision_config.patch_size) ** 2)
|
| 45 |
+
/ (config.pixel_shuffle_factor**2)
|
| 46 |
+
)
|
| 47 |
+
self.image_token_id = config.image_token_id
|
| 48 |
+
self.post_init()
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
class UltraVBertForMaskedLM(ModernVBertPreTrainedModel):
|
| 52 |
+
config_class = UltraVBertConfig
|
| 53 |
+
_keys_to_ignore_on_load_unexpected = [r"vision_model\.head\."]
|
| 54 |
+
_tied_weights_keys = {"head.decoder.weight": "model.text_model.embed_tokens.weight"}
|
| 55 |
+
|
| 56 |
+
def __init__(self, config: UltraVBertConfig):
|
| 57 |
+
super().__init__(config)
|
| 58 |
+
self.vocab_size = config.text_config.vocab_size
|
| 59 |
+
self.model = UltraVBertModel(config)
|
| 60 |
+
self.head = UltrabertPredictionHead(config.text_config)
|
| 61 |
+
self.post_init()
|
| 62 |
+
|
| 63 |
+
def get_output_embeddings(self):
|
| 64 |
+
return self.head.decoder
|
| 65 |
+
|
| 66 |
+
def set_output_embeddings(self, new_embeddings):
|
| 67 |
+
self.head.decoder = new_embeddings
|
| 68 |
+
|
| 69 |
+
def forward(self, input_ids=None, attention_mask=None, position_ids=None, inputs_embeds=None, pixel_values=None,
|
| 70 |
+
pixel_attention_mask=None, image_hidden_states=None, labels=None, **kwargs):
|
| 71 |
+
outputs = self.model(
|
| 72 |
+
input_ids=input_ids,
|
| 73 |
+
attention_mask=attention_mask,
|
| 74 |
+
position_ids=position_ids,
|
| 75 |
+
inputs_embeds=inputs_embeds,
|
| 76 |
+
pixel_values=pixel_values,
|
| 77 |
+
pixel_attention_mask=pixel_attention_mask,
|
| 78 |
+
image_hidden_states=image_hidden_states,
|
| 79 |
+
**kwargs,
|
| 80 |
+
)
|
| 81 |
+
logits = self.head(outputs.last_hidden_state)
|
| 82 |
+
loss = None
|
| 83 |
+
if labels is not None:
|
| 84 |
+
loss = CrossEntropyLoss()(logits.view(-1, self.vocab_size), labels.view(-1))
|
| 85 |
+
return ModernVBertMaskedLMOutput(
|
| 86 |
+
loss=loss,
|
| 87 |
+
logits=logits,
|
| 88 |
+
hidden_states=outputs.hidden_states,
|
| 89 |
+
attentions=outputs.attentions,
|
| 90 |
+
image_hidden_states=outputs.image_hidden_states,
|
| 91 |
+
)
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
def _build_classifier(model, config: UltraVBertConfig):
|
| 95 |
+
# ModernVBert's own __init__ builds a ModernBERT prediction head that UltraBERT's text config cannot configure.
|
| 96 |
+
ModernVBertPreTrainedModel.__init__(model, config)
|
| 97 |
+
model.num_labels = config.num_labels
|
| 98 |
+
model.model = UltraVBertModel(config)
|
| 99 |
+
model.head = nn.Identity()
|
| 100 |
+
model.drop = nn.Dropout(config.classifier_dropout)
|
| 101 |
+
model.classifier = nn.Linear(config.text_config.hidden_size, config.num_labels)
|
| 102 |
+
model.post_init()
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
class UltraVBertForSequenceClassification(ModernVBertForSequenceClassification):
|
| 106 |
+
config_class = UltraVBertConfig
|
| 107 |
+
_keys_to_ignore_on_load_unexpected = [r"vision_model\.head\."]
|
| 108 |
+
|
| 109 |
+
def __init__(self, config: UltraVBertConfig):
|
| 110 |
+
_build_classifier(self, config)
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
class UltraVBertForTokenClassification(ModernVBertForTokenClassification):
|
| 114 |
+
config_class = UltraVBertConfig
|
| 115 |
+
_keys_to_ignore_on_load_unexpected = [r"vision_model\.head\."]
|
| 116 |
+
|
| 117 |
+
def __init__(self, config: UltraVBertConfig):
|
| 118 |
+
_build_classifier(self, config)
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
__all__ = [
|
| 122 |
+
"UltraVBertModel",
|
| 123 |
+
"UltraVBertForMaskedLM",
|
| 124 |
+
"UltraVBertForSequenceClassification",
|
| 125 |
+
"UltraVBertForTokenClassification",
|
| 126 |
+
]
|
processor_config.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"image_processor": {
|
| 3 |
+
"do_convert_rgb": true,
|
| 4 |
+
"do_image_splitting": true,
|
| 5 |
+
"do_normalize": true,
|
| 6 |
+
"do_pad": true,
|
| 7 |
+
"do_rescale": true,
|
| 8 |
+
"do_resize": true,
|
| 9 |
+
"image_mean": [
|
| 10 |
+
0.5,
|
| 11 |
+
0.5,
|
| 12 |
+
0.5
|
| 13 |
+
],
|
| 14 |
+
"image_processor_type": "UltraVBertImageProcessor",
|
| 15 |
+
"image_std": [
|
| 16 |
+
0.5,
|
| 17 |
+
0.5,
|
| 18 |
+
0.5
|
| 19 |
+
],
|
| 20 |
+
"max_image_size": {
|
| 21 |
+
"longest_edge": 512
|
| 22 |
+
},
|
| 23 |
+
"max_image_tiles": 27,
|
| 24 |
+
"resample": 1,
|
| 25 |
+
"rescale_factor": 0.00392156862745098,
|
| 26 |
+
"size": {
|
| 27 |
+
"longest_edge": 3072
|
| 28 |
+
},
|
| 29 |
+
"auto_map": {
|
| 30 |
+
"AutoImageProcessor": "image_processing_ultravbert.UltraVBertImageProcessor"
|
| 31 |
+
}
|
| 32 |
+
},
|
| 33 |
+
"image_seq_len": 64,
|
| 34 |
+
"processor_class": "Idefics3Processor"
|
| 35 |
+
}
|
tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"add_prefix_space": false,
|
| 3 |
+
"backend": "tokenizers",
|
| 4 |
+
"bos_token": "<|endoftext|>",
|
| 5 |
+
"clean_up_tokenization_spaces": false,
|
| 6 |
+
"eos_token": "<|endoftext|>",
|
| 7 |
+
"errors": "replace",
|
| 8 |
+
"extra_special_tokens": [
|
| 9 |
+
"<fake_token_around_image>",
|
| 10 |
+
"<image>",
|
| 11 |
+
"<end_of_utterance>"
|
| 12 |
+
],
|
| 13 |
+
"is_local": true,
|
| 14 |
+
"local_files_only": false,
|
| 15 |
+
"mask_token": "<|mask|>",
|
| 16 |
+
"model_max_length": 32768,
|
| 17 |
+
"pad_token": "<|endoftext|>",
|
| 18 |
+
"processor_class": "Idefics3Processor",
|
| 19 |
+
"sep_token": "<|sep|>",
|
| 20 |
+
"tokenizer_class": "GPT2Tokenizer",
|
| 21 |
+
"unk_token": "<|endoftext|>",
|
| 22 |
+
"vocab_size": 49152
|
| 23 |
+
}
|
ultravbert-hero.png
ADDED
|
Git LFS Details
|