SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2502.07972 · 2025

Training Sparse Mixture Of Experts Text Embedding Models

arXiv · PDF · Open in the Atlas

Code that ran

9 of 9 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (0 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 1 violated it and 8 have no contract verdict; 0 failures of our instrument; 0 no recorded run), measured 2026-11-22; repository links from the Papers with Code archive attributed under CC BY-SA, no affiliation; bodies inline only under a permissive licence as GitHub detects it. Not a reproduction of the paper's results.

"Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results. This record, dated, as JSON: /api/ran/2502.07972.json · badge: /api/ran/2502.07972.svg

Each repository's role is a label: a classifier's output recorded on the link, or, where no role is recorded, what the Papers with Code archive marked. The line under it names its basis. Neither says who wrote the code.

RepositoryRoleRan
nomic-ai/contrastors canonical (classifier label)
classifier basis not recorded on the link
9 ran · 0 no recorded run
FunctionStatusWhere it lives
calculate_auxiliary_loss Ran
ran on a synthesized input
nomic-ai/contrastors/src/contrastors/loss.py
code served (permissive licence) · get_code("a9ecfab3d0116215")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned Tensor, ndim 0, dtype family float, shape () as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn.functional as F

torch.manual_seed(0)

# Set up basic parameters
batch_size = 2
sequence_length = 3
num_experts = 4
top_k = 2
num_hidden_layers = 2

# Create router_logits as a list of tensors
# Each tensor has shape (batch_size * sequence_length, num_experts)
router_logits = [
    torch.randn(batch_size * sequence_length, num_experts),
    torch.randn(batch_size * sequence_length, num_experts)
]

# Create attention_mask with shape (batch_size, sequence_length)
attention_mask = torch.ones(batch_size, sequence_length, dtype=torch.float32)

# Create a mock tracker (wandb-like object)
class MockTracker:
    def log(self, data, step=None):
        pass

tracker = MockTracker()

