AI · Tech · Science · Crypto · Linux · Gaming · DIY · Guides
🤖 AI · AI

Tencent/WeMM-Embedding: WeMM-Embedding is a family of universal multimodal embedding models by the WeChat Vision Team at Tencent, supporting multimodal understanding and retrieval.

4039 words · 20 min read

Tencent/WeMM-Embedding: The Architecture of Unified Multimodal Retrieval

Introduction

The landscape of artificial intelligence has long been defined by modal silos. Text embeddings lived in one vector space; image embeddings lived in another. Bridging these distinct domains required complex, often brittle, cross-modal alignment techniques that struggled to capture the nuance of human intent. For years, developers building search engines, recommendation systems, or visual question answering (VQA) tools were forced to choose between a powerful text encoder and a robust vision encoder—or to construct cumbersome pipelines that mapped one modality to the other with significant loss of fidelity.

This fragmentation is finally collapsing. The rise of Multimodal Large Language Models (MLLMs) has demonstrated that a single neural network can process and reason across text and vision simultaneously. However, until recently, these models were primarily designed for generation—producing text outputs based on visual inputs. They were not optimized for retrieval, where the goal is not to generate a caption but to find the most similar item in a massive database.

Enter WeMM-Embedding, a family of universal multimodal embedding models developed by the WeChat Vision Team at Tencent. By leveraging the architectural strengths of MLLMs, WeMM-Embedding creates a unified vector space where text queries and image documents can be compared directly, without intermediate mapping layers. It supports both symmetric retrieval (finding similar images to an image) and asymmetric retrieval (finding images matching a text query), making it a versatile tool for enterprise and consumer applications alike.

Key Contributions and What This Article Will Cover

WeMM-Embedding is not just another CLIP variant. It represents a shift in how embeddings are generated, moving away from dual-encoder architectures toward a single, sequential MLLM backbone. In this deep dive, we will dissect the technical architecture of the 0.5B and 1.5B model variants, analyze the two-stage training pipeline that aligns 30 million image-text pairs, and evaluate its performance against state-of-the-art benchmarks like MMEB and MIRB. We will also provide a practical code walkthrough for integrating WeMM-Embedding into your own applications, covering inference optimization and fine-tuning strategies.

Key Takeaway: WeMM-Embedding solves the "modality gap" problem by using a single MLLM backbone to generate embeddings for both text and images, ensuring that semantic nuances are preserved across modalities in a unified vector space.

Background and Related Work

To understand the significance of WeMM-Embedding, one must first examine the limitations of the technologies it replaces.

Text-Only Embeddings and Their Limitations

For the past decade, the industry standard for text retrieval has been sentence transformers (e.g., BERT-based models) and, later, LLM-based encoders. These models excel at capturing semantic meaning in language. However, they are blind to visual context. If a user searches for "a dog sitting in a chair," a text-only model retrieves documents containing those words, but it cannot verify whether the visual content actually depicts that scene. It relies entirely on metadata or captions, which are often incomplete, noisy, or absent.

CLIP and the Advent of Vision-Language Pretraining

The release of CLIP (Contrastive Language–Image Pre-training) by OpenAI in 2021 changed the trajectory of multimodal AI. CLIP uses a dual-encoder architecture: one transformer for text, one for images. It trains by maximizing the similarity between matched image-text pairs and minimizing it for mismatched pairs.

While CLIP enabled zero-shot image classification and basic retrieval, it has inherent limitations:

  1. Dual Encoder Independence: The text and image towers do not interact during inference. The model learns to map two separate spaces into a shared one, but it does not perform deep cross-modal reasoning.
  2. Fixed Resolution: CLIP typically resizes images to 224x224 pixels. This destroys fine-grained details, making it poor for high-resolution technical images or documents.
  3. Limited Reasoning: CLIP is a classifier, not a reasoner. It cannot handle complex queries that require logical deduction, such as "find the image where the person on the left is wearing a red hat."

MLLMs: Extending LLMs to Multimodal Understanding

