train-sentence-transformers
できること
このスキルは、テキストを検索可能なベクトルに変換するモデルや、二つの文章がどれくらい合うかを採点するモデルを学習させます。検索、マッチング、クラスタリングの機能を作る開発者向けです。
使う場面
- ✓検索や類似度のために、埋め込みモデルを微調整したいとき。
- ✓クエリと本文の組を採点するリランカーを学習させたいとき。
- ✓疎な、またはマルチベクトルの検索モデルを学習させる必要があるとき。
スキルのリンク
https://github.com/huggingface/skills/blob/main/skills/train-sentence-transformers/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“私の、サポートの質問と回答のペアで、sentence-transformersモデルを微調整し、検索を改善してください。”
毎週5つの新しいスキル。1分で読めます。
仕組み
AIは、バイエンコーダー、クロスエンコーダー、SPLADEなどの疎なエンコーダーといった、適切なモデルの種類を選びます。スクリプトを一から書くのではなく、テスト済みの学習テンプレートから始め、あなたのデータに合わせて調整します。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
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, pre
よくある質問
どのモデルの種類を扱いますか?
埋め込み用のバイエンコーダー、リランク用のクロスエンコーダー、SPLADEなどの疎なエンコーダー、マルチベクトルモデルを扱います。
テンプレートから始める理由は?
テンプレートには見落としやすい設定の詳細が含まれているため、そこから始めると一般的な間違いを避けられます。
モデルの種類を選ぶ手助けはありますか?
はい。スキル内の表が、仕事に合うモデルの種類を選ぶ助けになります。
詳細
作者による元の説明
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.
repo: huggingface/skills
人気
- GitHubのスター
- 11k
- ランキング
- #11781
- ライセンス
- Apache-2.0
- 更新日
- 2026/10/30
コメント
- …
このリポジトリの他のスキル
hf-cli
11kエージェントが、Hugging Faceのコマンドラインツールhfでモデル、データセット、Spaces、リポジトリ、ローカルのキャッシュをダウンロード、アップロード、管理できるよう支援します。
hf-cloud-aws-context-discovery
11kエージェントが、クラウドの作業を始める前にAWSのプロファイル、リージョン、アカウントの詳細を見つけ、どのアカウントを使うかを推測しないよう支援します。
hf-cloud-python-env-setup
11kエージェントが、SageMakerやAWSの自動化を実行する前に、適切なPythonのバージョンと最新のライブラリで、クリーンなPython環境を設定できるよう支援します。
hf-cloud-sagemaker-deployment-planner
11kエージェントが、モデルをAmazon SageMakerにデプロイする方法を計画し、リアルタイム、サーバーレス、非同期、バッチのホスティングから、適切な既定値とともに選べるよう支援します。