Feature Extraction
Transformers
Safetensors
sentence-transformers
Chinese
English
qwen3_5
image-text-to-text
multimodal-embedding
text-embedding
image-embedding
video-embedding
mrl
custom_code
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
| import torch | |
| import torch.nn.functional as F | |
| from transformers import Qwen3_5ForConditionalGeneration | |
| class WeMMEmbedding(Qwen3_5ForConditionalGeneration): | |
| def embedding(self, input_ids=None, attention_mask=None, **kwargs): | |
| # transformers < 5.15 reuses the rope_deltas cached by the previous multimodal | |
| # forward for a text-only one, which shifts its position ids. | |
| self.model.rope_deltas = None | |
| outputs = self.model( | |
| input_ids=input_ids, | |
| attention_mask=attention_mask, | |
| **kwargs | |
| ) | |
| last_hidden_state = outputs.last_hidden_state | |
| if attention_mask is not None: | |
| eos_positions = attention_mask.sum(dim=1) - 1 | |
| else: | |
| eos_positions = torch.full((last_hidden_state.shape[0],), last_hidden_state.shape[1] - 1, device=last_hidden_state.device) | |
| eos_positions = eos_positions.clamp(min=0) | |
| batch_indices = torch.arange(last_hidden_state.size(0), device=last_hidden_state.device) | |
| embeddings = last_hidden_state[batch_indices, eos_positions] | |
| embeddings = F.normalize(embeddings, dim=-1) | |
| return embeddings |