Finetuning multi-vector (a.k.a. late-interaction or ColBERT-style) models heavily improves their retrieval performance on your specific domain: the vocabulary, the query style,…
Training Overview
Why Finetune?
Finetuning multi-vector (a.k.a. late-interaction or ColBERT-style) models heavily improves their retrieval performance on your specific domain: the vocabulary, the query style, and the notion of relevance all differ between e.g. web search, legal discovery, code search, and scientific literature review. Because queries and documents are matched token by token with MaxSim, multi-vector models pick up fine-grained domain signals that single-vector models tend to average away, and they typically respond very well to even modest amounts of in-domain finetuning data.
Also see Training Examples for training scripts for common real-world recipes that you can adopt.
Training Components
Training MultiVectorEncoder models involves between 4 to 6 components:
Model
Learn how to initialize the model for training.
Dataset
Learn how to prepare the data for training.
Loss Function
Learn how to prepare and choose a loss function.
Training Arguments
Learn which training arguments are useful.
Evaluator
Learn how to evaluate during and after training.
Trainer
Learn how to start the training process.
Model
Dataset
Dataset Format
Multimodal Datasets
Loss Function
Loss functions quantify how well a model performs for a given batch of data, allowing an optimizer to update the model weights to produce more favourable (i.e., lower) loss values. This is the core of the training process.
Sadly, there is no single loss function that works best for all use-cases. Instead, which loss function to use greatly depends on your available data and on your target task. See Dataset Format to learn what datasets are valid for which loss functions. Additionally, the Loss Overview will be your best friend to learn about the options.
Training Arguments
Key Training Arguments for improving training performance
learning_rate
lr_scheduler_type
warmup_steps
num_train_epochs
max_steps
per_device_train_batch_size
per_device_eval_batch_size
auto_find_batch_size
fp16
bf16
load_best_model_at_end
metric_for_best_model
gradient_accumulation_steps
activation_checkpointing
eval_accumulation_steps
optim
batch_sampler
multi_dataset_batch_sampler
router_mapping
learning_rate_mapping
Key Training Arguments for observing training performance
eval_strategy
eval_steps
save_strategy
save_steps
save_total_limit
report_to
run_name
log_level
logging_steps
push_to_hub
hub_model_id
hub_strategy
hub_private_repo
args = MultiVectorEncoderTrainingArguments(
# Required parameter:
output_dir="models/multivector-ModernBERT-base-msmarco",
# Optional training parameters:
num_train_epochs=1,
per_device_train_batch_size=32,
per_device_eval_batch_size=32,
learning_rate=3e-5,
warmup_steps=0.05,
fp16=False, # Set to True if your GPU doesn't support BF16
bf16=True, # Set to True if you have a GPU that supports BF16
batch_sampler=BatchSamplers.NO_DUPLICATES, # losses that use "in-batch negatives" benefit from no duplicates
# Optional tracking/debugging parameters:
eval_strategy="steps",
eval_steps=0.1,
save_strategy="steps",
save_steps=0.1,
save_total_limit=2,
logging_steps=0.01,
run_name="multivector-ModernBERT-base-msmarco", # Will be used in W&B if `wandb` is installed
)
Evaluator
Trainer
Callbacks
Multi-Dataset Training
Training Tips
Comparisons with SentenceTransformer Training
End-to-End Example
For a complete end-to-end training example, see the Training and Finetuning Multi-Vector Embedding Models blogpost. It applies the components described on this page to a real training task.
Source and license
Source: Sentence Transformers documentation, adapted for this site. Licensing and attribution follow the terms of the upstream project.