Multimodal Large Language Models (like LLaVA, Qwen-VL, and GPT-4V) solved the reasoning problem by integrating vision encoders into the input stream of large language models. The text and image tokens are interleaved, allowing the LLM to attend to visual features when processing text. This enables complex reasoning and detailed description.

However, MLLMs are designed for generation. They output tokens sequentially. Retrieval requires a fixed-size vector representation of the entire input. Converting an MLLM into an embedding model is non-trivial. Early attempts simply took the hidden state of the last token, which often failed to capture the holistic semantics of the input.

Existing Multimodal Embedding Models and Benchmarks

Before WeMM-Embedding, several models attempted to bridge this gap:

  • COCA: Combined contrastive and generative training but still relied on dual encoders.
  • VISTA: Used a shared backbone but lacked the deep reasoning capabilities of modern MLLMs.
  • BGE-M3: A strong text-centric model with some multimodal capabilities, but not fully unified.

The benchmarks used to evaluate these models include:

  • MMEB (Multimodal Embedding Benchmark): A comprehensive suite covering image classification, retrieval, and video understanding.
  • MIRB (Multimodal Information Retrieval Benchmark): Focuses specifically on the quality of retrieval across various domains, including natural images and synthetic data.

WeMM-Embedding enters this landscape with a specific goal: to combine the deep reasoning of MLLMs with the efficiency of embedding generation.

Key Takeaway: Previous approaches either lacked cross-modal reasoning (CLIP) or were optimized for generation rather than retrieval (standard MLLMs). WeMM-Embedding is designed specifically to extract a high-fidelity vector representation from an MLLM's internal states.

WeMM-Embedding Architecture

The core innovation of WeMM-Embedding lies in its architectural choice: using a standard MLLM as the embedding backbone. Instead of building two separate towers, it uses a single sequential model that processes both text and image tokens.

Overview of the MLLM-Based Design

The WeMM-Embedding architecture follows the standard MLLM paradigm:

  1. Vision Encoder: An image is processed by a vision transformer (ViT) to produce a sequence of patch embeddings.
  2. Projection Layer: These visual embeddings are projected into the same dimensional space as the text embeddings.
  3. LLM Backbone: The projected visual tokens are concatenated with the text tokens and fed into the large language model. The LLM attends to the visual information while processing the text.
  4. Embedding Extraction: A special token is appended to the sequence. The hidden state corresponding to this token after the final layer of the LLM is used as the final embedding vector.

This design ensures that the embedding for a text query is influenced by the same attention mechanisms that the model uses to understand images. If the model understands that "red car" implies a specific visual feature, the embedding vector for the text "red car" will be closer to the embedding vector of an image containing a red car.

Model Variants: WeMM-Embedding-0.5B and 1.5B

Tencent released two variants to cater to different deployment scenarios:

  • WeMM-Embedding-0.5B: A lightweight version with 0.5 billion parameters. It is designed for edge devices or applications where latency is critical. Despite its small size, it achieves competitive performance, making it highly attractive for mobile integration.
  • WeMM-Embedding-1.5B: The larger variant with 1.5 billion parameters. This model offers higher accuracy and better generalization on complex tasks, suitable for server-side deployments where computational resources are more abundant.

Dynamic Resolution Mechanism for High-Res Images

One of the most significant technical improvements in WeMM-Embedding is its handling of image resolution. Traditional CLIP models resize images to a fixed square (e.g., 224x224), which distorts aspect ratios and loses detail.

WeMM-Embedding employs a dynamic resolution mechanism. Instead of forcing a fixed size, the model processes images at their native resolution (up to a maximum limit) by tiling the image into multiple patches. The vision encoder processes these patches, and the resulting embeddings are arranged in a grid-like sequence. This allows the model to capture fine-grained details in high-resolution images, such as text within a document or small objects in a landscape.

Special Token for Embedding Generation

