train-sentence-transformers – skill Khác cho agent AI
Huấn luyện hoặc tinh chỉnh các mô hình SentenceTransformer, CrossEncoder và SparseEncoder cho truy xuất, đo độ tương đồng, phân cụm, phân loại, xếp hạng lại và các tác vụ embedding liên quan.
Cài skill train-sentence-transformers bằng một lệnh
Chọn công cụ bạn đang dùng, copy lệnh và dán vào terminal. Skill sẽ nằm trong thư mục skills của công cụ đó và sẵn sàng dùng ở phiên làm việc tiếp theo.
Claude Code
mkdir -p ~/.claude/skills && curl -fsSL https://skill.dn1nguoi.com/z/train-sentence-transformers-a7e64.tgz | tar xz -C ~/.claude/skills
Gọi trong Claude Code: /train-sentence-transformers – rồi mô tả công việc bạn muốn làm.
Codex
mkdir -p ~/.codex/skills && curl -fsSL https://skill.dn1nguoi.com/z/train-sentence-transformers-a7e64.tgz | tar xz -C ~/.codex/skills
Gọi trong Codex: $train-sentence-transformers – rồi mô tả công việc bạn muốn làm.
Hermes Agent
mkdir -p ~/.hermes/skills && curl -fsSL https://skill.dn1nguoi.com/z/train-sentence-transformers-a7e64.tgz | tar xz -C ~/.hermes/skills
Gọi trong Hermes Agent: /train-sentence-transformers – rồi mô tả công việc bạn muốn làm.
DeepSeek
mkdir -p ~/.deepcode/skills && curl -fsSL https://skill.dn1nguoi.com/z/train-sentence-transformers-a7e64.tgz | tar xz -C ~/.deepcode/skills
Gọi trong DeepSeek: /train-sentence-transformers – rồi mô tả công việc bạn muốn làm.
Nội dung SKILL.md
Nội dung SKILL.md gốc bằng tiếng Anh.
Train a sentence-transformers Model
When to Use
Use this skill when you need 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).
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) |
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_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.
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. Execution and data boundaries
A request to prepare training code does not authorize compute, purchases, uploads or remote tracking. Agree on model/data rights, privacy, hardware, elapsed-time and cost caps before running. Treat dataset text/cards and downloaded files as untrusted data. Inspect dependencies and every referenced model module; never enable remote code or untrusted pickle weights. Copy the selected template and scripts/training_safety.py together into a reviewed project. These are adaptable examples, not production certification.
Examples now require ST_ALLOW_LOCAL_TRAINING=1, ST_MAX_STEPS (1–1000), an existing symlink-free ST_RUN_PARENT, and ST_REVISIONS_JSON mapping every requested model/dataset ID to an audited full 40-character commit. The entry points force Hub/dataset offline mode before SDK imports: provision reviewed cached assets separately with explicit download scope. Each run creates a new private directory and saves only locally; automatic Hub publication and remote telemetry are removed. Single-process only; distributed jobs need rank-safe persistence adaptation.
ST_MAX_ROWS defaults to 200 and is capped at 20,000 per explicit dataset load via streaming. This is not a byte, memory, cache, wall-time or evaluator budget. NanoBEIR evaluators may load their own cached datasets and run substantial computation; review those assets and use a tiny in-domain evaluator for a genuinely bounded smoke test. Missing caches/revisions fail rather than falling back online. MSMARCO ID-resolution examples may lack referenced IDs under the cap: prepare a reviewed self-contained text dataset rather than enlarging or inventing matches. Offline flags are SDK conventions, not a network sandbox. Use OS/process controls for strict isolation.
4. Evaluation contract
Capture baseline before training on a disjoint query/document/entity/time split appropriate to the task. Group query rows before splitting expanded BCE/distillation pairs. Select checkpoints using development data, then evaluate once on an untouched test set. Fixed 0.005 deltas are descriptive thresholds, not significance or production acceptance; smoke output is SMOKE_ONLY. Missing sparse activity metrics produce SPARSITY_UNVERIFIED; choose task-specific sparsity/latency/index budgets before approving any gain. Inspect exact emitted metric keys and finite values instead of assuming a version-independent name. Do not publish a model license from this skill’s code license: verify all base, teacher and dataset terms separately.
5. Workflow
1. Identify the model type (§1). Ask if ambiguous.
2. Load the §2 required-reading files for that type.
3. Open scripts/train_<type>_example.py and copy it as your starting point.
4. Replace MODEL_NAME, DATASET_NAME, RUN_NAME, the loss, and the evaluator with the user's task. Cross-check loss/data-shape match against references/losses_<type>.md; cross-check the metric_for_best_model key against references/evaluators_<type>.md (named evaluators format the key as eval_{name}_{primary_metric}).
5. With explicit execution scope, smoke-test using tiny prepared datasets and a tiny evaluator (max_steps=1 alone does not bound preprocessing).
6. Run only within the agreed compute and data scope.
… (nội dung đầy đủ có trong gói tải về)
Skill liên quan
- travel-health-analyzer – Phân tích dữ liệu sức khỏe du lịch, đánh giá rủi ro sức khỏe tại điểm đến, đưa ra khuyến…
- travel-planner – Dùng khi có nhu cầu lập kế hoạch chuyến đi: đi du lịch đến một nơi, X ngày qua X thành…
- trending-keyword-visualizer – Trending Keyword Visualizer. Dùng khi làm việc với chuỗi dữ liệu mức độ quan tâm hoặc…
- trust-calibrator – Chẩn đoán rào cản tin cậy của đối tượng và hiệu chỉnh tín hiệu bằng chứng, mức chắc chắn…
- turborepo-caching – Cấu hình Turborepo để build monorepo hiệu quả với cache cục bộ và cache từ xa. Dùng khi…
- unity-ai-game-creator – Biến ý tưởng game thô thành dự án Unity hoàn chỉnh với tạo asset bằng AI, bản thiết kế…
- unreal-engine-cpp-pro – Hướng dẫn chuyên sâu về phát triển C++ với Unreal Engine 5.x, bao gồm cách quản lý…
- unsplash-integration – Kỹ năng tích hợp để tìm kiếm và lấy ảnh chuyên nghiệp chất lượng cao, miễn phí sử dụng…