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는 bi-encoder, cross-encoder, 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
자주 묻는 질문
어떤 모델 유형을 다루나요?
임베딩용 bi-encoder, 리랭킹용 cross-encoder, 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에이전트가 hf 명령줄 도구로 Hugging Face Hub의 모델, 데이터셋, Space, 저장소를 내려받고 올리며 로컬 캐시를 관리하도록 돕습니다.
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에 배포하는 방법을 계획하고, 실시간, 서버리스, 비동기, 배치 호스팅 중 합리적인 기본값으로 고르도록 돕습니다.