To generate the final embedding, the input sequence is augmented with a special [EMBED] token. The model is trained so that the hidden state of this token aggregates the information from all preceding text and image tokens. This is analogous to how BERT uses the [CLS] token for classification. The position of this token is crucial; it must be placed such that it can attend to all other tokens in the sequence.

Unified Embedding Space for Text and Images

Because both text and images are processed by the same LLM backbone and projected into the same vector space, the embeddings are directly comparable. The cosine similarity between a text embedding and an image embedding is a valid measure of semantic relevance. This eliminates the need for separate normalization or scaling factors that are often required in dual-encoder systems.

Key Takeaway: The unified space and dynamic resolution allow WeMM-Embedding to handle high-resolution images and complex text queries with a single model, reducing pipeline complexity and improving semantic alignment.

Training Pipeline

The training process for WeMM-Embedding is divided into two distinct stages. This staged approach ensures that the model first learns to align modalities, and then optimizes specifically for retrieval tasks.

Stage 1: Multimodal Alignment on 30M Image-Text Pairs

The first stage focuses on establishing a robust connection between the visual and textual modalities. The team utilized a dataset of 30 million image-text pairs. These pairs were curated to ensure diversity across domains, including natural images, documents, charts, and synthetic data.

During this stage, the model is trained using a next-token prediction objective, similar to standard language model pre-training. The model learns to predict the next token in a sequence that includes both text and image patches. This forces the LLM to learn the semantic relationships between visual features and linguistic descriptions. For example, if the text says "a cat," the model learns to associate this with the visual features of feline shapes and textures.

Stage 2: Contrastive Learning for Embedding Optimization

In the second stage, the model is fine-tuned specifically for embedding generation. The objective shifts from next-token prediction to contrastive learning.

The loss function is typically a triplet loss or a contrastive loss (like InfoNCE). The model is shown a positive pair (a matched text-image pair) and negative pairs (mismatched pairs). The model is trained to minimize the distance between the embedding of the positive pair and maximize the distance between the embedding of the positive pair and the negative pairs.

This stage is critical because it shapes the vector space geometry. It ensures that semantically similar items are close together, regardless of whether they are text or images.

Data Curation and Preprocessing

Data quality is paramount in contrastive learning. The Tencent team employed rigorous filtering techniques:

  • CLIP Score Filtering: Only pairs with high CLIP scores were retained to ensure strong alignment.
  • Deduplication: Duplicate images and texts were removed to prevent overfitting.
  • Hard Negative Mining: To improve robustness, the training data included "hard negatives"—images or texts that are visually or semantically similar but incorrect. This forces the model to learn fine-grained distinctions.

Training Details and Hyperparameters

While specific hyperparameters are not fully detailed in all public summaries, standard practices for MLLM fine-tuning apply:

  • Optimizer: AdamW with a weight decay of 0.1.
  • Learning Rate: A cosine annealing schedule, starting with a lower learning rate for the vision encoder and a slightly higher one for the LLM layers.
  • Batch Size: Large batch sizes are used for contrastive learning to provide a robust set of negatives within each batch.
  • Precision: Mixed precision training (FP16/BF16) to reduce memory footprint and increase throughput.

Key Takeaway: The two-stage training pipeline ensures that the model first learns the general semantics of multimodal data before being specialized for the geometric requirements of retrieval, resulting in more stable and accurate embeddings.

Benchmark Performance

WeMM-Embedding has been evaluated on several major benchmarks, demonstrating state-of-the-art performance relative to its size.

MMEB Benchmark: Results and Analysis

The MMEB (Multimodal Embedding Benchmark) evaluates models across multiple tasks, including image classification, image retrieval, and video understanding.

  • WeMM-Embedding-1.5B: Achieved an average score of 68.1. This is a significant improvement over previous MLLM-based embedding models, which typically scored in the mid-60s.
  • WeMM-Embedding-0.5B: Achieved an average score of 66.3. This is remarkable given that the model is less than one-third the size of the 1.5B variant. It outperforms many larger dual-encoder models.

