Visual Document Retrieval
sentence-transformers
Safetensors
ColPali
ultravbert
vision-language
multimodal
document-retrieval
late-interaction
multi-vector
colbert
vidore
custom_code
Run this model with HF Jobs
Run vllm/ColUltraVBERT on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/vllm/ColUltraVBERT. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/vllm/ColUltraVBERT on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Instructions to use vllm/ColUltraVBERT with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use vllm/ColUltraVBERT with sentence-transformers:
from sentence_transformers import MultiVectorEncoder model = MultiVectorEncoder("vllm/ColUltraVBERT", trust_remote_code=True) queries = ["Which planet is known as the Red Planet?"] documents = [ "Venus is often called Earth's twin because of its similar size and proximity.", "Mars, known for its reddish appearance, is often referred to as the Red Planet.", "Jupiter, the largest planet in our solar system, has a prominent red spot.", ] query_embeddings = model.encode_query(queries) document_embeddings = model.encode_document(documents) similarities = model.similarity(query_embeddings, document_embeddings) print(similarities) - ColPali
How to use vllm/ColUltraVBERT 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
Download image_processing_ultravbert.py from vllm/ColUltraVBERT: direct link, hf CLI and curl.
- Browser
- Download file 3.29 kB
-
https://huggingface.co/vllm/ColUltraVBERT/resolve/main/image_processing_ultravbert.py
- Command line
-
hf download hf://vllm/ColUltraVBERT/image_processing_ultravbert.py
-
curl -L -o image_processing_ultravbert.py https://huggingface.co/vllm/ColUltraVBERT/resolve/main/image_processing_ultravbert.py
3.29 kB
| import math | |
| from transformers.image_utils import SizeDict | |
| from transformers.models.idefics3.image_processing_idefics3 import ( | |
| MAX_IMAGE_SIZE, | |
| Idefics3ImageProcessor, | |
| Idefics3ImageProcessorKwargs, | |
| _resize_output_size_rescale_to_max_len, | |
| _resize_output_size_scale_below_upper_bound, | |
| ) | |
| def get_capped_longest_edge(height: int, width: int, longest_edge: int, tile_size: int, max_image_tiles: int) -> int: | |
| for edge in range(longest_edge, tile_size - 1, -tile_size): | |
| resized_height, resized_width = _resize_output_size_rescale_to_max_len(height, width, max_len=edge) | |
| resized_height, resized_width = _resize_output_size_scale_below_upper_bound( | |
| resized_height, resized_width, max_len=MAX_IMAGE_SIZE | |
| ) | |
| aspect_ratio = resized_width / resized_height | |
| if resized_width >= resized_height: | |
| cols = math.ceil(resized_width / tile_size) | |
| rows = math.ceil(int(cols * tile_size / aspect_ratio) / tile_size) | |
| else: | |
| rows = math.ceil(resized_height / tile_size) | |
| cols = math.ceil(int(rows * tile_size * aspect_ratio) / tile_size) | |
| if rows * cols <= max_image_tiles: | |
| return edge | |
| return tile_size | |
| class UltraVBertImageProcessorKwargs(Idefics3ImageProcessorKwargs, total=False): | |
| max_image_tiles: int | None | |
| class UltraVBertImageProcessor(Idefics3ImageProcessor): | |
| max_image_tiles = None | |
| valid_kwargs = UltraVBertImageProcessorKwargs | |
| def _preprocess(self, images, *, do_resize, size, resample, do_image_splitting, max_image_size, | |
| max_image_tiles=None, **kwargs): | |
| if do_resize and do_image_splitting and max_image_tiles is not None: | |
| tile_size = max_image_size["longest_edge"] | |
| images = [ | |
| [ | |
| self.resize( | |
| image, | |
| SizeDict( | |
| longest_edge=get_capped_longest_edge( | |
| *image.shape[-2:], size.longest_edge, tile_size, max_image_tiles | |
| ) | |
| ), | |
| resample=resample, | |
| ) | |
| for image in batch_images | |
| ] | |
| for batch_images in images | |
| ] | |
| do_resize = False | |
| return super()._preprocess(images, do_resize=do_resize, size=size, resample=resample, | |
| do_image_splitting=do_image_splitting, max_image_size=max_image_size, **kwargs) | |
| def get_number_of_image_patches(self, height: int, width: int, images_kwargs: dict | None = None): | |
| images_kwargs = dict(images_kwargs or {}) | |
| max_image_tiles = images_kwargs.get("max_image_tiles", self.max_image_tiles) | |
| if max_image_tiles is not None: | |
| size = images_kwargs.get("size", self.size) | |
| tile_size = images_kwargs.get("max_image_size", self.max_image_size)["longest_edge"] | |
| longest_edge = get_capped_longest_edge(height, width, size["longest_edge"], tile_size, max_image_tiles) | |
| images_kwargs["size"] = {"longest_edge": longest_edge} | |
| return super().get_number_of_image_patches(height, width, images_kwargs) | |
| __all__ = ["UltraVBertImageProcessor"] | |