Loading...
Loading...
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), and `SparseEncoder` (SPLADE, sparse embedding model; for learned-sparse retrieval). Covers loss selection, hard-negative mining, evaluators, distillation, LoRA, Matryoshka, and Hugging Face Hub publishing. Use for any sentence-transformers training task.
npx skill4agent add huggingface/skills train-sentence-transformersreferences/scripts/scripts/train_<type>_example.pyforce=Trueseed| Tag | Class | What it does | When to pick |
|---|---|---|---|
| [SentenceTransformer] | | Maps each input to a fixed-dim dense vector | Retrieval, similarity, clustering, classification, paraphrase mining, dedup |
| [CrossEncoder] | | Scores | Two-stage retrieval (rerank top-100 from bi-encoder), pair classification |
| [SparseEncoder] | | Sparse vectors over the vocabulary | Learned-sparse retrieval, inverted-index backends (Elasticsearch / OpenSearch / Lucene) |
references/losses_sentence_transformer.mdBatchSamplers.NO_DUPLICATESCached*gradient_checkpointingreferences/evaluators_sentence_transformer.mdmetric_for_best_modelprimary_metricreferences/model_architectures.mdscripts/train_sentence_transformer_example.pyreferences/losses_cross_encoder.mdpos_weightactivation_fn=Identity()references/evaluators_cross_encoder.mdCrossEncoderRerankingEvaluatoreval_{name}_{primary_metric}scripts/train_cross_encoder_example.pyreferences/losses_sparse_encoder.mdSpladeLossreferences/evaluators_sparse_encoder.mdSparseNanoBEIREvaluatoreval_{name}_{primary_metric}scripts/train_sparse_encoder_example.pyreferences/training_args.mdTrainingArgumentstorch_dtype=bfloat16warmup_stepswarmup_ratiosave_stepseval_stepsload_best_model_at_endreferences/dataset_formats.mdreferences/base_model_selection.mdmax_seq_length=8192datasets >= 4references/troubleshooting.mdreferences/hardware_guide.mdreferences/hf_jobs_execution.mdreferences/prompts_and_instructions.mdquery: passage: scripts/train_sentence_transformer_<matryoshka|multi_dataset|with_lora|distillation|make_multilingual|static_embedding>_example.pyscripts/train_cross_encoder_<distillation|listwise>_example.pyscripts/train_sparse_encoder_distillation_example.pyscripts/mine_hard_negatives.pyreferences/training_args.mdpush_to_hub=Truehub_strategy="every_save"references/hf_jobs_execution.mdbaseline_evaltrainer.train()VERDICT: WIN|MARGINAL|REGRESSION | score=... | baseline=... | delta=...httpxhttpcorehuggingface_huburllib3filelockfsspeclogs/{RUN_NAME}.logmodel.push_to_hub(...)try/exceptmax_steps=1SMOKE_TESTEarlyStoppingCallback(patience>=3)query_active_dimscorpus_active_dims..._query_active_dimsscripts/train_<type>_example.pyMODEL_NAMEDATASET_NAMERUN_NAMEreferences/losses_<type>.mdmetric_for_best_modelreferences/evaluators_<type>.mdeval_{name}_{primary_metric}max_steps=1logs/experiments.mdpip install "sentence-transformers[train]>=5.0" # add [train,image] / [audio] / [video] for [SentenceTransformer] multimodal
pip install trackio # optional tracker; or wandb / tensorboard / mlflow
hf auth login # or set HF_TOKEN with write scope (for Hub push)[SentenceTransformer]StaticEmbedding