Model reference · open weights
e5-v is an open-weight embedding model from royokong. AxForge deploys and operates it for you on dedicated EU-owned hardware — with the licence handled where one is required.
Available as managed deployment — configured and operated for you on dedicated EU hardware, quoted per deployment.
What it is
| Released by | royokong |
|---|---|
| Type | Embedding models |
| Task | Embeddings |
| Parameters (lead) | 8.4B |
| Context | 8k tokens |
| Runs with | sentence-transformers |
| Released | 2024-07-14 |
| Popularity | 21k downloads / month |
| Licence | Unknown |
About
E5-V is fine-tuned based on lmms-lab/llama3-llava-next-8b.
We propose a framework, called E5-V, to adpat MLLMs for achieving multimodal embeddings. E5-V effectively bridges the modality gap between different types of inputs, demonstrating strong performance in multimodal embeddings even without fine-tuning. We also propose a single modality training approach for E5-V, where the model is trained exclusively on text pairs, demonstrating better performance than multimodal training.
More details can be found in https://github.com/kongds/E5-V
Install Sentence Transformers:
pip install "sentence_transformers[image]"
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("royokong/e5-v")
# Encode text inputs
texts = [
"A dog sitting in the grass.",
"A dog standing in the snow.",
"A cat sitting in the grass.",
"A cat standing in the snow.",
]
text_embeddings = model.encode(texts)
print(text_embeddings.shape)
# (4, 4096)
# Encode image inputs
images = [
"https://huggingface.co/royokong/e5-v/resolve/main/assets/dog.jpg",
"https://huggingface.co/royokong/e5-v/resolve/main/assets/cat.jpg",
]
image_embeddings = model.encode(images)
print(image_embeddings.shape)
# (2, 4096)
# Compute text-image similarities
similarities = model.similarity(text_embeddings, image_embeddings)
print(similarities)
# tensor([[0.7183, 0.3579],
# [0.5806, 0.5522],
# [0.4714, 0.6479],
# [0.4150, 0.8081]])
The model uses a custom chat template that automatically wraps text inputs with the instruction "Summary above sentence in one word:" and image inputs with "Summary above image in one word:".
import torch
import torch.nn.functional as F
import requests
from PIL import Image
from transformers import AutoTokenizer
from transformers import LlavaNextProcessor, LlavaNextForConditionalGeneration
llama3_template = 'user\n\n{}assistant\n\n \n'
processor = LlavaNextProcessor.from_pretrained('royokong/e5-v')
model = LlavaNextForConditionalGeneration.from_pretrained('royokong/e5-v', torch_dtype=torch.float16).cuda()
img_prompt = llama3_template.format('\nSummary above image in one word: ')
text_prompt = llama3_template.format('\nSummary above sentence in one word: ')
urls = [
'https://huggingface.co/royokong/e5-v/resolve/main/assets/dog.jpg',
'https://huggingface.co/royokong/e5-v/resolve/main/assets/cat.jpg',
]
images = [Image.open(requests.get(url, stream=True).raw) for url in urls]
texts = ['A dog sitting in the grass.',
'A dog standing in the snow.',
'A cat sitting in the grass.',
'A cat standing in the snow.']
text_inputs = processor([text_prompt.replace('', text) for text in texts], return_tensors="pt", padding=True).to('cuda')
img_inputs = processor([img_prompt]*len(images), images, return_tensors="pt", padding=True).to('cuda')
with torch.no_grad():
text_embs = model(**text_inputs, output_hidden_states=True, return_dict=True).hidden_states[-1][:, -1, :]
img_embs = model(**img_inputs, output_hidden_states=True, return_dict=True).hidden_states[-1][:, -1, :]
text_embs = F.normalize(text_embs, dim=-1)
img_embs = F.normalize(img_embs, dim=-1)
print(text_embs @ img_embs.t())
# tensor([[0.7275, 0.3630],
# [0.5957, 0.5522],
# [0.4709, 0.6406],
# [0.4202, 0.7974]])
From the published model card. Full card on the HuggingFace links in the sidebar.
Using it via the API
Once AxForge deploys e5-v for you, it answers on the OpenAI-compatible API — the same base URL and keys as every other model. (e5-v below is illustrative; you get the exact model name on deployment.)
$ curl -sS https://api.axforge.ai/v1/embeddings \
-H "Authorization: Bearer $AXFORGE_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"e5-v","input":"text to embed"}'
Create an account — your API key is available in the console. 3M free tokens every 30 days with every new account.