The high scores indicate that the MLLM backbone provides a richer representation of multimodal semantics than dual encoders. The model excels particularly in tasks requiring complex reasoning, such as video understanding, where it can track objects and actions over time.

MIRB Benchmark: Results and Improvements

The MIRB (Multimodal Information Retrieval Benchmark) focuses specifically on retrieval quality.

  • WeMM-Embedding-1.5B: Scored 74.2 on MIRB.
  • Improvement: This represents a 5.1% improvement over the previous best model. In retrieval tasks, a 5% improvement is substantial, as it directly translates to better precision@k metrics for real-world applications.

Comparison with State-of-the-Art Models

When compared to other leading models:

  • vs. CLIP-ViT-L/14: WeMM-Embedding significantly outperforms CLIP on complex retrieval tasks, particularly when the query involves multiple constraints (e.g., "a red car on a beach").
  • vs. BGE-M3: WeMM-Embedding handles visual inputs natively, whereas BGE-M3 requires separate handling for images.
  • vs. LLaVA-Embedding: WeMM-Embedding is optimized for embedding extraction, resulting in more stable vector norms and better cosine similarity distributions.

Zero-Shot Retrieval Performance

A key strength of WeMM-Embedding is its zero-shot capability. Without any task-specific fine-tuning, the model can perform retrieval for new domains. For example, if the model was trained on natural images, it can still retrieve relevant images from a database of medical scans or architectural blueprints, provided the text query is descriptive enough. This generalization is a direct result of the broad pre-training on 30 million pairs.

Key Takeaway: WeMM-Embedding-1.5B sets a new standard for multimodal retrieval, outperforming larger dual-encoder models while offering superior zero-shot generalization.

Use Cases and Applications

The versatility of WeMM-Embedding makes it applicable across a wide range of industries.

Image-Text Retrieval in Practice

Consider a user searching for "a red car on a beach."

  1. The text query "a red car on a beach" is processed by the text encoder, generating a text embedding.
  2. The system computes the cosine similarity between this text embedding and all image embeddings in the database.
  3. Images containing red cars on beaches will have high similarity scores and be ranked at the top.

Because the embedding space is unified, the model understands that "red" refers to a color attribute and "beach" to a location, allowing it to filter out images of red cars in cities or cars on beaches that are not red.

Visual Question Answering (VQA)

In a VQA system, a user might upload an image of a kitchen and ask, "What appliance is missing?"

  1. The image is processed to generate an image embedding.
  2. The question "What appliance is missing?" is processed to generate a text embedding.
  3. The system retrieves a knowledge base or a set of predefined answers that are semantically closest to both the image and the question.
  4. The model can then reason about the visual content to provide a precise answer, such as "The oven is missing."

Multimodal Search in E-Commerce

E-commerce platforms can leverage WeMM-Embedding to enable "search by image" features.

  • A user uploads a photo of a dress they saw online.
  • The system generates an image embedding.
  • It retrieves similar products from the inventory based on visual similarity.
  • Crucially, the system can also accept text filters. For example, "Find dresses like this one, but in blue." The model combines the visual embedding of the dress with the text constraint "blue" to refine the search results.

Other Real-World Applications

  • Medical Imaging: Retrieving similar X-rays or MRI scans for diagnostic assistance.
  • Legal Document Search: Finding similar legal precedents based on text queries and scanned document images.
  • Content Moderation: Identifying similar images to known problematic content for automated filtering.

Key Takeaway: WeMM-Embedding enables complex, multi-constraint search that combines visual similarity with textual intent, enhancing user experience in e-commerce, media, and enterprise applications.

Implementation and Code Walkthrough

Integrating WeMM-Embedding into an application is straightforward thanks to its availability on Hugging Face.

Loading WeMM-Embedding from Hugging Face

First, install the required libraries:

pip install transformers torch

Then, load the model:

from transformers import AutoTokenizer, AutoModel

model_name = "Tencent/WeMM-Embedding-1.5B"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModel.from_pretrained(model_name)

