Skip to content

v1.1.1

Latest
Compare
Choose a tag to compare
@tomaarsen tomaarsen released this 13 Jan 11:26
· 0 commits to main since this release

This is a patch release with two notable fixes:

  • Compatibility with transformers v4.45.2 is introduced; tested up to v4.48.0, including support for finetuning with ModernBERT, e.g. nomic-ai/modernbert-embed-base (see #577)
  • Prevent report_to="none" in the TrainingArguments from being ignored (see #570)
Click to expand a ModernBERT training script
from datasets import load_dataset
from setfit import SetFitModel, Trainer, TrainingArguments

# Load a dataset from the Hugging Face Hub
dataset = load_dataset("sst2")

# Simulate the few-shot regime by sampling 8 examples per class
train_dataset = dataset["train"].select(range(200))
eval_dataset = dataset["validation"].select(range(200))
test_dataset = dataset["validation"].select(range(200, len(dataset["validation"])))

# Load a SetFit model from Hub
model = SetFitModel.from_pretrained(
    "nomic-ai/modernbert-embed-base",
    labels=["negative", "positive"],
)

# Train for 100 steps; log, evaluate (with 100 steps)
args = TrainingArguments(
    batch_size=16,
    max_steps=100,
    logging_steps=10,
    eval_strategy="steps",
    eval_steps=10,
    eval_max_steps=100,
    save_total_limit=-1,
)

trainer = Trainer(
    model=model,
    args=args,
    train_dataset=train_dataset,
    eval_dataset=eval_dataset,
    metric="accuracy",
    column_mapping={"sentence": "text", "label": "label"}
)

# Train and evaluate
trainer.train()
metrics = trainer.evaluate(test_dataset)
print(metrics)
# {'accuracy': 0.9092261904761905}

preds = model.predict(["I loved the spiderman movie!", "Pineapple on pizza is the worst 🤮"])
print(preds)
# ['positive', 'negative']

What's Changed

New Contributors

Full Changelog: v1.1.0...v1.1.1