---
title: "Training and Finetuning Embedding Models with Sentence Transformers"
description: "Sentence Transformers v3 trains and finetunes embedding models through a SentenceTransformerTrainer that combines Hugging Face datasets, a loss function, optional training arguments and evaluators."
url: "https://swe.quest/articles/training-and-finetuning-embedding-models-with-sentence-transformers-d6dcb3eebe384143"
canonical: "https://huggingface.co/blog/train-sentence-transformers"
source: "Hugging Face"
published: "2024-05-28"
difficulty: "medium"
kind: "How-to"
reading_minutes: 14
tags: ["model-training","python","machine-learning","search","evals"]
---

# Training and Finetuning Embedding Models with Sentence Transformers

A post on [Hugging Face](https://swe.quest/sources/hugging-face.md), published 2024-05-28, 14 min read, How-to. Original: [https://huggingface.co/blog/train-sentence-transformers](https://huggingface.co/blog/train-sentence-transformers)

## Summary

Sentence Transformers v3 trains and finetunes embedding models through a SentenceTransformerTrainer that combines Hugging Face datasets, a loss function, optional training arguments and evaluators. Finetuning matters because each task needs its own notion of similarity. Dataset column order must match the chosen loss's inputs, with an optional "label" or "score" column, and extraneous columns must be removed. A worked example finetunes MPNet on AllNLI triplets with MultipleNegativesRankingLoss and a no-duplicates batch sampler, and evaluates with TripletEvaluator and EmbeddingSimilarityEvaluator on STSb.

Written by swe.quest, not by the author.

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

## Topics

- [Model training](https://swe.quest/tags/model-training.md) (AI & ML)
- [Python](https://swe.quest/tags/python.md) (Languages)
- [Machine learning](https://swe.quest/tags/machine-learning.md) (AI & ML)
- [Search](https://swe.quest/tags/search.md) (Backend & APIs)
- [Evaluation](https://swe.quest/tags/evals.md) (AI & ML)

## Prerequisites

- Python ([easy posts on Python](https://swe.quest/tags/python.md?difficulty=easy))
- text embeddings basics ([easy posts on RAG & retrieval](https://swe.quest/tags/rag.md?difficulty=easy))
- Hugging Face datasets

## Keywords

Sentence Transformers, Hugging Face, MultipleNegativesRankingLoss, CoSENTLoss, AllNLI, STS Benchmark, MPNet

## Related posts

- [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 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.
- [Training and Finetuning Sparse Embedding Models with Sentence Transformers](https://swe.quest/articles/training-and-finetuning-sparse-embedding-models-with-sentence-transformers-bcdd540c54167ab1.md): Hugging Face · 2025-07-01 · Medium · 27 min read · Search, Model training, Python, RAG & retrieval
  Sentence Transformers' SparseEncoder API can train and finetune neural sparse embedding models such as SPLADE, inference-free SPLADE and Contrastive Sparse Representation (CSR).
- [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.
- [Training and Finetuning Reranker Models with Sentence Transformers](https://swe.quest/articles/training-and-finetuning-reranker-models-with-sentence-transformers-56e6eabec0c38454.md): Hugging Face · 2025-03-26 · Medium · 24 min read · Model training, Search, RAG & retrieval, Python
  Sentence Transformers can finetune reranker (cross-encoder) models on domain data.

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)
