Skip to content

Training Sparse Mixture Of Experts Text Embedding Models

optionalcorefrontierpaperrubric 10/122025 · ~35 min

Zach Nussbaum, Brandon Duderstadt

Status

TL;DR. Nomic Embed v2 is a multilingual embedder built by turning every second MLP of an extended XLM-R base encoder into a mixture-of-experts (MoE) layer with 8 experts and top-2 routing. It holds 475M parameters but uses 305M per token. Trained on 1.6B filtered pairs and fine-tuned with margin-filtered hard negatives, it reaches 52.86 nDCG@10 on BEIR and 65.80 on MIRACL. All code, models and evaluation data are released.

Why it matters now. Multilingual embedders usually buy English quality back by growing larger, which raises encoding cost and memory for every RAG index refresh. This paper tests a different lever: more capacity at roughly constant compute per token. It also contains one of the clearest public ablations of hard-negative mining (teacher model, margin, number of negatives). Read it as a diff against Nomic Embed v1.

The pipeline follows v1, with three changes.

  1. A long-context multilingual backbone (mNomic-BERT). XLM-R base gets RoPE (base 10,000) in place of absolute positions and is trained for 10,000 MLM steps on 2048-token CC100 segments with language sampling temperature 0.3. GLUE and XTREME-R stay close to XLM-R base (81.63 vs 82.35 GLUE; 62.70 vs 62.31 XTREME-R), using about 3% of mGTE-base’s pretraining steps.
  2. Upcycling to MoE, then contrastive pretraining. Starting at layer 2, every second MLP becomes an MoE block. A router assigns each token to its top 2 of 8 experts, and an auxiliary loss keeps traffic balanced:
Lbalance=α∑i=1Eri pi,\mathcal{L}_{\text{balance}} = \alpha \sum_{i=1}^{E} r_i\, p_i ,

where rir_i is the fraction of tokens routed to expert ii, pip_i its mean router probability, and α=1\alpha = 1. The loss is smallest when both are spread evenly. The model then trains with InfoNCE (τ=0.02\tau = 0.02, batch 16,384, one dataset per batch) on 1.6B pairs: v1’s filtered English data plus mC4 and multilingual CC-News, consistency-filtered per language with multilingual-E5-small (keep a pair if its document is in the query’s top 2 within 1M-example shards). Queries are cut to 32 tokens and documents to 256 for cost. Training uses 16 H100s. 3. Fine-tuning with positive-aware negatives and Matryoshka dimensions. Each query gets 10 hard negatives, accepted only if their teacher similarity is below a margin of the positive’s:

accept d−  ⟺  s(q,d−)<0.95⋅s(q,d+).\text{accept } d^- \iff s(q, d^-) < 0.95 \cdot s(q, d^+) .

This rule, from NV-Retriever, drops candidates that score almost as high as the positive, since many of those are unlabelled positives. Fine-tuning also uses Matryoshka representation learning, so 768-dim vectors can be cut to 256.

Nomic Embed v2: upcycling every other MLP of a 12-layer encoder into an 8-expert, top-2 mixture of experts Left: a stack of twelve encoder layers in which layers 2, 4, 6, 8, 10 and 12 have their MLP replaced by a mixture-of-experts block. Right top: inside one such block, a router scores eight experts for each token and sends the token to the two highest-scoring experts, whose outputs are combined with the router weights; an auxiliary load-balancing loss keeps traffic even. Right bottom: parameter accounting showing about 278 million dense parameters plus about 198 million extra expert parameters gives 475 million total, while each token uses about 305 million. Encoder (XLM-R base + RoPE) L1 · dense MLP L2 · MoE: 8 experts, top-2 L3 · dense MLP L4 · MoE L5 · dense MLP L6 · MoE L7 · dense MLP L8 · MoE L9 · dense MLP L10 · MoE L11 · dense MLP L12 · MoE attention layers stay dense Inside one MoE layer, per token token state h router: softmax over 8 E1 E2 E3 E4 E5 E6 E7 E8 output = g₃·E₃(h) + g₆·E₆(h), the top-2 router weights aux loss α·Σ rᵢ·pᵢ (α = 1) pushes traffic towards even Parameter accounting (our arithmetic) one expert MLP ≈ 2 · 768 · 3072 ≈ 4.7M weights dense XLM-R base ≈ 278M + 6 layers × 7 extra experts ≈ +198M → 475M total per token: 278M + 6 × 1 extra expert ≈ 305M active
Original sketch. Only the MLPs of alternate layers become experts; attention stays dense. The parameter accounting is our arithmetic and matches the paper's 475M total and 305M active.

