Skip to content
Edit this page

muscari

Parts for building learned sparse retrieval models with Sentence Transformers, and for training the sparse autoencoders (SAEs) that some of them use as their vocabulary.

Get started New to sparse retrieval? Examples API reference

A learned sparse retriever turns a text into a vector with a few hundred non-zero weights, so that an inverted index can search it. SPLADE reads those weights off the language-model head, one dimension per vocabulary entry. Newer models take the latents of an SAE instead (SAE-SPLADE, SPLARE, SlideOn), or change how the head's logits become weights (SPARSEUP). muscari adds what these models need as modules, losses and callbacks that plug into Sentence Transformers' SparseEncoder and SparseEncoderTrainer. It is a toolkit: every choice the sources disagree on is an option.

If you know dense embedding models and have not used a sparse one, start with What is learned sparse retrieval?. Coming from dense models maps what you know onto sparse training, and Methods at a glance puts the supported methods side by side, with what speaks for each and what it costs. With a task or a problem in mind, start from What do you want to do?

  • Train an SAE on an encoder


    Top-K SAEs on the token states of any Hugging Face encoder: streamed activations, content tokens only, a sparse backward pass, two trainers and one file format.

    Train an SAE

  • See what an SAE learned


    Reconstruction and dictionary use, what each latent fires on, and how the encoder ranks with the SAE in its path, before any retrieval training.

    Evaluate and inspect

  • SAE latents as the vocabulary


    SAEPooling puts an SAE on its encoder as the head of a sparse encoder: frozen or trained, with its own k, a gate per latent, a load-balance term.

    Build a retriever on an SAE

  • A sparser SPLADE head


    VocabularyPooling shifts the logits, limits them per position, folds spellings and masks noise entries, so that ModernBERT-style encoders train.

    Build a retriever on the vocabulary

  • Losses, schedules, recipes


    Contrastive, KL, MarginMSE and soft-label terms on one scale, training under caps, and nine option files with the published settings of seven methods.

    Train a retriever

  • A smaller encoder for queries


    Documents through a large encoder, queries through a small one, in one model; for SAE heads the query side starts from a map between the two encoders.

    Separate encoders

  • Evaluate under caps


    Reranking and retrieval at several limits on the vector size, with size and FLOPS, and intervals over runs and queries when two models are compared.

    Evaluate a retriever

  • What has been measured


    Small runs on Japanese encoders, with their conditions and limits. A recipe copies a source's settings; it does not promise the source's results.

    Measurements

Two things this project does not claim

A recipe copies what a paper, a model card or released code states and marks every value that is this project's own; a reimplementation from a description is not a reproduction. And published values do not carry over between encoders: in the recipes here, FLOPS weights range from 2e-5 to 0.06, contrastive temperatures from 0.02 to 6, and distillation temperatures from 1 to 80. That is why the diagnostics exist: they measure, before training, the quantities those settings act on.

The interfaces still move while the major version is 0; the changelog says how versions are numbered, and What is verified lists what has run where.