Instructions to use codefuse-ai/ML-Embed-0.6B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use codefuse-ai/ML-Embed-0.6B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("feature-extraction", model="codefuse-ai/ML-Embed-0.6B")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModel tokenizer = AutoTokenizer.from_pretrained("codefuse-ai/ML-Embed-0.6B") model = AutoModel.from_pretrained("codefuse-ai/ML-Embed-0.6B", device_map="auto") - sentence-transformers
How to use codefuse-ai/ML-Embed-0.6B with sentence-transformers:
from sentence_transformers import SentenceTransformer model = SentenceTransformer("codefuse-ai/ML-Embed-0.6B") 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
File size: 13,950 Bytes
c14e0f7 98f3b21 c14e0f7 98f3b21 fb82458 98f3b21 bb75a91 98f3b21 fb82458 98f3b21 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 | ---
license: apache-2.0
language:
- en
- zh
- ru
- es
- fr
- de
- ar
- nl
- vi
- hi
- ko
- ja
- it
- id
- pt
- pl
- tr
- da
- th
- sv
- fa
- uk
- cs
- 'no'
- el
- ca
- ro
- fi
- bg
- tl
- gl
- my
- hy
- km
- ne
- hu
- eu
- he
- lo
- sw
- az
- lv
- si
- sk
- tg
- et
- lt
- ms
- hr
- is
- sl
- sr
- ur
- bn
- af
- ta
- ka
- te
- ml
- mn
- nn
- kk
- cy
- mr
- sq
- nb
- mk
- jv
- kn
- eo
- la
- gu
- uz
- am
- oc
- be
- mg
- vo
- pa
- lb
- ht
- br
- ga
- xh
- tt
- bs
- yo
base_model:
- codefuse-ai/F2LLM-v2-0.6B-Preview
pipeline_tag: feature-extraction
library_name: transformers
tags:
- sentence-transformers
datasets:
- codefuse-ai/F2LLM-v2
---
# ML-Embed-0.6B
**ML-Embed-0.6B** is a multilingual text embedding model developed by CodeFuse AI and trained from Qwen3-0.6B. It is part of the ML-Embed family introduced in the ICML 2026 paper [**ML-Embed: Inclusive and Efficient Embeddings for a Multilingual World**](https://arxiv.org/abs/2605.15081).
This model is designed to be:
- strong multilingual embedding model
- fully compatible with standard Qwen3 loading/inference
- efficient to deploy, thanks to:
- **Matryoshka Layer Learning (MLL)** for layer truncation
- **Matryoshka Embedding Learning (MEL)** for factorized embedding deployment
- **Matryoshka Representation Learning (MRL)** for flexible embedding dimension truncation
The default released checkpoint is in **compatibility mode**, meaning it behaves like a standard Transformer embedding model and can be used directly with `sentence-transformers` or `transformers`.
## Model Highlights
- Base architecture: Qwen3-0.6B
- Embedding dimension: 1024
- Sequence embedding: EOS token representation
- Attention type: causal attention
- Trained in two stages (first-stage checkpiont: [codefuse-ai/F2LLM-v2-0.6B-Preview](https://huggingface.co/codefuse-ai/F2LLM-v2-0.6B-Preview))
- Supports multilingual retrieval and semantic similarity
- Supports efficient deployment with:
- fewer transformer layers
- factorized embedding matrices (`U.pth`, `V.pth`)
## Quick Start
### With Sentence Transformers
To encode text with the [Sentence Transformers](https://www.sbert.net/) library:
```python
from sentence_transformers import SentenceTransformer
model = SentenceTransformer(
"codefuse-ai/ML-Embed-0.6B",
device="cuda:0",
model_kwargs={"torch_dtype": "bfloat16"}
)
# Some sample query and documents
query = "What is ML-Embed used for?"
documents = [
"ML-Embed is a family of multilingual embedding models for retrieval, semantic search, and other NLP tasks.",
"ML-Embed is trained to produce text embeddings that work well across many languages.",
"ML-Embed 是 CodeFuse AI 开源的多语言嵌入模型。",
"ML-Embed — это многоязычная модель эмбеддингов для поиска и семантического сопоставления."
]
# Encode the query and documents separately. The encode_query method uses the query prompt
query_embedding = model.encode_query(query)
document_embeddings = model.encode_document(documents)
print(query_embedding.shape, document_embeddings.shape)
# (1024,) (4, 1024)
# Compute cosine similarity between the query and documents
similarity = model.similarity(query_embedding, document_embeddings)
print(similarity)
```
### With Transformers
Or directly with the [Transformers](https://huggingface.co/docs/transformers/index) library:
```python
from transformers import AutoModel, AutoTokenizer
import torch
import torch.nn.functional as F
model_path = "codefuse-ai/ML-Embed-0.6B"
tokenizer = AutoTokenizer.from_pretrained(model_path)
model = AutoModel.from_pretrained(
model_path,
torch_dtype=torch.bfloat16,
device_map={"": 0}
)
query = "What is ML-Embed used for?"
query_prompt = "Instruct: Given a question, retrieve passages that can help answer the question.\nQuery: "
documents = [
"ML-Embed is a family of multilingual embedding models for retrieval, semantic search, and other NLP tasks.",
"ML-Embed is trained to produce text embeddings that work well across many languages.",
"ML-Embed 是 CodeFuse AI 开源的多语言嵌入模型。",
"ML-Embed — это многоязычная модель эмбеддингов для поиска и семантического сопоставления."
]
def encode(sentences):
batch_size = len(sentences)
tokenized_inputs = tokenizer(sentences, padding=True, return_tensors="pt").to(model.device)
last_hidden_state = model(**tokenized_inputs).last_hidden_state
eos_positions = tokenized_inputs.attention_mask.sum(dim=1) - 1
embeddings = last_hidden_state[torch.arange(batch_size, device=model.device), eos_positions]
embeddings = F.normalize(embeddings, p=2, dim=1)
return embeddings
# Encode the query and documents
query_embedding = encode([query_prompt + query])
document_embeddings = encode(documents)
print(query_embedding.shape, document_embeddings.shape)
# torch.Size([1, 1024]) torch.Size([4, 1024])
# Compute cosine similarity between the query and documents
similarity = query_embedding @ document_embeddings.T
print(similarity)
```
## Prompts
The model supports custom instructions in the following format:
```text
Instruct: your_instruction
Query:
```
In general, for retrieval and reranking tasks:
- use the prompt for **queries**
- do **not** prepend the prompt to **documents/passages**
For symmetric tasks such as STS, clustering, and bitext mining, you can encode the documents either with or without prompts. The model is trained to support both scenarios.
## Efficient Deployment
ML-Embed-0.6B was trained with **3D Matryoshka Learning**, including:
- **MLL**: Matryoshka Layer Learning
- **MEL**: Matryoshka Embedding Learning
- **MRL**: Matryoshka Representation Learning
This enables multiple deployment modes.
### 1. Compatibility Mode
The default released checkpoint is a standard Qwen3-compatible model. You can load it normally with `AutoModel` or `SentenceTransformer` without any code changes (refer to the examples above).
This is the recommended option if you want the simplest integration.
### 2. Fewer-Layer Deployment with MLL
This model was trained so that **shallower versions remain useful**.
If you want to save memory or compute, you can deploy a smaller model by editing:
- `num_hidden_layers`
- `max_window_layers`
in `config.json` to a value smaller than the current one.
For example, changing both values from `28` to `16` will make `transformers` load only the first 16 layers and ignore the remaining weights.
This works automatically with the Hugging Face `transformers` library.
> Note: make sure `num_hidden_layers` and `max_window_layers` stay consistent. If you are using transformers v5, you will also need to trucate `layer_types` in the config file according to the new layer count.
### 3. Factorized Embedding Deployment with MEL
This repository also provides two additional weight files:
- `U.pth`
- `V.pth`
These correspond to the factorized embedding layer.
Instead of using the full embedding matrix, you can reconstruct token embeddings from:
$$
E \approx U V
$$
This can reduce storage and memory usage for the embedding layer, and it also allows more aggressive low-rank deployment if desired.
Below is a simple inference example adapted from the training code.
#### Inference demo using `U.pth` and `V.pth`
```python
import torch
import torch.nn.functional as F
from transformers import AutoModel, AutoTokenizer
from huggingface_hub import hf_hub_download
model_path = "codefuse-ai/ML-Embed-0.6B"
dtype = torch.bfloat16
device = "cuda"
# Load tokenizer and model
tokenizer = AutoTokenizer.from_pretrained(model_path)
model = AutoModel.from_pretrained(
model_path,
torch_dtype=dtype,
device_map={"": 0}
)
model.eval()
# Load factorized embedding weights
u_path = hf_hub_download(repo_id=model_path, filename="U.pth")
v_path = hf_hub_download(repo_id=model_path, filename="V.pth")
U = torch.load(u_path, map_location="cpu").to(dtype).to(device)
V = torch.load(v_path, map_location="cpu").to(dtype).to(device)
# Optional: choose a smaller rank for more compression
# If rank is None, use the full factorized rank
rank = None
def encode_with_factorized_embedding(sentences, rank=None):
tokenized = tokenizer(sentences, padding=True, return_tensors="pt").to(device)
input_ids = tokenized["input_ids"]
attention_mask = tokenized["attention_mask"]
if rank is None:
inputs_embeds = (U @ V)[input_ids]
else:
inputs_embeds = (U[:, :rank] @ V[:rank, :])[input_ids]
outputs = model(
inputs_embeds=inputs_embeds,
attention_mask=attention_mask
)
last_hidden_state = outputs.last_hidden_state
eos_positions = attention_mask.sum(dim=1) - 1
embeddings = last_hidden_state[torch.arange(len(sentences), device=device), eos_positions]
embeddings = F.normalize(embeddings, p=2, dim=1)
return embeddings
query = "What is ML-Embed used for?"
query_prompt = "Instruct: Given a question, retrieve passages that can help answer the question.\nQuery: "
documents = [
"ML-Embed is a family of multilingual embedding models for retrieval, semantic search, and other NLP tasks.",
"ML-Embed is trained to produce text embeddings that work well across many languages.",
"ML-Embed 是 CodeFuse AI 开源的多语言嵌入模型。",
"ML-Embed — это многоязычная модель эмбеддингов для поиска и семантического сопоставления."
]
query_embedding = encode_with_factorized_embedding([query_prompt + query], rank=rank)
document_embeddings = encode_with_factorized_embedding(documents, rank=rank)
similarity = query_embedding @ document_embeddings.T
print(similarity)
```
## Matryoshka Representation Learning
This model was also trained with MRL, which means the embedding is trained to support prefix truncation.
The full embedding size is 1024, but users may also experiment with keeping only the first `d` dimensions. This can reduce storage and speed up vector search in downstream systems. The model is trained with a smallest Matryoshka dimension of 8.
Example:
```python
embedding = embedding[..., :512]
embedding = torch.nn.functional.normalize(embedding, p=2, dim=-1)
```
> Note: you need to apply normalization **after** trucation, not the other way around.
If you are using sentence transformer, you can also simply pass `truncate_dim=512` to the encode interface.
## Training
ML-Embed-0.6B is trained in two stages from Qwen3-0.6B.
- Stage 1 includes large-scale retrieval-focused data to build strong semantic embedding capability.
- Stage 2 uses instruction-aware fine-tuning on a diverse multilingual mixture of tasks.
The model is fully open:
- Training data is available at: [`codefuse-ai/F2LLM-v2`](https://huggingface.co/datasets/codefuse-ai/F2LLM-v2)
- Training code is available at: https://github.com/codefuse-ai/CodeFuse-Embeddings/tree/main/ML-Embed
## Intended Uses
ML-Embed-0.6B can be used for:
- semantic search
- dense retrieval
- RAG pipelines
- clustering
- classification
- duplicate detection
- cross-lingual retrieval
- multilingual similarity search
## Limitations
- Performance may vary across languages, domains, and task formats.
- Benchmark performance does not guarantee optimal behavior in all production retrieval or RAG systems.
- For best embedding quality, use appropriate prompts for queries.
- Efficient modes such as fewer-layer deployment and low-rank factorized embeddings involve trade-offs between quality and efficiency.
### Citation (to be updated after the conference)
```bibtex
@misc{zhang2026mlembedinclusiveefficientembeddings,
title={ML-Embed: Inclusive and Efficient Embeddings for a Multilingual World},
author={Ziyin Zhang and Zihan Liao and Hang Yu and Peng Di and Rui Wang},
year={2026},
eprint={2605.15081},
archivePrefix={arXiv},
primaryClass={cs.CL},
url={https://arxiv.org/abs/2605.15081},
}
```
## Related models
The baseline models are released and submitted to the MTEB leaderboard under the name [`F2LLM-v2`](https://huggingface.co/collections/codefuse-ai/f2llm):
| Model | Base | Instruct |
| ----- | ----------------------------------------------------------------------------------- | ------------------------------------------------------------------- |
| 80M | | [🤗F2LLM-v2-80M](https://huggingface.co/codefuse-ai/F2LLM-v2-80M) |
| 160M | | [🤗F2LLM-v2-160M](https://huggingface.co/codefuse-ai/F2LLM-v2-160M) |
| 330M | | [🤗F2LLM-v2-330M](https://huggingface.co/codefuse-ai/F2LLM-v2-330M) |
| 0.6B | [🤗F2LLM-v2-0.6B-Preview](https://huggingface.co/codefuse-ai/F2LLM-v2-0.6B-Preview) | [🤗F2LLM-v2-0.6B](https://huggingface.co/codefuse-ai/F2LLM-v2-0.6B) |
| 1.7B | [🤗F2LLM-v2-1.7B-Preview](https://huggingface.co/codefuse-ai/F2LLM-v2-1.7B-Preview) | [🤗F2LLM-v2-1.7B](https://huggingface.co/codefuse-ai/F2LLM-v2-1.7B) |
| 4B | [🤗F2LLM-v2-4B-Preview](https://huggingface.co/codefuse-ai/F2LLM-v2-4B-Preview) | [🤗F2LLM-v2-4B](https://huggingface.co/codefuse-ai/F2LLM-v2-4B) |
| 8B | [🤗F2LLM-v2-8B-Preview](https://huggingface.co/codefuse-ai/F2LLM-v2-8B-Preview) | [🤗F2LLM-v2-8B](https://huggingface.co/codefuse-ai/F2LLM-v2-8B) |
| 14B | [🤗F2LLM-v2-14B-Preview](https://huggingface.co/codefuse-ai/F2LLM-v2-14B-Preview) | [🤗F2LLM-v2-14B](https://huggingface.co/codefuse-ai/F2LLM-v2-14B) | |