Finetune a Sentence Transformer with a matching loss and trainer
Answer: Finetuning Sentence Transformer models often improves performance on your use case, because each task also requires a different notion of similarity. Loss functions play a critical role, and there is no one size fits all loss function.
Why finetune
Given news articles, a model for classification should produce similar embeddings for related texts. A model for semantic textual similarity should produce dissimilar embeddings for texts that have different meanings. A semantic search model would not need a notion for similarity between two documents, as it should then compare only queries and documents.
Components and losses
Training Sentence Transformer models involves between 4 to 6 components: Model, Dataset, Loss Function, Training Arguments, Evaluator, and Trainer. Training Arguments and Evaluator are optional. If you want to further finetune a SentenceTransformer model, for example it has a modules.json file, then you do not have to worry about which modules are used.
The loss overview table should help narrow down your choice of loss function by matching them to your data formats. You can often convert one training data format into another, then allowing more loss functions to be viable. For example, pairs with class labels can also be converted into anchor, positive, negative triplets by sampling the inputs with the same or different classes. Star-marked losses are commonly recommended defaults.
| Model | Dataset | |---|---| | Model | Initialize the model for training | | Dataset | Prepare the data for training | | Loss Function | Prepare and choose a loss function | | Training Arguments | Optional arguments that are useful | | Evaluator | Evaluate during and after training | | Trainer | Start the training process |
See also
Claims
- id: C1 claim: Finetuning often improves results because each task needs a different notion of similarity. source: S1 evidence: "each task requires a different notion of similarity"
- id: C2 claim: A Sentence Transformer training run uses between 4 and 6 components, including model, dataset, loss, and trainer. source: S1 evidence: "involves between 4 to 6 components"
- id: C3 claim: Loss functions should be chosen to match the data format, and there is no single loss that fits every case. source: S2 evidence: "one size fits all"
Sources
- [S1] Training Overview. Sentence Transformers. https://www.sbert.net/docs/sentence_transformer/training_overview.html . License: Apache-2.0. Accessed 2026-11-19.
- [S2] Loss Overview. huggingface/sentence-transformers (GitHub). https://github.com/huggingface/sentence-transformers/blob/main/docs/sentence_transformer/loss_overview.md . License: Apache-2.0. Accessed 2026-11-19.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Sentence Transformers, Training Overview; huggingface/sentence-transformers (GitHub), Loss Overview. Apache-2.0; Apache-2.0. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Sentence Transformers, Training Overview; huggingface/sentence-transformers (GitHub), Loss Overview. Apache-2.0; Apache-2.0.
Cite this
iinventedlight. 2026. "Finetune a Sentence Transformer with a matching loss and trainer." iinventedlight Library, iil:note:ayx16qhd, version of 2026-11-19. https://iinventedlight.com/library/notes/sentence-transformers-training/. License: CC-BY-4.0.
@misc{iil_note_ayx16qhd,
author = {{iinventedlight}},
title = {{Finetune a Sentence Transformer with a matching loss and trainer}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-19},
url = {https://iinventedlight.com/library/notes/sentence-transformers-training/},
note = {Permanent ID iil:note:ayx16qhd. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- sentence-transformers-training.table.json (table; CC-BY-4.0)
- sentence-transformers-training.schema.json (schema; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/sentence-transformers-training.md.