All numbers are paper-reported, nDCG@10, inputs truncated to 512 tokens, evaluated with FlagEmbedding (mE5 numbers copied from its paper).

ModelParams (paper’s count)DimBEIRMIRACL
Nomic Embed v2305M active (475M total)76852.8665.80
mGTE base305M76851.1063.40
Arctic Embed v2 base305M76855.4059.90
mE5 base278M76848.8862.30
BGE-M3568M102448.8069.20
mE5 large560M102451.4066.50
Arctic Embed v2 large568M102455.6566.00
  • In its size class, Nomic v2 trails only Arctic Embed v2 base on BEIR (52.86 vs 55.40) and leads on MIRACL. The authors note that Arctic’s training data is not released and is largely private web-search data.
  • Hard-negative ablation (Table 8, starting from E5-large unsupervised and evaluated on NQ, FiQA and HotpotQA): Arctic-Embed-Large teacher with no margin gives 52.87; with margin 0.95, 55.20; NV-Embed v1 teacher 54.94; Stella 1.5B teacher 57.22 (57.45 with 10 negatives). Margin 0.95 vs 0.98 barely matters.
  • No latency or throughput measurements are reported. The efficiency claim rests on active-parameter counts.
  • Efficiency is argued, not measured. MoE serving cost depends on kernels and batching; the paper reports active parameters, not wall-clock encoding throughput or memory.
  • MIRACL may not be zero-shot. Fine-tuning negatives come from the data released with BGE-M3, whose fine-tuning set includes MIRACL and Mr. TyDi training data. The paper does not separate this.
  • No routing analysis. We do not learn whether experts specialise by language, script or domain.
  • Short training inputs. Pretraining truncates documents to 256 tokens, so the 2048-token backbone is not exploited for long-document retrieval, and long-context evaluation is absent.

Questions to think through

