Visual Document Retrieval
sentence-transformers
Safetensors
ColPali
ultravbert
vision-language
multimodal
document-retrieval
late-interaction
multi-vector
colbert
vidore
custom_code
Instructions to use vllm-project/ColUltraVBERT with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use vllm-project/ColUltraVBERT with sentence-transformers:
from sentence_transformers import MultiVectorEncoder model = MultiVectorEncoder("vllm-project/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-project/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 modeling_ultravbert.py from vllm-project/ColUltraVBERT: direct link, hf CLI and curl.
- Browser
- Download file 1.85 kB
-
https://huggingface.co/vllm-project/ColUltraVBERT/resolve/main/modeling_ultravbert.py
- Command line
-
hf download hf://vllm-project/ColUltraVBERT/modeling_ultravbert.py
-
curl -L -o modeling_ultravbert.py https://huggingface.co/vllm-project/ColUltraVBERT/resolve/main/modeling_ultravbert.py
1.85 kB
| from torch import nn | |
| from transformers import AutoModel | |
| from transformers.models.modernvbert.modeling_modernvbert import ( | |
| ModernVBertConnector, | |
| ModernVBertModel, | |
| ModernVBertPreTrainedModel, | |
| ) | |
| from transformers.models.ultrabert.modeling_ultrabert import UltrabertRMSNorm | |
| from .configuration_ultravbert import UltraVBertConfig | |
| class UltraVBertConnector(ModernVBertConnector): | |
| def __init__(self, config: UltraVBertConfig): | |
| super().__init__(config) | |
| # UltraBERT's first layer takes embeddings unnormalized; raw projections would swamp its token embeddings. | |
| self.norm = ( | |
| UltrabertRMSNorm(config.text_config.hidden_size, eps=config.text_config.rms_norm_eps) | |
| if config.connector_norm | |
| else nn.Identity() | |
| ) | |
| def forward(self, image_hidden_states): | |
| return self.norm(super().forward(image_hidden_states)) | |
| class UltraVBertModel(ModernVBertModel): | |
| config_class = UltraVBertConfig | |
| _keys_to_ignore_on_load_unexpected = [r"vision_model\.head\."] | |
| def __init__(self, config: UltraVBertConfig): | |
| # ModernVBertModel.__init__ builds ModernVBertConnector; the rest of its body follows unchanged. | |
| ModernVBertPreTrainedModel.__init__(self, config) | |
| self.padding_idx = config.text_config.pad_token_id | |
| self.vocab_size = config.text_config.vocab_size | |
| self.vision_model = AutoModel.from_config(config.vision_config) | |
| self.connector = UltraVBertConnector(config) | |
| self.text_model = AutoModel.from_config(config.text_config) | |
| self.image_seq_len = int( | |
| ((config.vision_config.image_size // config.vision_config.patch_size) ** 2) | |
| / (config.pixel_shuffle_factor**2) | |
| ) | |
| self.image_token_id = config.image_token_id | |
| self.post_init() | |
| __all__ = ["UltraVBertModel"] | |