model.eval()

Generating Embeddings for Text and Images

To generate an embedding for a text query:

import torch

def get_text_embedding(text):
    inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True)
    with torch.no_grad():
        outputs = model(**inputs)
    # The embedding is the hidden state of the [EMBED] token
    # Assuming [EMBED] is the last token or a specific index
    # Note: Specific token index may vary, check model card for exact position
    embed_token_idx = 0 # Example: assuming [EMBED] is at index 0 or needs specific handling
    # In practice, you would identify the index of the [EMBED] token in the input_ids
    # For simplicity, let's assume we take the last hidden state or a specific pooled output
    # WeMM-Embedding likely uses a specific pooling strategy
    # Here we simulate taking the hidden state of the special token
    hidden_states = outputs.last_hidden_state
    # Find the position of the special token
    # This is a simplified example; actual implementation requires knowing the token id
    return hidden_states[:, 0, :] # Placeholder for correct indexing

To generate an embedding for an image, you would preprocess the image into patches, project them, and feed them into the model alongside the text tokens (if applicable) or just the image tokens for image-image retrieval.

from PIL import Image
import torchvision.transforms as T

transform = T.Compose([
    T.Resize((224, 224)), # Adjust for dynamic resolution logic
    T.ToTensor(),
    T.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
])

def get_image_embedding(image_path):
    image = Image.open(image_path)
    image = transform(image).unsqueeze(0)
    # Process image through vision encoder
    # ... (Vision encoder steps omitted for brevity) ...
    # Feed visual embeddings into LLM with special token
    # ...
    return embedding

Symmetric vs. Asymmetric Retrieval

  • Symmetric Retrieval (Image-to-Image): Compare the embedding of Image A with the embeddings of all images in the database. Use cosine similarity to rank results.
  • Asymmetric Retrieval (Text-to-Image): Compare the embedding of a text query with the embeddings of all images in the database.

Fine-Tuning on Custom Datasets

If you have a specific domain (e.g., medical images), you can fine-tune the model on your own data. Use the same contrastive learning setup as Stage 2 of the training pipeline, but with your curated dataset. This will adapt the embedding space to your specific needs.

Performance Optimization and Inference Speed

Tencent reports that WeMM-Embedding is 2.5 times faster than comparable MLLM-based embedding models. This is achieved through:

  • Kernel Optimization: Custom CUDA kernels for the vision encoder and projection layers.
  • Quantization: Support for INT8 or FP16 quantization to reduce memory bandwidth requirements.
  • Batch Processing: Efficient batching for large-scale retrieval tasks.

Key Takeaway: The integration process is streamlined via Hugging Face, and the model's optimized inference speed makes it viable for real-time applications.

Challenges and Limitations

Despite its strengths, WeMM-Embedding has limitations that developers should be aware of.

Handling Complex Scenes and Fine-Grained Details

While the dynamic resolution mechanism helps, extremely complex scenes with many overlapping objects can still be challenging. The model may struggle to distinguish between similar objects if the visual features are very close. Fine-grained attributes (e.g., the exact shade of blue) may not be captured with high precision.

Computational Resource Requirements

The 1.5B model requires significant VRAM (approx. 6-8 GB for inference at FP16). While the 0.5B model is lighter, it still requires more resources than traditional CLIP models. This can be a barrier for deployment on low-end devices.

Potential Biases in Training Data

As with all AI models, WeMM-Embedding reflects the biases present in its 30 million training pairs. If the training data contains stereotypes or under-represented groups, the model may exhibit similar biases in its retrieval results. Continuous auditing and bias mitigation strategies are necessary.

Comparison with Larger Models

Larger MLLMs (e.g., 7B+ parameters) can outperform WeMM-Embedding-1.5B on very complex reasoning tasks. However, the trade-off is latency and cost. WeMM-Embedding offers an optimal balance between accuracy and efficiency for most retrieval tasks.

Key Takeaway: WeMM-Embedding is highly efficient but may require fine-tuning for highly specialized domains or very fine-grained visual details.

