# /train-sentence-transformers: Train embedding and reranker models from tested templates

Source: https://trendhub.net/skills/huggingface-skills/train-sentence-transformers
Skill folder: https://github.com/huggingface/skills/tree/main/skills/train-sentence-transformers
Pack: Hugging Face Skills (https://trendhub.net/skills/huggingface-skills)
Works with: Claude Code, Gemini CLI

This skill routes sentence-transformers training to the right model type, references and production template instead of letting the agent improvise a script. It covers bi-encoders, cross-encoder rerankers, SPLADE sparse encoders and ColBERT-style multi-vector models, and requires a baseline score, a smoke test and a single verdict line comparing the result to that baseline.

## When to use it

- You need a domain-specific embedding model for retrieval or deduplication.
- You want to train a reranker for two-stage search.
- You are building learned-sparse or late-interaction retrieval.

## How it works

1. **Identify the model type**: The agent maps the request to bi-encoder, cross-encoder, sparse or multi-vector, using keywords such as rerank or SPLADE, and asks if it is still unclear.
2. **Read the required references**: It loads the loss, evaluator and cross-cutting guides for that type in full before writing code.
3. **Start from the template**: It copies the matching production script and swaps in your model, dataset, run name, loss and evaluator.
4. **Smoke-test, then run**: It runs one step on a tiny slice first, then trains, recording the baseline before training and a WIN, MARGINAL or REGRESSION verdict after.
5. **Publish and log**: It pushes the model to the Hub inside a try block, appends the run to an experiments log and proposes further runs if the gain is weak.

## What it steers the agent away from

- Training scripts synthesised from memory that miss the template's scaffolding.
- Reporting a score without a pre-training baseline to compare against.
- Sparse models that score well while their sparsity has collapsed.

## What it can touch

It writes and runs Python training scripts locally or on Hugging Face Jobs, writes log files, and pushes models to the Hub with your token.

## Pairs well with

- `/huggingface-datasets`
- `/huggingface-trackio`

## Questions

### Does it need a GPU?

A GPU is strongly recommended; CPU training is only practical for demos and static embedding models.

### Where does training run by default?

Locally. It only suggests Hugging Face Jobs when your hardware cannot handle the job.
