---
title: "Training and Finetuning Sparse Embedding Models with Sentence Transformers"
description: "Sentence Transformers' SparseEncoder API can train and finetune neural sparse embedding models such as SPLADE, inference-free SPLADE and Contrastive Sparse Representation (CSR)."
url: "https://swe.quest/articles/training-and-finetuning-sparse-embedding-models-with-sentence-transformers-bcdd540c54167ab1"
canonical: "https://huggingface.co/blog/train-sparse-encoder"
source: "Hugging Face"
published: "2025-07-01"
difficulty: "medium"
kind: "How-to"
reading_minutes: 27
tags: ["search","model-training","python","rag"]
---

# Training and Finetuning Sparse Embedding Models with Sentence Transformers

A post on [Hugging Face](https://swe.quest/sources/hugging-face.md), published 2025-07-01, 27 min read, How-to. Original: [https://huggingface.co/blog/train-sparse-encoder](https://huggingface.co/blog/train-sparse-encoder)

## Summary

Sentence Transformers' SparseEncoder API can train and finetune neural sparse embedding models such as SPLADE, inference-free SPLADE and Contrastive Sparse Representation (CSR). The guide walks through each training component: model architecture, datasets, loss functions, training arguments, evaluators and the trainer. Sparse models produce vocabulary-sized vectors with learned query and document expansion, which makes them interpretable and strong in hybrid search. Finetuning teaches domain-specific expansions, for example mapping "cephalalgia" to "headache". Practical details include using router\_mapping for the query/document split in inference-free SPLADE and a much higher learning rate for the SparseStaticEmbedding module.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Search](https://swe.quest/tags/search.md) (Backend & APIs)
- [Model training](https://swe.quest/tags/model-training.md) (AI & ML)
- [Python](https://swe.quest/tags/python.md) (Languages)
- [RAG & retrieval](https://swe.quest/tags/rag.md) (AI & ML)

## Prerequisites

- embedding models
- PyTorch/Transformers training basics ([easy posts on Model training](https://swe.quest/tags/model-training.md?difficulty=easy))
- information retrieval basics ([easy posts on Search](https://swe.quest/tags/search.md?difficulty=easy))

## Keywords

Sentence Transformers, SPLADE, SparseEncoder, Hugging Face, BM25, Contrastive Sparse Representation

## Related posts

- [Training and Finetuning Embedding Models with Sentence Transformers](https://swe.quest/articles/training-and-finetuning-embedding-models-with-sentence-transformers-d6dcb3eebe384143.md): Hugging Face · 2024-05-28 · Medium · 14 min read · Model training, Python, Machine learning, Search, Evaluation
  Sentence Transformers v3 trains and finetunes embedding models through a SentenceTransformerTrainer that combines Hugging Face datasets, a loss function, optional training arguments and evaluators.
- [Train and Fine-Tune Sentence Transformers Models](https://swe.quest/articles/train-and-fine-tune-sentence-transformers-models-49bc0c36b2cdc22e.md): Hugging Face · 2022-08-10 · Medium · 11 min read · Model training, Machine learning, Python, Search
  Sentence Transformers models map text to fixed-size embeddings by running a pre-trained Transformer and pooling its token embeddings, and training them depends on matching the dataset format to the right loss.
- [Train 400x faster Static Embedding Models with Sentence Transformers](https://swe.quest/articles/train-400x-faster-static-embedding-models-with-sentence-transformers-9f174d4b1294477b.md): Hugging Face · 2025-01-15 · Hard · 39 min read · Model training, Machine learning, Search, Python, Performance engineering
  Static embedding models, which replace the attention-based encoder with a token embedding lookup plus mean pooling (an EmbeddingBag), can be trained with modern contrastive losses and Matryoshka Representation Learning to run 100x to 400x faster on CPU than models like all-mpnet-base-v2 and multilingual-e5-small, while keeping at least 85% of their benchmark quality.
- [Training and Finetuning Multi-Vector Embedding Models with Sentence Transformers](https://swe.quest/articles/training-and-finetuning-multi-vector-embedding-models-with-sentence-transformers-454449569f0d4793.md): Hugging Face · 2026-08-26 · Medium · 27 min read · Model training, Search, Python, RAG & retrieval
  Sentence Transformers v6.0 adds a MultiVectorEncoder model type for ColBERT-style late-interaction retrieval, with a full training stack covering models, datasets, losses, training arguments, evaluators and the trainer.
- [Train a Sentence Embedding Model with 1B Training Pairs](https://swe.quest/articles/train-a-sentence-embedding-model-with-1b-training-pairs-f0642783223f8c14.md): Hugging Face · 2021-10-25 · Hard · 6 min read · Model training, Machine learning, Vector search
  Sentence embedding models trained with a contrastive multiple-negatives ranking loss (InfoNCE) on up to 1 billion sentence pairs, using in-batch negatives, a scaled similarity (C≈20), and cosine vs. dot-product tradeoffs for clustering and ANN search.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