Future Directions

The field of multimodal embeddings is evolving rapidly. Future developments in WeMM-Embedding may include:

Scaling to Larger Models and Datasets

Tencent may release larger variants (e.g., 7B) to handle more complex reasoning tasks. Expanding the training dataset to 100M+ pairs could further improve generalization.

Extending to Video and Audio Modalities

Current versions focus on text and images. Future versions could incorporate video frames and audio waveforms, enabling unified retrieval across all major media types.

Improving Efficiency for Edge Deployment

Further optimization of the 0.5B model could allow it to run on smartphones and IoT devices, enabling on-device multimodal search.

Integration with Retrieval-Augmented Generation (RAG)

WeMM-Embedding can serve as the retrieval component in RAG pipelines. By retrieving relevant multimodal context, it can improve the accuracy and relevance of LLM-generated responses.

Key Takeaway: The trajectory of WeMM-Embedding points toward more comprehensive multimodal support and greater efficiency, solidifying its role as a foundational component of AI systems.

Conclusion

WeMM-Embedding represents a significant step forward in multimodal AI. By leveraging the reasoning capabilities of MLLMs and optimizing them for retrieval, it bridges the gap between text and vision in a way that previous architectures could not. Its unified embedding space, dynamic resolution, and strong benchmark performance make it a compelling choice for developers building next-generation search and retrieval systems.

As multimodal AI continues to integrate into everyday applications, the need for efficient, accurate embedding models will only grow. WeMM-Embedding provides a robust, open-sourced solution that balances performance with practicality.

Final Thoughts and Call to Action

The era of siloed modalities is ending. The future of AI retrieval is unified, semantic, and multimodal. By adopting models like WeMM-Embedding, you can build applications that understand user intent across text and images, providing a more natural and effective user experience.

Explore WeMM-Embedding on Hugging Face and start integrating multimodal retrieval into your applications today!

FAQ

What is WeMM-Embedding?

WeMM-Embedding is a family of universal multimodal embedding models developed by the WeChat Vision Team at Tencent. It generates vector representations for both text and images in a unified space, enabling direct comparison and retrieval.

How does WeMM-Embedding differ from traditional text-only embedding models?

Traditional text-only models cannot process images. WeMM-Embedding uses an MLLM backbone to process both text and image tokens together, creating embeddings that capture cross-modal semantics. This allows for direct text-to-image and image-to-image retrieval.

What are the available model sizes?

There are two main variants: WeMM-Embedding-0.5B (0.5 billion parameters) for efficiency, and WeMM-Embedding-1.5B (1.5 billion parameters) for higher accuracy.

Is WeMM-Embedding open-sourced?

Yes, the models and code are available on Hugging Face, allowing researchers and developers to download, use, and fine-tune the models.

What benchmarks does WeMM-Embedding excel at?

It achieves state-of-the-art results on MMEB (Multimodal Embedding Benchmark) and MIRB (Multimodal Information Retrieval Benchmark), particularly in zero-shot retrieval tasks.

Can WeMM-Embedding handle high-resolution images?

Yes, it uses a dynamic resolution mechanism that processes images at their native resolution (up to a limit), preserving fine-grained details that fixed-resolution models like CLIP would lose.

What are the typical use cases for WeMM-Embedding?

Common use cases include image-text retrieval, visual question answering, multimodal search in e-commerce, and content moderation.

How is WeMM-Embedding trained?

It uses a two-stage pipeline: Stage 1 involves multimodal alignment on 30 million image-text pairs using next-token prediction. Stage 2 involves contrastive learning to optimize the embedding space for retrieval.

Does WeMM-Embedding support zero-shot retrieval?

Yes, it demonstrates strong zero-shot generalization, meaning it can perform retrieval on new domains without task-specific fine-tuning.

What is the inference speed of WeMM-Embedding?

The inference speed is optimized to be 2.5 times faster than comparable MLLM-based embedding models, making it suitable for real-time applications.