Migration Guide
Migrating from v2.x to v3.x
The v3 Sentence Transformers release refactored the training of SentenceTransformer
embedding models, replacing SentenceTransformer.fit
with a SentenceTransformerTrainer
and SentenceTransformerTrainingArguments
. This update softly deprecated SentenceTransformer.fit
, meaning that it still works, but it’s recommended to switch to the new v3.x training format. Behind the scenes, this method now uses the new trainer.
Warning
If you don’t have code that uses SentenceTransformer.fit
, then you will not have to make any changes to your code to update from v2.x to v3.x.
If you do, your code still works, but it is recommended to switch to the new v3.x training format, as it allows more training arguments and functionality. See the Training Overview for more details.
v2.x |
v3.x (recommended) |
---|---|
from sentence_transformers import SentenceTransformer, InputExample, losses
from torch.utils.data import DataLoader
# 1. Define the model. Either from scratch of by loading a pre-trained model
model = SentenceTransformer("microsoft/mpnet-base")
# 2. Define your train examples. You need more than just two examples...
train_examples = [
InputExample(texts=[
"A person on a horse jumps over a broken down airplane.",
"A person is outdoors, on a horse.",
"A person is at a diner, ordering an omelette.",
]),
InputExample(texts=[
"Children smiling and waving at camera",
"There are children present",
"The kids are frowning",
]),
]
train_dataloader = DataLoader(train_examples, shuffle=True, batch_size=16)
# 3. Define a loss function
train_loss = losses.MultipleNegativesRankingLoss(model)
# 4. Finetune the model
model.fit(
train_objectives=[(train_dataloader, train_loss)],
epochs=1,
warmup_steps=100,
)
# 5. Save the trained model
model.save_pretrained("models/mpnet-base-all-nli")
|
from datasets import load_dataset
from sentence_transformers import SentenceTransformer, SentenceTransformerTrainer
from sentence_transformers.losses import MultipleNegativesRankingLoss
# 1. Define the model. Either from scratch of by loading a pre-trained model
model = SentenceTransformer("microsoft/mpnet-base")
# 2. Load a dataset to finetune on
dataset = load_dataset("sentence-transformers/all-nli", "triplet")
train_dataset = dataset["train"].select(range(10_000))
eval_dataset = dataset["dev"].select(range(1_000))
# 3. Define a loss function
loss = MultipleNegativesRankingLoss(model)
# 4. Create a trainer & train
trainer = SentenceTransformerTrainer(
model=model,
train_dataset=train_dataset,
eval_dataset=eval_dataset,
loss=loss,
)
trainer.train()
# 5. Save the trained model
model.save_pretrained("models/mpnet-base-all-nli")
# model.push_to_hub("mpnet-base-all-nli")
|
Migration for specific parameters from SentenceTransformer.fit
SentenceTransformer.fit(train_objectives)
v2.x |
v3.x (recommended) |
---|---|
from sentence_transformers import SentenceTransformer, InputExample, losses
from torch.utils.data import DataLoader
# Define a training dataloader
train_examples = [
InputExample(texts=[
"A person on a horse jumps over a broken down airplane.",
"A person is outdoors, on a horse.",
"A person is at a diner, ordering an omelette.",
]),
InputExample(texts=[
"Children smiling and waving at camera",
"There are children present",
"The kids are frowning",
]),
]
train_dataloader = DataLoader(train_examples, shuffle=True, batch_size=16)
# Define a loss function
train_loss = losses.MultipleNegativesRankingLoss(model)
# Finetune the model
model.fit(train_objectives=[(train_dataloader, train_loss)])
|
from datasets import Dataset
from sentence_transformers import SentenceTransformer, SentenceTransformerTrainer
from sentence_transformers.losses import MultipleNegativesRankingLoss
# Define a training dataset
train_examples = [
{
"anchor": "A person on a horse jumps over a broken down airplane.",
"positive": "A person is outdoors, on a horse.",
"negative": "A person is at a diner, ordering an omelette.",
},
{
"anchor": "Children smiling and waving at camera",
"positive": "There are children present",
"negative": "The kids are frowning",
},
]
train_dataset = Dataset.from_list(train_examples)
# Define a loss function
loss = MultipleNegativesRankingLoss(model)
# Finetune the model
trainer = SentenceTransformerTrainer(
model=model,
train_dataset=train_dataset,
loss=loss,
)
trainer.train()
|
SentenceTransformer.fit(evaluator)
v2.x |
v3.x (recommended) |
---|---|
...
# Load an evaluator
evaluator = NanoBEIREvaluator()
# Finetune with an evaluator
model.fit(
train_objectives=[(train_dataloader, train_loss)],
evaluator=evaluator,
)
|
# Load an evaluator
evaluator = NanoBEIREvaluator()
# Finetune with an evaluator
trainer = SentenceTransformerTrainer(
model=model,
train_dataset=train_dataset,
eval_dataset=eval_dataset,
loss=loss,
evaluator=evaluator,
)
trainer.train()
|
SentenceTransformer.fit(epochs)
v2.x |
v3.x (recommended) |
---|---|
...
# Finetune the model
model.fit(
train_objectives=[(train_dataloader, train_loss)],
epochs=1,
)
|
...
# Prepare the Training Arguments
args = SentenceTransformerTrainingArguments(
num_train_epochs=1,
)
# Finetune the model
trainer = SentenceTransformerTrainer(
model=model,
args=args,
train_dataset=train_dataset,
loss=loss,
)
trainer.train()
|
SentenceTransformer.fit(steps_per_epoch)
v2.x |
v3.x (recommended) |
---|---|
...
# Finetune the model
model.fit(
train_objectives=[(train_dataloader, train_loss)],
steps_per_epoch=1000,
)
|
...
# Prepare the Training Arguments
args = SentenceTransformerTrainingArguments(
max_steps=1000, # Note: max_steps is across all epochs, not per epoch
)
# Finetune the model
trainer = SentenceTransformerTrainer(
model=model,
args=args,
train_dataset=train_dataset,
loss=loss,
)
trainer.train()
|
SentenceTransformer.fit(scheduler)
v2.x |
v3.x (recommended) |
---|---|
...
# Finetune the model
model.fit(
train_objectives=[(train_dataloader, train_loss)],
scheduler="WarmupLinear",
)
|
...
# Prepare the Training Arguments
args = SentenceTransformerTrainingArguments(
# See https://huggingface.co/docs/transformers/main_classes/optimizer_schedules#transformers.SchedulerType
lr_scheduler_type="linear"
)
# Finetune the model
trainer = SentenceTransformerTrainer(
model=model,
args=args,
train_dataset=train_dataset,
loss=loss,
)
trainer.train()
|
SentenceTransformer.fit(warmup_steps)
v2.x |
v3.x (recommended) |
---|---|
...
# Finetune the model
model.fit(
train_objectives=[(train_dataloader, train_loss)],
warmup_steps=1000,
)
|
...
# Prepare the Training Arguments
args = SentenceTransformerTrainingArguments(
warmup_steps=1000,
)
# Finetune the model
trainer = SentenceTransformerTrainer(
model=model,
args=args,
train_dataset=train_dataset,
loss=loss,
)
trainer.train()
|
SentenceTransformer.fit(optimizer_class, optimizer_params)
v2.x |
v3.x (recommended) |
---|---|
...
# Finetune the model
model.fit(
train_objectives=[(train_dataloader, train_loss)],
optimizer_class=torch.optim.AdamW,
optimizer_params={"eps": 1e-7},
)
|
...
# Prepare the Training Arguments
args = SentenceTransformerTrainingArguments(
# See https://github.com/huggingface/transformers/blob/main/src/transformers/training_args.py
optim="adamw_torch",
optim_args={"eps": 1e-7},
)
# Finetune the model
trainer = SentenceTransformerTrainer(
model=model,
args=args,
train_dataset=train_dataset,
loss=loss,
)
trainer.train()
|
SentenceTransformer.fit(weight_decay)
v2.x |
v3.x (recommended) |
---|---|
...
# Finetune the model
model.fit(
train_objectives=[(train_dataloader, train_loss)],
weight_decay=0.02,
)
|
...
# Prepare the Training Arguments
args = SentenceTransformerTrainingArguments(
weight_decay=0.02,
)
# Finetune the model
trainer = SentenceTransformerTrainer(
model=model,
args=args,
train_dataset=train_dataset,
loss=loss,
)
trainer.train()
|
SentenceTransformer.fit(evaluation_steps)
v2.x |
v3.x (recommended) |
---|---|
...
# Finetune the model
model.fit(
train_objectives=[(train_dataloader, train_loss)],
evaluator=evaluator,
evaluation_steps=1000,
)
|
...
# Prepare the Training Arguments
args = SentenceTransformerTrainingArguments(
eval_strategy="steps",
eval_steps=1000,
)
# Finetune the model
# Note: You need an eval_dataset and/or evaluator to evaluate
trainer = SentenceTransformerTrainer(
model=model,
args=args,
train_dataset=train_dataset,
eval_dataset=eval_dataset,
loss=loss,
evaluator=evaluator,
)
trainer.train()
|
SentenceTransformer.fit(output_path, save_best_model)
v2.x |
v3.x (recommended) |
---|---|
...
# Finetune the model
model.fit(
train_objectives=[(train_dataloader, train_loss)],
evaluator=evaluator,
output_path="my/path",
save_best_model=True,
)
|
...
# Prepare the Training Arguments
args = SentenceTransformerTrainingArguments(
load_best_model_at_end=True,
metric_for_best_model="all_nli_cosine_accuracy", # E.g. `evaluator.primary_metric`
)
# Finetune the model
trainer = SentenceTransformerTrainer(
model=model,
args=args,
train_dataset=train_dataset,
loss=loss,
)
trainer.train()
# Save the best model at my output path
model.save_pretrained("my/path")
|
SentenceTransformer.fit(max_grad_norm)
v2.x |
v3.x (recommended) |
---|---|
...
# Finetune the model
model.fit(
train_objectives=[(train_dataloader, train_loss)],
max_grad_norm=1,
)
|
...
# Prepare the Training Arguments
args = SentenceTransformerTrainingArguments(
max_grad_norm=1,
)
# Finetune the model
trainer = SentenceTransformerTrainer(
model=model,
args=args,
train_dataset=train_dataset,
loss=loss,
)
trainer.train()
|
SentenceTransformer.fit(use_amp)
v2.x |
v3.x (recommended) |
---|---|
...
# Finetune the model
model.fit(
train_objectives=[(train_dataloader, train_loss)],
use_amp=True,
)
|
...
# Prepare the Training Arguments
args = SentenceTransformerTrainingArguments(
fp16=True,
bf16=False, # If your GPU supports it, you can also use bf16 instead
)
# Finetune the model
trainer = SentenceTransformerTrainer(
model=model,
args=args,
train_dataset=train_dataset,
loss=loss,
)
trainer.train()
|
SentenceTransformer.fit(callback)
v2.x |
v3.x (recommended) |
---|---|
...
def printer_callback(score, epoch, steps):
print(f"Score: {score:.4f} at epoch {epoch:d}, step {steps:d}")
# Finetune the model
model.fit(
train_objectives=[(train_dataloader, train_loss)],
callback=printer_callback,
)
|
from transformers import TrainerCallback
...
class PrinterCallback(TrainerCallback):
# Subclass any method from https://huggingface.co/docs/transformers/main_classes/callback#transformers.TrainerCallback
def on_evaluate(self, args, state, control, metrics=None, **kwargs):
print(f"Metrics: {metrics} at epoch {state.epoch:d}, step {state.global_step:d}")
printer_callback = PrinterCallback()
# Finetune the model
trainer = SentenceTransformerTrainer(
model=model,
train_dataset=train_dataset,
loss=loss,
callbacks=[printer_callback],
)
trainer.train()
|
SentenceTransformer.fit(checkpoint_path, checkpoint_save_steps, checkpoint_save_total_limit)
v2.x |
v3.x (recommended) |
---|---|
...
# Finetune the model
model.fit(
train_objectives=[(train_dataloader, train_loss)],
checkpoint_path="checkpoints",
checkpoint_save_steps=5000,
checkpoint_save_total_limit=2,
)
|
...
# Prepare the Training Arguments
args = SentenceTransformerTrainingArguments(
eval_strategy="steps",
eval_steps=5000,
save_strategy="steps",
save_steps=5000,
save_total_limit=2,
)
# Finetune the model
# Note: You need an eval_dataset and/or evaluator to checkpoint
trainer = SentenceTransformerTrainer(
model=model,
args=args,
train_dataset=train_dataset,
eval_dataset=eval_dataset,
loss=loss,
)
trainer.train()
|
Migration for custom Datasets and DataLoaders used in SentenceTransformer.fit
v2.x |
v3.x (recommended) |
---|---|
|
Manually creating a |
|
Loading or creating a |
|
Manually adding a column with noisy text to a |
|
Loading or creating a |
Migrating from v3.x to v4.x
The v4 Sentence Transformers release refactored the training of CrossEncoder
reranker/pair classification models, replacing CrossEncoder.fit
with a CrossEncoderTrainer
and CrossEncoderTrainingArguments
. Like with v3 and SentenceTransformer
models, this update softly deprecated CrossEncoder.fit
, meaning that it still works, but it’s recommended to switch to the new v4.x training format. Behind the scenes, this method now uses the new trainer.
Warning
If you don’t have code that uses CrossEncoder.fit
, then you will not have to make any changes to your code to update from v3.x to v4.x.
If you do, your code still works, but it is recommended to switch to the new v4.x training format, as it allows more training arguments and functionality. See the Training Overview for more details.
v3.x |
v4.x (recommended) |
---|---|
from sentence_transformers import CrossEncoder, InputExample
from torch.utils.data import DataLoader
# 1. Define the model. Either from scratch of by loading a pre-trained model
model = CrossEncoder("microsoft/mpnet-base")
# 2. Define your train examples. You need more than just two examples...
train_examples = [
InputExample(texts=["What are pandas?", "The giant panda ..."], label=1),
InputExample(texts=["What's a panda?", "Mount Vesuvius is a ..."], label=0),
]
train_dataloader = DataLoader(train_examples, shuffle=True, batch_size=16)
# 3. Finetune the model
model.fit(train_dataloader=train_dataloader, epochs=1, warmup_steps=100)
|
from datasets import load_dataset
from sentence_transformers import CrossEncoder, CrossEncoderTrainer
from sentence_transformers.cross_encoder.losses import BinaryCrossEntropyLoss
# 1. Define the model. Either from scratch of by loading a pre-trained model
model = CrossEncoder("microsoft/mpnet-base")
# 2. Load a dataset to finetune on, convert to required format
dataset = load_dataset("sentence-transformers/hotpotqa", "triplet", split="train")
def triplet_to_labeled_pair(batch):
anchors = batch["anchor"]
positives = batch["positive"]
negatives = batch["negative"]
return {
"sentence_A": anchors * 2,
"sentence_B": positives + negatives,
"labels": [1] * len(positives) + [0] * len(negatives),
}
dataset = dataset.map(triplet_to_labeled_pair, batched=True, remove_columns=dataset.column_names)
train_dataset = dataset.select(range(10_000))
eval_dataset = dataset.select(range(10_000, 11_000))
# 3. Define a loss function
loss = BinaryCrossEntropyLoss(model)
# 4. Create a trainer & train
trainer = CrossEncoderTrainer(
model=model,
train_dataset=train_dataset,
eval_dataset=eval_dataset,
loss=loss,
)
trainer.train()
# 5. Save the trained model
model.save_pretrained("models/mpnet-base-hotpotqa")
# model.push_to_hub("mpnet-base-hotpotqa")
|
Migration for parameters on CrossEncoder
initialization and methods
v3.x |
v4.x (recommended) |
---|---|
|
Renamed to |
|
Renamed to |
|
Renamed to |
|
Renamed to |
|
Renamed to |
|
Renamed to |
|
Use |
|
Renamed to |
|
Renamed to |
|
Fully deprecated, no longer has any effect. |
|
Fully deprecated, no longer has any effect. |
Note
The old keyword arguments still work, but they will emit a warning recommending you to use the new names instead.
Migration for specific parameters from CrossEncoder.fit
CrossEncoder.fit(train_dataloader)
v3.x |
v4.x (recommended) |
---|---|
from sentence_transformers import CrossEncoder, InputExample
from torch.utils.data import DataLoader
# 1. Define the model. Either from scratch of by loading a pre-trained model
model = CrossEncoder("microsoft/mpnet-base")
# 2. Define your train examples. You need more than just two examples...
train_examples = [
InputExample(texts=["What are pandas?", "The giant panda ..."], label=1),
InputExample(texts=["What's a panda?", "Mount Vesuvius is a ..."], label=0),
]
train_dataloader = DataLoader(train_examples, shuffle=True, batch_size=16)
# 3. Finetune the model
model.fit(train_dataloader=train_dataloader)
|
from datasets import Dataset
from sentence_transformers import CrossEncoder, CrossEncoderTrainer
from sentence_transformers.cross_encoder.losses import BinaryCrossEntropyLoss
# Define a training dataset
train_examples = [
{
"sentence_1": "A person on a horse jumps over a broken down airplane.",
"sentence_2": "A person is outdoors, on a horse.",
"label": 1,
},
{
"sentence_1": "Children smiling and waving at camera",
"sentence_2": "The kids are frowning",
"label": 0,
},
]
train_dataset = Dataset.from_list(train_examples)
# Define a loss function
loss = BinaryCrossEntropyLoss(model)
# Finetune the model
trainer = CrossEncoderTrainer(
model=model,
train_dataset=train_dataset,
loss=loss,
)
trainer.train()
|
CrossEncoder.fit(loss_fct)
v3.x |
v4.x (recommended) |
---|---|
...
# Finetune the model
model.fit(
train_dataloader=train_dataloader,
loss_fct=torch.nn.MSELoss(),
)
|
from sentence_transformers.cross_encoder.losses import MSELoss
...
# Prepare the loss function
# See all valid losses in https://sbert.net/docs/cross_encoder/loss_overview.html
loss = MSELoss(model)
# Finetune the model
trainer = CrossEncoderTrainer(
model=model,
args=args,
train_dataset=train_dataset,
loss=loss,
)
trainer.train()
|
CrossEncoder.fit(evaluator)
v3.x |
v4.x (recommended) |
---|---|
...
# Load an evaluator
evaluator = CrossEncoderNanoBEIREvaluator()
# Finetune with an evaluator
model.fit(
train_dataloader=train_dataloader,
evaluator=evaluator,
)
|
# Load an evaluator
evaluator = CrossEncoderNanoBEIREvaluator()
# Finetune with an evaluator
trainer = CrossEncoderTrainer(
model=model,
train_dataset=train_dataset,
eval_dataset=eval_dataset,
loss=loss,
evaluator=evaluator,
)
trainer.train()
|
CrossEncoder.fit(epochs)
v3.x |
v4.x (recommended) |
---|---|
...
# Finetune the model
model.fit(
train_dataloader=train_dataloader,
epochs=1,
)
|
...
# Prepare the Training Arguments
args = CrossEncoderTrainingArguments(
num_train_epochs=1,
)
# Finetune the model
trainer = CrossEncoderTrainer(
model=model,
args=args,
train_dataset=train_dataset,
loss=loss,
)
trainer.train()
|
CrossEncoder.fit(activation_fct)
v3.x |
v4.x (recommended) |
---|---|
...
# Finetune the model
model.fit(
train_dataloader=train_dataloader,
activation_fct=torch.nn.Sigmoid(),
)
|
...
# Prepare the loss function
loss = MSELoss(model, activation_fn=torch.nn.Sigmoid())
# Finetune the model
trainer = CrossEncoderTrainer(
model=model,
args=args,
train_dataset=train_dataset,
loss=loss,
)
trainer.train()
|
CrossEncoder.fit(scheduler)
v3.x |
v4.x (recommended) |
---|---|
...
# Finetune the model
model.fit(
train_dataloader=train_dataloader,
scheduler="WarmupLinear",
)
|
...
# Prepare the Training Arguments
args = CrossEncoderTrainingArguments(
# See https://huggingface.co/docs/transformers/main_classes/optimizer_schedules#transformers.SchedulerType
lr_scheduler_type="linear"
)
# Finetune the model
trainer = CrossEncoderTrainer(
model=model,
args=args,
train_dataset=train_dataset,
loss=loss,
)
trainer.train()
|
CrossEncoder.fit(warmup_steps)
v3.x |
v4.x (recommended) |
---|---|
...
# Finetune the model
model.fit(
train_dataloader=train_dataloader,
warmup_steps=1000,
)
|
...
# Prepare the Training Arguments
args = CrossEncoderTrainingArguments(
warmup_steps=1000,
)
# Finetune the model
trainer = CrossEncoderTrainer(
model=model,
args=args,
train_dataset=train_dataset,
loss=loss,
)
trainer.train()
|
CrossEncoder.fit(optimizer_class, optimizer_params)
v3.x |
v4.x (recommended) |
---|---|
...
# Finetune the model
model.fit(
train_dataloader=train_dataloader,
optimizer_class=torch.optim.AdamW,
optimizer_params={"eps": 1e-7},
)
|
...
# Prepare the Training Arguments
args = CrossEncoderTrainingArguments(
# See https://github.com/huggingface/transformers/blob/main/src/transformers/training_args.py
optim="adamw_torch",
optim_args={"eps": 1e-7},
)
# Finetune the model
trainer = CrossEncoderTrainer(
model=model,
args=args,
train_dataset=train_dataset,
loss=loss,
)
trainer.train()
|
CrossEncoder.fit(weight_decay)
v3.x |
v4.x (recommended) |
---|---|
...
# Finetune the model
model.fit(
train_dataloader=train_dataloader,
weight_decay=0.02,
)
|
...
# Prepare the Training Arguments
args = CrossEncoderTrainingArguments(
weight_decay=0.02,
)
# Finetune the model
trainer = CrossEncoderTrainer(
model=model,
args=args,
train_dataset=train_dataset,
loss=loss,
)
trainer.train()
|
CrossEncoder.fit(evaluation_steps)
v3.x |
v4.x (recommended) |
---|---|
...
# Finetune the model
model.fit(
train_dataloader=train_dataloader,
evaluator=evaluator,
evaluation_steps=1000,
)
|
...
# Prepare the Training Arguments
args = CrossEncoderTrainingArguments(
eval_strategy="steps",
eval_steps=1000,
)
# Finetune the model
# Note: You need an eval_dataset and/or evaluator to evaluate
trainer = CrossEncoderTrainer(
model=model,
args=args,
train_dataset=train_dataset,
eval_dataset=eval_dataset,
loss=loss,
evaluator=evaluator,
)
trainer.train()
|
CrossEncoder.fit(output_path, save_best_model)
v3.x |
v4.x (recommended) |
---|---|
...
# Finetune the model
model.fit(
train_dataloader=train_dataloader,
evaluator=evaluator,
output_path="my/path",
save_best_model=True,
)
|
...
# Prepare the Training Arguments
args = CrossEncoderTrainingArguments(
load_best_model_at_end=True,
metric_for_best_model="hotpotqa_ndcg@10", # E.g. `evaluator.primary_metric`
)
# Finetune the model
trainer = CrossEncoderTrainer(
model=model,
args=args,
train_dataset=train_dataset,
loss=loss,
)
trainer.train()
# Save the best model at my output path
model.save_pretrained("my/path")
|
CrossEncoder.fit(max_grad_norm)
v3.x |
v4.x (recommended) |
---|---|
...
# Finetune the model
model.fit(
train_dataloader=train_dataloader,
max_grad_norm=1,
)
|
...
# Prepare the Training Arguments
args = CrossEncoderTrainingArguments(
max_grad_norm=1,
)
# Finetune the model
trainer = CrossEncoderTrainer(
model=model,
args=args,
train_dataset=train_dataset,
loss=loss,
)
trainer.train()
|
CrossEncoder.fit(use_amp)
v3.x |
v4.x (recommended) |
---|---|
...
# Finetune the model
model.fit(
train_dataloader=train_dataloader,
use_amp=True,
)
|
...
# Prepare the Training Arguments
args = CrossEncoderTrainingArguments(
fp16=True,
bf16=False, # If your GPU supports it, you can also use bf16 instead
)
# Finetune the model
trainer = CrossEncoderTrainer(
model=model,
args=args,
train_dataset=train_dataset,
loss=loss,
)
trainer.train()
|
CrossEncoder.fit(callback)
v3.x |
v4.x (recommended) |
---|---|
...
def printer_callback(score, epoch, steps):
print(f"Score: {score:.4f} at epoch {epoch:d}, step {steps:d}")
# Finetune the model
model.fit(
train_dataloader=train_dataloader,
callback=printer_callback,
)
|
from transformers import TrainerCallback
...
class PrinterCallback(TrainerCallback):
# Subclass any method from https://huggingface.co/docs/transformers/main_classes/callback#transformers.TrainerCallback
def on_evaluate(self, args, state, control, metrics=None, **kwargs):
print(f"Metrics: {metrics} at epoch {state.epoch:d}, step {state.global_step:d}")
printer_callback = PrinterCallback()
# Finetune the model
trainer = CrossEncoderTrainer(
model=model,
train_dataset=train_dataset,
loss=loss,
callbacks=[printer_callback],
)
trainer.train()
|
Note
The old CrossEncoder.fit
method still works, it was only softly deprecated. It now uses the new CrossEncoderTrainer
behind the scenes.
Migration for CrossEncoder evaluators
v3.x |
v4.x (recommended) |
---|---|
|
Use |
|
Use |
|
Use |
|
Use |
|
Use |
|
Renamed to |
Note
The old evaluators still work, they will simply warn you to update to the new evaluators.