train-sentence-transformers
Skill19k starsChanged 4 months agoApache-2.0View on GitHub
Train or fine-tune sentence-transformers models across `SentenceTransformer` (bi-encoder, dense or static embedding model for retrieval, similarity, clustering, classification, paraphrase mining, dedup, multimodal), `CrossEncoder` (reranker, pair scoring for two-stage retrieval / pair classification), `SparseEncoder` (SPLADE, sparse embedding model for learned-sparse retrieval), and `MultiVectorEncoder` (ColBERT / late-interaction, per-token embeddings scored with MaxSim). Covers loss selection, hard-negative mining, evaluators, distillation, LoRA, Matryoshka, and Hugging Face Hub publishing. Use for any sentence-transformers training task.
- Installs packages
4 other projects use a version of this, 3 of them edited.
Trending
More talk lately.about the whole repository
Most recently taken up by
- huggingface/skillsword for word, first seen Oct 1, 2026
- PracticalSwan/agent-skillsedited, first seen Sep 14, 2026
- waybarrios/opencode-power-packedited, first seen Aug 17, 2026
- noahsilve123/claude-skillsetedited, first seen Jul 3, 2026
Who's talking about huggingface/sentence-transformers
- huggingface/huggingface_hub“[httpx] Let's migrate to httpx2!”GitHub · Sep 3, 2026 · 3 reactions
- Ven0m0/gemini-web-wrapper“chore(deps): bump the uv-all group with 2 updates”GitHub · Jun 17, 2026 · 3 reactions
- Ven0m0/gemini-web-wrapper“chore(deps): bump the uv-all group across 1 directory with 5 updates”GitHub · May 20, 2026 · 3 reactions
- Ven0m0/gemini-web-wrapper“chore(deps): bump the uv-all group with 3 updates”GitHub · May 13, 2026 · 3 reactions
- djimit/juraregel“chore(deps)(deps): bump sentence-transformers from 3.2.0 to 5.6.1”GitHub · Jul 25, 2026 · 2 reactions
The biggest 5 of 50 mentions linking to the repository that our crawl found. Each line is their own headline.
See all 50
Talked about on GitHub (50 times).
On GitHub · 50
- Sep 3, 2026[httpx] Let's migrate to httpx2! — huggingface/huggingface_hub3 reactions · 7 comments
- Jun 17, 2026chore(deps): bump the uv-all group with 2 updates — Ven0m0/gemini-web-wrapper3 reactions · 6 comments
- May 20, 2026chore(deps): bump the uv-all group across 1 directory with 5 updates — Ven0m0/gemini-web-wrapper3 reactions · 8 comments
- May 13, 2026chore(deps): bump the uv-all group with 3 updates — Ven0m0/gemini-web-wrapper3 reactions · 7 comments
- Jul 25, 2026chore(deps)(deps): bump sentence-transformers from 3.2.0 to 5.6.1 — djimit/juraregel2 reactions · 3 comments
45 more on GitHub
- Jul 22, 2026chore(deps)(deps): bump sentence-transformers from 3.2.0 to 5.6.0 — djimit/juraregel2 reactions · 3 comments
- May 17, 2026build(deps): bump sentence-transformers from 3.0.1 to 5.5.0 — EvezArt/evez-atlas2 reactions · 2 comments
- May 12, 2026chore(deps): bump sentence-transformers from 3.0.1 to 5.4.1 — EvezArt/evez-atlas2 reactions · 3 comments
- Dec 15, 2025[Internal] trigger `sentence-transformers` CI for hfh prerelease — huggingface/huggingface_hub2 reactions · 1 comment
- Oct 31, 2026Bump the python-security group across 1 directory with 5 updates — werdnum/family-assistant1 reaction · 1 comment
- Oct 31, 2026chore(deps): Update sentence-transformers requirement from >=6.1.0 to >=6.2.0 in /requirements — chatoe-norm/jarvise1 reaction
- Oct 20, 2026chore(deps): bump the uv group across 2 directories with 9 updates — Ditto190/modme-ui-011 reaction · 5 comments
- Oct 10, 2026chore(deps): bump sentence-transformers from 5.4.1 to 5.6.0 — 0xmariowu/Autosearch1 reaction · 3 comments
- Oct 6, 2026build(deps): bump sentence-transformers from 2.2.2 to 5.6.0 in /memory-pipeline — Jimthetaxguy/IMPULSE-rs1 reaction
- Sep 25, 2026deps(uv): bump the uv-minor-patch group with 9 updates — DataBoar/data-boar1 reaction · 1 comment
- Aug 28, 2026deps(uv): bump sentence-transformers from 5.7.0 to 6.0.0 — DataBoar/data-boar1 reaction · 2 comments
- Aug 14, 2026deps(uv): bump the uv-minor-patch group with 9 updates — DataBoar/data-boar1 reaction
- Aug 12, 2026Use device for similarity compute — embeddings-benchmark/mteb1 reaction · 3 comments
- Jul 26, 2026build(deps): bump the python-minor-patch group with 7 updates — gptme/gptme1 reaction · 6 comments
- Jun 18, 2026deps(lora): bump the lora-deps group across 1 directory with 7 updates — Bryan-Roe/Aria1 reaction · 3 comments
- May 21, 2026chore(deps): bump sentence-transformers from 5.4.1 to 5.5.1 — concept2cure/ClinicalSageAI-2-replit1 reaction · 1 comment
- May 20, 2026deps(lora): bump the lora-deps group across 1 directory with 2 updates — Bryan-Roe/Aria1 reaction · 2 comments
- May 17, 2026Gate media reranking behind bounded cascade — brianmeyer/recallforge1 reaction
- May 16, 2026deps(lora): bump the lora-deps group across 1 directory with 6 updates — Bryan-Roe/Aria1 reaction · 2 comments
- May 16, 2026deps(lora): bump the lora-deps group in /ai-projects/lora-training/microsoft_phi-silica-3.6_v1 with 8 updates — Bryan-Roe/Aria1 reaction · 4 comments
- May 7, 2026chore(deps): bump sentence-transformers from 2.2.2 to 5.4.1 — concept2cure/ClinicalSageAI-2-replit1 reaction · 1 comment
- Dec 10, 2025Add dataset: multilingual NanoBeir — embeddings-benchmark/mteb1 reaction · 3 comments
- Jul 5, 2025Update dependency sentence-transformers to v5 - autoclosed — TanNhatCMS/rag_dieu_le_doan1 reaction · 1 comment
- Nov 2, 2026Update sentence-transformers requirement from >=6.1.0 to >=6.2.0 — 7zbkdz7j55-pixel/scaling-waffle0 reactions · 1 comment
- Nov 2, 2026chore(deps): update sentence-transformers requirement from ~=3.0.1 to ~=6.2.0 in /backend — trx-0833/EngramNote0 reactions · 1 comment
- Nov 1, 2026chore(deps-dev): update sentence-transformers requirement from >=2.2 to >=6.2.0 — armchairfuturist-code/novel-writer-harness0 reactions
- Nov 1, 2026[catalog-candidate] sentence-transformers-local — ePlus-DEV/free-tier-hub0 reactions · 3 comments
- Oct 31, 2026chore(deps): update sentence-transformers requirement from >=3.0 to >=6.2.0 — chenkangkang999/doctor-quest0 reactions
- Oct 30, 2026chore(deps): bump sentence-transformers from 6.1.0 to 6.2.0 in /backend — aiwithpranav/securesearch-ai0 reactions
- Oct 28, 2026chore(deps): update sentence-transformers requirement from >=3.0 to >=6.2.0 in /api — Mike-Animal-Counseling/porter0 reactions
- Oct 26, 2026fix(deps): bump sentence-transformers from 6.1.0 to 6.2.0 in the ml-embeddings group across 1 directory — CaseyRo/mcp-stolperfalle0 reactions
- Oct 21, 2026Pin sentence-transformers to latest version 6.2.0 — tnir/gunicorn0 reactions
- Oct 16, 2026Support ordered concatenated sentence pooling modes — filthyrake/damendaemon0 reactions
- Oct 16, 2026Support single-mode BERT max weighted and last-token sentence pooling — filthyrake/damendaemon0 reactions
- Oct 16, 2026Support declared CLS sentence pooling in BERT checkpoints — filthyrake/damendaemon0 reactions
- Oct 16, 2026Support saved sentence-embedding truncation with correct output dimensions — filthyrake/damendaemon0 reactions
- Oct 16, 2026Load equivalent Sentence Transformers 5.4 compact mean-pooling checkpoints — filthyrake/damendaemon0 reactions
- Oct 9, 2026Release watch: 14 new reranker releases — sheephess9527/reranker.uk0 reactions · 17 comments
- Oct 4, 2026[Candidate] huggingface/sentence-transformers/skills/train-sentence-transformers - train-sentence-transformers — ProSkillsMD/proskills0 reactions · 1 comment
- Sep 28, 2026sentence_transformers-2.5.1-py3-none-any.whl: 105 vulnerabilities (highest severity is: 9.8) [main] (reachable) — jgeraigery/AutoPrompt0 reactions
- Sep 28, 2026sentence-transformers-2.2.2.tar.gz: 77 vulnerabilities (highest severity is: 9.8) [main] (reachable) — jgeraigery/AutoPrompt0 reactions
- Sep 28, 2026sentence-transformers-2.2.2.tar.gz: 77 vulnerabilities (highest severity is: 9.8) [main] (reachable) — jgeraigery/AutoPrompt-AI-TESt0 reactions
- Sep 16, 2026[audit ISSUE-060] sentence-transformers 下界 pin 容纳 CVE-2026-68770(本地模型加载 RCE,绕过 trust_remote_code=False)全部受影响 — WindWang2/webgis-ai-agent0 reactions · 1 comment
- Sep 13, 2026Link Checker Report — onlydole/awesome-knowledge-infrastructure0 reactions
- Sep 7, 2026Require sentence-transformers 6.0.1 to include multi-vector prompt fixes — FahadEbrahim/matheel0 reactions
Other versions4 projects use a version of this.
Word for word · 1
- huggingface/skills★ 11k100% same
Edited · 3
- waybarrios/opencode-power-pack★ 53196% same
- PracticalSwan/agent-skills★ 1879% same
- noahsilve123/claude-skillset★ 198% same
Wrote their own version · 0
None found.
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
The file
We split this skill into the rules it gives an agent
2 rules. 0 are common, 0 are distinctive, and 2 are very specific to this project.
0
Common
Most of the 3 edited versions we read keep these.
0
Distinctive
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 73
Single run: After it completes, propose experimentation if the user would benefit (weak/marginal verdict, "see how high you can push it" …
- Very specific: line 98
After the run, append to logs/experiments.md and propose iteration if the verdict is weak/marginal.
“Common” is measured: kept by at least 6 in 10 of the 3 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Train a sentence-transformers Model
This SKILL.md is a router, not a manual. It tells you which references and example scripts to load for your task. The actual content (recommended losses, evaluators, training-script structure, model selection, training-arg knobs, troubleshooting) lives in references/ and scripts/.
Do not synthesize a training script from this file alone. Open the per-type production template (scripts/train_<type>_example.py) and copy it as your starting point. The templates contain load-bearing scaffolding (autocast helper, model-card class, logger silencing list, force=True, seed, TF32, version-compatible imports, named-evaluator metric handling) that prior agent runs have repeatedly missed when rolling their own from a synthesized snippet.
1. Identify the model type
| Tag | Class | What it does | When to pick |
| [SentenceTransformer] | SentenceTransformer (bi-encoder) | Maps each input to a fixed-dim dense vector | Retrieval, similarity, clustering, classification, paraphrase mining, dedup |
| [CrossEncoder] | CrossEncoder (reranker) | Scores (query, passage) pairs jointly | Two-stage retrieval (rerank top-100 from bi-encoder), pair classification |
| [SparseEncoder] | SparseEncoder (SPLADE) | Sparse vectors over the vocabulary | Learned-sparse retrieval, inverted-index backends (Elasticsearch / OpenSearch / Lucene) |
| [MultiVectorEncoder] | MultiVectorEncoder (ColBERT) | One embedding per token, scored with MaxSim | Late-interaction retrieval, recall gains over bi-encoders at higher storage cost, multimodal (ColPali / ColQwen2) |
Tiebreakers when the request is ambiguous: "embedding model" / "vector search" / "similarity" → [SentenceTransformer]. "rerank" / "ranker" / "two-stage" → [CrossEncoder]. "SPLADE" / "sparse" / "inverted index" → [SparseEncoder]. "ColBERT" / "late interaction" / "multi-vector" / "MaxSim" / "ColPali" / "ColQwen" → [MultiVectorEncoder]. If still unclear, ask.
2. Required reading
Read these in full before writing any code. Do not triage by perceived relevance.
Per-type: always required
[SentenceTransformer]
references/losses_sentence_transformer.md: loss-to-data-shape mapping,BatchSamplers.NO_DUPLICATESrequirement for MNRL-family,Cached*↔gradient_checkpointingincompatibility.references/evaluators_sentence_transformer.md: evaluator-to-task mapping,metric_for_best_modelkey construction (named vs unnamed), per-evaluatorprimary_metricvalues.references/model_architectures.md: encoder vs decoder vs static vs Router pipelines, pooling rules (mean / cls / lasttoken), auto-mean-pooling behavior for fresh-start MLM bases.scripts/train_sentence_transformer_example.py: production template. Copy this as your starting point.
[CrossEncoder]
references/losses_cross_encoder.md: pointwise / pairwise / listwise / distillation,pos_weightderivation,activation_fn=Identity()mandatory for non-BCE losses (silent eval-rank collapse otherwise).references/evaluators_cross_encoder.md:CrossEncoderRerankingEvaluatorrecipe, named-evaluator key formateval_{name}_{primary_metric}.scripts/train_cross_encoder_example.py: production template. Copy this as your starting point.
[SparseEncoder]
references/losses_sparse_encoder.md:SpladeLosswrapper requirement, FLOPS regularizer weights, smoke-test active-dim ramp behavior.references/evaluators_sparse_encoder.md:SparseNanoBEIREvaluator(English-only) and the in-domain alternative,eval_{name}_{primary_metric}key format.scripts/train_sparse_encoder_example.py: production template. Copy this as your starting point.
[MultiVectorEncoder]
references/losses_multi_vector_encoder.md: MaxSim scoring, scale choice per scoring mode (scale=1.0for MaxSim, roughly the average query length for MeanMaxSim), MNRL / CachedMNRL / MarginMSE / DistillKLDiv, XTR-vs-ColBERT scoring, CachedMNRL ↔gradient_checkpointingincompatibility.references/evaluators_multi_vector_encoder.md:MultiVectorNanoBEIREvaluator(English-only) and the in-domain alternative,eval_NanoBEIR_mean_maxsim_ndcg@10key format, distillation-eval spearman variant.scripts/train_multi_vector_encoder_example.py: production template. Copy this as your starting point.
Cross-cutting: always required (regardless of task)
references/training_args.md:TrainingArgumentsknobs, precision rules (load fp32 + autocast bf16/fp16, nevertorch_dtype=bfloat16),warmup_steps(float) vs deprecatedwarmup_ratio,save_stepsmust be a multiple ofeval_stepsforload_best_model_at_end, schedulers, HPO, tracker, resume, hub-push variants.references/dataset_formats.md: column-matching rules (label name auto-detection, column-order-not-name), reshaping recipes, hard-negative mining options.references/base_model_selection.md: discovery commands, per-type model namespaces, ModernBERT-familymax_seq_length=8192trap,datasets >= 4script-loader rejection, non-English starting-point shortcuts.references/troubleshooting.md: symptom-indexed failure recipes. Skim the section headings on every run, even a healthy one. The "Metrics don't improve" and "Hub push fails" entries cover bugs that bite frequently and are cheaper to recognize before they fire than to debug after.
Cross-cutting: load when applicable
references/hardware_guide.md: VRAM sizing, multi-GPU, FSDP / DeepSpeed, HF Jobs flavors. Required for >24GB models, multi-GPU, or HF Jobs runs.references/hf_jobs_execution.md: required when running on HF Jobs.references/prompts_and_instructions.md: required when using prompt-tuned bases (E5, BGE, GTE, Qwen3-Embedding, Instructor, Nomic, etc.) or addingquery:/passage:style prefixes.
Variant scripts (open when the task matches)
- [SentenceTransformer]
scripts/train_sentence_transformer_<matryoshka|multi_dataset|with_lora|distillation|make_multilingual|static_embedding>_example.py. - [CrossEncoder]
scripts/train_cross_encoder_<distillation|listwise>_example.py. - [SparseEncoder]
scripts/train_sparse_encoder_distillation_example.py. - Hard-negative mining CLI:
scripts/mine_hard_negatives.py.
3. Defaults
Override only if the user specifies otherwise:
- Local execution. Pitch HF Jobs only if local hardware can't fit the job.
- Single run. After it completes, propose experimentation if the user would benefit (weak/marginal verdict, "see how high you can push it" framing, etc.). Iteration rules in
references/training_args.md(Experimentation section). - Public Hub push at end-of-run, wrapped in try-except. On HF Jobs (ephemeral env) ALSO enable in-trainer push (
push_to_hub=True+hub_strategy="every_save"). Details inreferences/hf_jobs_execution.md.
4. Constraints the produced script must satisfy
These are non-negotiable contracts. Implementation lives in the production templates and references. Do not reinvent.
- Capture the pre-training evaluator score as
baseline_evalbeforetrainer.train(). - Emit a single end-of-run line:
VERDICT: WIN|MARGINAL|REGRESSION | score=... | baseline=... | delta=.... A monitor scrapes for this. - Silence
httpx,httpcore,huggingface_hub,urllib3,filelock,fsspecto WARNING (otherwise HF download URLs flood the agent's context). - Tee logs to
logs/{RUN_NAME}.log. - End with
model.push_to_hub(...)wrapped intry/except. - Smoke-test before any long run (
max_steps=1+ tiny dataset slice). The production templates show one common pattern (SMOKE_TESTenv var). - [CrossEncoder] Include
EarlyStoppingCallback(patience>=3). CE rerankers often peak mid-training and regress. - [SparseEncoder] Log
query_active_dims/corpus_active_dimson the verdict line. High nDCG with collapsed sparsity is not a win. The keys come back name-prefixed (e.g...._query_active_dims). Use suffix matching to pluck them. See the SPARSE production template for the exact pattern. - [MultiVectorEncoder] Match
scaleto the scoring mode on any MNRL-family loss: near1.0for unnormalized MaxSim (do not copyscale=20.0from bi-encoder MNRL), roughly the average query length with length-normalized MeanMaxSim, since each score is divided by its query's token count.XTRScoresis a train-onlysimilarity_fct: the evaluators reject it, so evaluation always scores with MaxSim, including for XTR-trained models.
5. Workflow
- Identify the model type (§1). Ask if ambiguous.
- Load the §2 required-reading files for that type.
- Open
scripts/train_<type>_example.pyand copy it as your starting point. - Replace
MODEL_NAME,DATASET_NAME,RUN_NAME, the loss, and the evaluator with the user's task. Cross-check loss/data-shape match againstreferences/losses_<type>.md. Cross-check themetric_for_best_modelkey againstreferences/evaluators_<type>.md(named evaluators format the key aseval_{name}_{primary_metric}). - Smoke-test (
max_steps=1). - Run.
- After the run, append to
logs/experiments.mdand propose iteration if the verdict is weak/marginal.
Prerequisites
pip install "sentence-transformers[train]>=5.0" # add [train,image] / [audio] / [video] for [SentenceTransformer] multimodal
# [MultiVectorEncoder] requires >=6.0
pip install trackio # optional tracker (or wandb / tensorboard / mlflow)
hf auth login # or set HF_TOKEN with write scope (for Hub push)GPU strongly recommended. CPU works only for demos and [SentenceTransformer] StaticEmbedding.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

