XLM-RoBERTa
The multilingual encoder behind the multilingual-e5 models, its position numbering, and why a checkpoint's family comes from its config rather than its name.
XLM-RoBERTa is BERT's encoder with one rule changed: positions are numbered from the padding id upward instead of from zero. The multilingual-e5 base and large models, BAAI/bge-m3 and sentence-transformers/paraphrase-multilingual-mpnet-base-v2 run on it, as do two rerankers and bge-m3's sparse and multi-vector heads.
What it is
BERT's encoder, with its attention block, erf GELU, biases and weight names, over a 250002-entry SentencePiece Unigram vocabulary, with a single-row token type table and an epsilon of 1e-5. The tokenizer wraps every input in <s> and </s>, so token_count of an empty string is 2, and pads with <pad>, id 1.
How candding implements it
Position ids come from the token ids, as in the reference: the running count of non-padding ids is added to the padding id, so a row's first real token is position 2 and padding stays at 1. A real <pad> in the text is numbered as padding too, and every later token one lower than its column.
BAAI/bge-m3 publishes only a pytorch_model.bin, read tensor by tensor and slower to load than memory-mapped safetensors. Its default length costs gigabytes per layer on the matmul path, so on the CPU embed long documents one at a time; devices and dtypes has the sizes.
| Other output | Checkpoint | Loaded through | What it adds |
|---|---|---|---|
| sparse | BAAI/bge-m3 | SparseTextEmbedding | sparse_linear.pt, a relu'd Linear(1024, 1) per token, scattered by token id |
| multi-vector | BAAI/bge-m3 | MultiVectorTextEmbedding | colbert_linear.pt, a biased Linear(1024, 1024) per surviving position |
| rerank | BAAI/bge-reranker-base, BAAI/bge-reranker-v2-m3 | TextCrossEncoder | a classifier head, dense, tanh and out_proj on the <s> state, returning a raw logit |
A reranker pair is <s> query </s></s> document </s> with every token type id zero. BAAI/bge-reranker-v2-m3 has bge-m3's shape and defaults to FlagEmbedding's 512 tokens, although its tokenizer declares 8192.
Pooling and templates
| Models | Pooling | Query template | Passage template |
|---|---|---|---|
| intfloat/multilingual-e5-base, -large | mean | query: {text} | passage: {text} |
| BAAI/bge-m3 | cls | none | none |
| sentence-transformers/paraphrase-multilingual-mpnet-base-v2 | mean | none | none |
The e5 model card puts query: on both sides for tasks other than retrieval, so a symmetric comparison uses query_embed twice. None of these models has an instruction placeholder or Matryoshka support, and paraphrase-multilingual-mpnet-base-v2 ships no Normalize module.
Supported models
| Model | Family | Dim | Pooling | Max length | Dtypes | CPU | Metal | CUDA | License |
|---|---|---|---|---|---|---|---|---|---|
| intfloat/multilingual-e5-base | XLM-RoBERTa | 768 | mean | 512 | f32f16bf16 | verified | verified | verified | MIT |
| intfloat/multilingual-e5-large | XLM-RoBERTa | 1024 | mean | 512 | f32f16bf16 | verified | verified | verified | MIT |
| BAAI/bge-m3 | XLM-RoBERTa | 1024 | cls | 8192 | f32f16bf16 | verified | verified | verified | MIT |
| sentence-transformers/paraphrase-multilingual-mpnet-base-v2 | XLM-RoBERTa | 768 | mean | 128 | f32f16bf16 | verified | verified | verified | Apache-2.0 |
Dtypes: bold is the default the builder loads; plain text is verified, muted is untested, struck through is unsupported, each colored by the dtype's own Metal status so a processor-only refusal does not read as unsupported everywhere; hover a dtype for its own cpu/metal/cuda breakdown. BF16 is refused on the CPU for every row: candle has no CPU BF16 matmul.
Pitfalls
- Position ids start at the padding id plus one and come from the token ids; numbering from zero shifts every hidden state and still yields unit-length vectors.
- The single token type row is not zero, so the lookup runs on every forward.
- The epsilon is
1e-5, not BERT's1e-12; read it from the config. - A repository's
model_typedecides its family, never its name:intfloat/multilingual-e5-smalldeclaresbertand runs on BERT, andparaphrase-multilingual-mpnet-base-v2declaresxlm-robertaand runs here, not on MPNet. paraphrase-multilingual-mpnet-base-v2defaults to its repository's 128 tokens and truncates longer text silently, as the reference does.- candding and the golden references replay the published
tokenizer.json, which sentence-transformers and FlagEmbedding rebuild with a pre-tokenizer step: forintfloat/multilingual-e5-small, everyBAAI/bge-m3head andBAAI/bge-reranker-base, the two differ by one trailing token on an input whose normalized form ends in whitespace, and nowhere else. - A live
FlagRerankercall also builds a different input for an empty document; the rerank page describes that case. pooler.dense.*is in every checkpoint and never runs.