JavaScript is disabled. Some features may not work.
train-sentence-transformers — ★ 10.7K GitHub Stars — Install Guide | SkillsNav
🇺🇸 English🇨🇳 中文
SkillsNav
Home

train-sentence-transformers

★ 10K repomlN/AIntermediateClaude
🤖 AI Summary

This skill trains a sentence-transformers model for generating semantically meaningful sentence embeddings. It provides production-ready training templates and references for configuring losses, evaluators, and training arguments, rather than generating scripts from scratch.

How to Install

Claude Code:
git clone --depth 1 https://github.com/huggingface/skills.git && cp skills/skills/train-sentence-transformers ~/.claude/skills/train-sentence-transformers -r
# 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__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) | Tiebreakers when the request is ambiguous: "embedding model" / "vector search" / "similarity" → **[SentenceTransformer]**. "rerank" / "ranker" / "two-stage" → **[CrossEncoder]**. "SPLADE" / "sparse" / "inverted index" → **[SparseEncoder]**. 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_DUPLICATES` requirement for MNRL-family; `Cached*` ↔ `gradient_checkpointing` incompatibility. - `references/evaluators_sentence_transformer.md` — evaluator-to-task mapping; `metric_for_best_model` key construction (named vs unnamed); per-evaluator `primary_metric` values. - `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_weight` derivation; `activation_fn=Identity()` mandatory for non-BCE losses (silent eval-rank collapse otherwise). - `references/evaluators_cross_encoder.md` — `CrossEncoderRerankingEvaluator` recipe; named-evaluator key format `eval_{name}_{primary_metric}`. - `scripts/train_cross_encoder_example.py` — production template; copy this as your starting point. **

Details

Category AI/ML → ml
Sourcehuggingface/skills
SKILL.mdView on GitHub →
Repo Stars★ 10.7K
Est. per Skill357 (shared across 30 skills from this repo)
DifficultyIntermediate
Risk LevelN/A

Related Skills

Works Well With

Skills from the same repository — often designed to work together