← All notes

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

Sources

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

Permanent ID: iil:note:ayx16qhd

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.},
}

Markdown

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.

All artifact files (JSON index)

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.