Instructions to use tencent/WeMM-Embedding-4B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use tencent/WeMM-Embedding-4B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("feature-extraction", model="tencent/WeMM-Embedding-4B", trust_remote_code=True)# Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("tencent/WeMM-Embedding-4B", trust_remote_code=True) model = AutoModelForMultimodalLM.from_pretrained("tencent/WeMM-Embedding-4B", trust_remote_code=True, device_map="auto") - sentence-transformers
How to use tencent/WeMM-Embedding-4B with sentence-transformers:
from sentence_transformers import SentenceTransformer model = SentenceTransformer("tencent/WeMM-Embedding-4B", trust_remote_code=True) sentences = [ "The weather is lovely today.", "It's so sunny outside!", "He drove to the stadium." ] embeddings = model.encode(sentences) similarities = model.similarity(embeddings, embeddings) print(similarities.shape) # [3, 3] - Notebooks
- Google Colab
- Kaggle
Integrate with Sentence Transformers, restore training-time tokenization on newer transformers
Hello @JUNJIE99 @kekekeke @xiaoxiaoshadiao and team!
As a heads up, this PR is AI-generated but human-reviewed.
Pull Request overview
- Integrate WeMM-Embedding-4B with Sentence Transformers v5.7+ via
modules.jsonandtrust_remote_code - Restore the training-time tokenization on
transformersnewer than the pinned 5.2.0
Details
This is the sister PR of the https://huggingface.co/tencent/WeMM-Embedding-2B/discussions/1, with the same changes to transformers and Sentence Transformers integration, but for the 4B model. See that PR description for more details.
You can test the Sentence Transformers integration with the following snippet:
from sentence_transformers import SentenceTransformer
model_id = "tencent/WeMM-Embedding-4B"
model = SentenceTransformer(model_id, trust_remote_code=True)
queries = [
"Which Llama 4 model variants are available?",
"How is mapo tofu prepared?",
]
documents = [
"Mapo tofu is a Sichuan dish of soft tofu simmered in a spicy, numbing sauce of chili bean paste and Sichuan peppercorn.",
{
"image": "https://huggingface.co/datasets/sentence-transformers/example-documents/resolve/main/llama4_hgf.png",
"text": "Represent this image.",
},
{
"video": "https://huggingface.co/datasets/sentence-transformers/example-documents/resolve/main/mapo_tofu.mp4",
"text": "Represent this video.",
},
]
query_embeddings = model.encode_query(queries)
document_embeddings = model.encode_document(documents)
print(query_embeddings.shape, document_embeddings.shape)
# (2, 2560) (3, 2560)
similarities = model.similarity(query_embeddings, document_embeddings)
print(similarities)
# tensor([[ 0.0713, 0.4782, -0.0742],
# [ 0.7497, 0.0909, 0.4030]])
To try it before merging, load the PR revision:SentenceTransformer(model_id, revision="refs/pr/1", trust_remote_code=True).
Happy to tweak anything you'd like changed. Please let me know if you have any questions or feedback!
- Tom Aarsen
Thanks for the PR!