These questions have no single right answer. Write or say your answer before you open the hints. Mark a question once you could defend your answer in a reading group.

  1. Derive / compute

    Nomic Embed v2 starts from XLM-R base (≈ 278M parameters, 12 layers, hidden 768, MLP inner size 3072) and turns layers 2, 4, …, 12 into MoE layers with 8 experts and top-2 routing, each expert a copy of the original MLP. (a) Reproduce the reported 475M total and 305M active parameters. (b) For a separate top-1 toy router with eight experts, where rᵢ is the fraction of tokens sent to expert i and pᵢ its mean router probability, compute the load-balancing loss α·Σ rᵢ·pᵢ with α = 1 for perfectly even routing and for total collapse onto one expert. (c) For 100M passages in fp32, compute index size at the 768 and 256 Matryoshka dimensions.

    What a strong answer covers
    • (a) One MLP ≈ 2 · 768 · 3072 ≈ 4.7M weights. Six MoE layers each add 7 extra experts: 6 · 7 · 4.7M ≈ 198M, so 278M + 198M ≈ 476M ≈ 475M total. Top-2 means one extra expert per MoE layer is active: 278M + 6 · 4.7M ≈ 306M ≈ 305M.
    • Router weights (768 × 8 per layer) are negligible. Attention, embeddings and the other six MLPs are shared by every token.
    • (b) Top-1 toy router. Even routing: rᵢ = pᵢ = 1/8, so Σ = 8 · 1/64 = 1/8 = 0.125. Collapse: r = p ≈ 1 for one expert, so the loss ≈ 1. The gradient pushes probability mass away from overloaded experts. (Under Nomic's actual top-2 routing, balanced dispatch gives rᵢ = 2/8 and Σ rᵢ = 2, so the balanced value is 0.25 unless counts are normalised by k; do not mix the two conventions.)
    • (c) 100M · 768 · 4 B ≈ 307 GB; at 256 dims ≈ 102 GB, a 3× saving. The index cost depends on the embedding dimension, not on the 475M total parameters.
  2. Mechanism

    In the paper's multilingual ablation, the MoE model underperformed its dense counterpart when trained on 100M contrastive pairs but beat it on the larger mix. Using how sparse upcycling initialises experts and how many tokens each expert sees, explain why an MoE embedder needs more data than a dense one before the extra capacity pays off.

    What a strong answer covers
    • Upcycling copies the dense MLP into all 8 experts, so at the start the MoE layer computes the same function as the dense model. Gains only appear once experts diverge and specialise.
    • With top-2 of 8 routing, each expert receives roughly a quarter of the tokens a dense MLP would, so each expert gets fewer gradient updates per epoch.
    • The router also has to learn a useful partition, for example by language or domain. Early on, with identical experts, its choices carry little signal, and the balancing loss pulls against routing that is too uneven.
    • This matches the paper's citation of Krajewski et al.: MoE models tend to underperform dense ones in limited-training regimes.
  3. What if…

    Table 7 (monolingual, Switch routing k = 1) and Table 9 (multilingual) vary how many layers are upcycled, the routing k and the batch size. Summarise what each ablation shows and explain why the multilingual MoE does not reach XLM-R Large while the monolingual MoE roughly reaches BERT Large.

    What a strong answer covers
    • Table 7: converting 6 of 12 layers beats converting all 12 at batch 4,096 and 8,192 (BEIR 45.36 vs 44.89, 45.89 vs 45.48). More expert layers mean more unstable routing for little extra benefit.
    • Table 9 at batch 8,192: XLM-R Large 46.91 BEIR / 42.71 MIRACL; MoE k = 2 45.00 / 39.81; MoE k = 1 44.11 / 39.17; dense base 43.96 / 37.92. MoE beats the dense base but not the large model.
    • Multilingual training splits capacity across languages ("curse of multilinguality"), and XLM-R Large has more attention and embedding capacity that MoE layers do not add, since only the MLPs are expanded.
    • The multilingual ablation uses only six languages and about 300M pairs, so the gap may shrink at the full 1.6B-pair scale; the paper does not run that comparison.
  4. Critique

    Table 1 compares Nomic Embed v2 (305M active) with BGE-M3 and mE5-large (≈ 560M) and claims competitiveness with models twice its size. Identify two threats to validity in this comparison, one about parameter counting and one about the MIRACL training data, and propose a fairer protocol.

    What a strong answer covers
    • Counting: the 305M is active parameters. The model still holds 475M weights in memory. Latency and throughput were not measured in the paper, so "half the size" is about FLOPs per token, not about measured serving cost.
    • Data: Nomic v2 mines and filters its fine-tuning negatives with the data released with BGE-M3, and BGE-M3's fine-tuning set includes MIRACL and Mr. TyDi training data. MIRACL may therefore be in-domain for both models; that weakens a zero-shot reading.
    • Protocol: report measured encoding throughput and peak memory at matched batch and length, and evaluate on multilingual sets with no training-split overlap, or report MIRACL with and without MIRACL-train in the mix.
    • Also check the claim at matched embedding dimension: Nomic v2 uses 768 dims against 1024 for the larger models, which affects index cost more than encoder size does.
  5. Design

    You run multilingual RAG over 50M passages in 18 languages on a single GPU node and re-embed the corpus monthly. Compare Nomic Embed v2 at 256 dims, Nomic Embed v2 at 768 dims and a dense 568M model at 1024 dims. Which would you pick, and what would you measure before committing?

    What a strong answer covers
    • Index: 50M · 256 · 4 B ≈ 51 GB vs ≈ 154 GB at 768 vs ≈ 205 GB at 1024 (fp32). Smaller vectors also speed up ANN search.
    • Re-embedding: cost scales with active FLOPs per token, so 305M active is cheaper than 568M dense, provided the MoE kernels do not lose the gain to routing overhead or poor batching.
    • Quality: measure nDCG@10 and Recall@100 per language on held-out queries, especially low-resource ones, at 256 vs 768 dims. Matryoshka truncation costs are usually uneven across languages.
    • Decision rule: start at 256 dims with a 768-dim rerank of the top-k if the per-language loss is small; otherwise use 768 dims or a stronger reranker.
  6. Connect

    Contrast mixture of experts in Nomic Embed v2 with mixture of experts in decoder LLMs such as Switch Transformer or Mixtral. Which motivation carries over, which does not, and what does the bidirectional encoder setting make possible that the paper lists as future work?

    What a strong answer covers
    • Same mechanism: a learned router sends each token to k experts in place of a dense MLP, with an auxiliary balancing loss to prevent collapse.
    • Carries over: more capacity per FLOP. Different: there is no autoregressive decoding, so the memory-bandwidth cost of loading expert weights per generated token matters less; encoding is batched and compute-bound.
    • In an encoder the whole sequence is visible at once, so routing could use global information. The paper names loss-free routing that exploits bidirectionality as future work.
    • The paper also proposes distilling the MoE back into a dense model, which would recover the simpler deployment of a dense encoder.

Done with this page?

Status