# Define the arguments dictionary
ARGS = {
    'router_logits': router_logits,
    'num_experts': num_experts,
    'top_k': top_k,
    'attention_mask': attention_mask,
    'tracker': tracker,
    'name': 'test_loss',
    'step': 0
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch, wandb — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 0, dtype family float, shape () — shape () as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
collate_fn Ran
ran on a synthesized input
nomic-ai/contrastors/src/contrastors/dataset/text_text_loader.py
code served (permissive licence) · get_code("801ebbc0eea48637")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned tuple. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch

torch.manual_seed(0)

# The collate_fn function takes a batch parameter and returns batch[0]
# So batch needs to be a list-like object with at least one element

# Create a simple batch - a list of tuples (x, y) as would come from a DataLoader
batch = [
    (torch.randn(2, 4), torch.tensor([0, 1])),
    (torch.randn(2, 4), torch.tensor([1, 0])),
]

ARGS = {
    "batch": batch
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple — a tuple output has no array shape of its own; none is stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
collate_local_ds Ran
ran on a synthesized input
nomic-ai/contrastors/src/contrastors/dataset/text_text_loader.py
code served (permissive licence) · get_code("c522aff126ea966e")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned dict. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn

torch.manual_seed(0)

# Stand-in tokenizer that mimics HuggingFace tokenizer behavior
class StandInTokenizer:
    def __call__(self, texts, padding='max_length', truncation=True, return_tensors='pt'):
        # Simulate tokenizer output with input_ids and attention_mask
        batch_size = len(texts)
        max_length = 10
        
        input_ids = torch.randint(0, 1000, (batch_size, max_length))
        attention_mask = torch.ones((batch_size, max_length))
        
        result = {
            'input_ids': input_ids,
            'attention_mask': attention_mask
        }
        return result

# Create sample batch data
batch = [
    {
        'dataset_name': 'ds1',
        'query': 'what is machine learning',
        'document': 'machine learning is a field of AI',
        'negative': 'cats are cute animals'
    },
    {
        'dataset_name': 'ds2',
        'query': 'how to code in python',
        'document': 'python is a programming language',
        'negative': 'dogs are loyal pets'
    }
]

tokenizer = StandInTokenizer()

ARGS = {
    'batch': batch,
    'tokenizer': tokenizer,
    'add_prefix': False,
    'query_only': None,
    'path2prefix': None
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type dict — a dict output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a dict output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
configure_optimizer Ran
ran on a synthesized input
nomic-ai/contrastors/src/contrastors/optimizer.py
code served (permissive licence) · get_code("6651be3ec3f1b0ce")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned AdamW. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn
from torch.optim import AdamW

torch.manual_seed(0)

# Create a simple model with various parameter types
class SimpleModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(4, 3)
        self.layer_norm = nn.LayerNorm(3)
        self.logit_scale = nn.Parameter(torch.tensor(1.0))
        self.bias_param = nn.Parameter(torch.randn(2))
        self.weight_param = nn.Parameter(torch.randn(5, 6))
        
    def forward(self, x):
        return self.linear(x)

# Create another model to test multiple modules
class AnotherModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.embedding = nn.Embedding(10, 4)
        self.fc = nn.Linear(4, 2)
        
    def forward(self, x):
        return self.fc(x)

# Instantiate models
model1 = SimpleModel()
model2 = AnotherModel()

# Create a config/args object with required attributes
class Args:
    def __init__(self):
        self.weight_decay = 0.01
        self.learning_rate = 0.001
        self.adam_beta1 = 0.9
        self.adam_beta2 = 0.999
        self.eps = 1e-8

args = Args()

# Define ARGS dict mapping all parameters
ARGS = {
    'modules': [model1, model2],
    'args': args
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type AdamW — a AdamW output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a AdamW output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
cutoff_long_text_for_embedding_generation Ran
ran on a synthesized input
nomic-ai/contrastors/src/contrastors/eval/encoder.py
code served (permissive licence) · get_code("e3e85af21ad96887")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned str. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import numpy as np

class MockEncoding:
    """Mock encoding object with encode/decode methods"""
    def __init__(self):
        self.token_map = {
            'hello': 0,
            'world': 1,
            'this': 2,
            'is': 3,
            'a': 4,
            'test': 5,
            ' ': 6,
        }
        self.reverse_map = {v: k for k, v in self.token_map.items()}
    
    def encode(self, text):
        """Convert text to token list"""
        tokens = []
        for char in text:
            if char == ' ':
                tokens.append(6)
            else:
                # Simple character-based tokenization
                tokens.append(hash(char) % 7)
        return tokens
    
    def decode(self, tokens):
        """Convert token list back to text"""
        # Simple reconstruction - map tokens back to characters
        result = ""
        for token in tokens:
            if token == 6:
                result += " "
            else:
                result += chr(65 + (token % 26))  # Map to A-Z
        return result

# Create mock encoding object
encoding = MockEncoding()

# Create test text - something moderately long
text = "This is a sample text for testing the cutoff function. " * 200

# Create arguments dictionary
ARGS = {
    'text': text,
    'encoding': encoding,
    'cutoff': 8192
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type str — a str output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a str output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
gather Ran
ran on a synthesized input
nomic-ai/contrastors/src/contrastors/distributed.py
code served (permissive licence) · get_code("8cea512acd127521")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned Tensor, ndim 2, dtype family float, shape (2, 4) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.distributed as dist

torch.manual_seed(0)

# Initialize the distributed environment with a single process
# This allows the function to run without actually requiring multiple processes
if not dist.is_initialized():
    dist.init_process_group(
        backend='gloo',
        init_method='tcp://127.0.0.1:29500',
        rank=0,
        world_size=1
    )

# Create a small tensor to pass to gather
t = torch.randn(2, 4)

ARGS = {
    't': t
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 2, dtype family float, shape (2, 4) — shape (2, 4) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
gather_dict Ran
ran on a synthesized input
nomic-ai/contrastors/src/contrastors/distributed.py
code served (permissive licence) · get_code("c54c334ddaf65c44")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned dict. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.distributed as dist

torch.manual_seed(0)

# Mock distributed environment - pretend we're in a non-distributed setting
# so the function returns early without requiring actual distributed setup
if not dist.is_initialized():
    # Create a simple dict with tensor values
    d = {
        "tensor_a": torch.randn(2, 4),
        "tensor_b": torch.randn(3, 4),
        "scalar": torch.tensor(5.0),
    }
else:
    d = {
        "tensor_a": torch.randn(2, 4),
        "tensor_b": torch.randn(3, 4),
        "scalar": torch.tensor(5.0),
    }

ARGS = {
    "d": d,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type dict — a dict output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a dict output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
gather_with_grad Ran
ran on a synthesized input
nomic-ai/contrastors/src/contrastors/distributed.py
code served (permissive licence) · get_code("d02a4e692567ae9d")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned Tensor, ndim 0, dtype family float, shape () as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.distributed as dist
from unittest.mock import MagicMock, patch

torch.manual_seed(0)

# Mock distributed initialization since we're not actually running in a distributed setting
# We'll patch dist functions to simulate a single-process environment
original_is_initialized = dist.is_initialized
original_get_world_size = dist.get_world_size

def mock_is_initialized():
    return False

def mock_get_world_size():
    return 1

dist.is_initialized = mock_is_initialized
dist.get_world_size = mock_get_world_size

# Create a small tensor for testing
# The function checks if t.ndim == 0, so test with a scalar tensor
t = torch.tensor(3.14, requires_grad=True)

ARGS = {
    "t": t
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 0, dtype family float, shape () — shape () as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
log_and_continue Ran
ran, violated the contract we drafted
nomic-ai/contrastors/src/contrastors/dataset/image_text_loader.py
pointer only (licence: Apache-2.0); the stored copy get_code serves, from CSIPlab/SLUG, is pointer only (licence: NONE) · get_code("be4e00be50540042")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (Apache-2.0), but get_code serves the stored copy, first harvested from CSIPlab/SLUG, and GitHub detected no licence in that repository when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

Also present in other papers' code

Of 9 samples lifted from this paper's linked repositories, 9 carry a function identity and 0 do not. Of the 9 distinct functions with an identity, 2 are also present in other papers whose code we hold (2 with at least one paper dated earlier, 0 the same month, 0 later) and 7 are only here among the 52,977 papers whose code Syntology holds (as of 2026-09-26).

Only here means: among the 52,977 papers whose code Syntology holds (51,887 with lifted samples, 1,090 through their assemblies only), as of 2026-09-26, no other paper's lifted samples or current assembly bricks contain an identical function body after normalisation.

FunctionAlso present inEarliest-datedOthers named
log_and_continue 3 other papers
3 dated earlier
2403.16005 (2024-03)
Knowledge-Enhanced Dual-stream Zero-shot Composed Image Retrieval
2405.21070 (2024-05)
What Makes CLIP More Robust to Long-Tailed Pre-Training Data? A Controlled Study for Transferable Insights
2407.11867 (2024-07)
Targeted Unlearning with Single Layer Unlearning Gradient
collate_fn 1 other paper
1 dated earlier
2004.07999 (2020-04)
REVISE: A Tool for Measuring and Mitigating Bias in Visual Datasets

Presence, not direction: an identical function body in two papers' repositories does not say who wrote it, which came from which, or that either paper's method rests on it. Matching is exact after normalisation, so a renamed or edited function is not matched. Dates are when papers appeared, not when code was written. Only .py files the harvester lifted are covered; notebooks are not read. A new-style arXiv id YYMM.NNNN dates a paper to the month 20YY-MM; otherwise Paper.year dates it to the year; otherwise it is undated. Dates are when the paper appeared, not when the code was written. Read 2026-11-22.

Repositories linked to this paper

Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.

Abstract

Transformer-based text embedding models have improved their performance on benchmarks like MIRACL and BEIR by increasing their parameter counts. However, this scaling approach introduces significant deployment challenges, including increased inference latency and memory usage. These challenges are particularly severe in retrieval-augmented generation (RAG) applications, where large models' increased memory requirements constrain dataset ingestion capacity, and their higher latency directly impacts query-time performance. While causal language models have addressed similar efficiency challenges using Mixture of Experts (MoE) architectures, this approach hasn't been successfully adapted to the general text embedding setting. In this paper, we introduce Nomic Embed v2, the first general purpose MoE text embedding model. Our model outperforms models in the same parameter class on both monolingual and multilingual benchmarks while also maintaining competitive performance with models twice its size. We open-source all code, models, and evaluation data to ensure full reproducibility of our training pipeline at \href{https://github.com/nomic-ai/contrastors}{https://github.com/nomic-ai/contrastors}.

For agents

The same record, over MCP at https://syntology.ai/mcp:

get_harvested_code_for_paper("2502.07972")
get_code_for_paper("2502.07972")
have("2502.07972")

The run record, dated, one paper per request, free:

curl https://syntology.ai/api/ran/2502.07972.json

A badge for a README (the split and the date, never a ratio):

[![Syntology run record](https://syntology.ai/api/ran/2502.07972.svg)](https://syntology.ai/paper/2502.07972)

Connect an agent — have() is free.