Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to plot loss when using HugginFace's Trainer?

While finetuning a model using HF's trainer.

training_args = TrainingArguments(output_dir=data_dir + "test_trainer")

metric = load_metric("accuracy")

def compute_metrics(eval_pred):
    logits, labels = eval_pred
    predictions = np.argmax(logits, axis=-1)
    return metric.compute(predictions=predictions, references=labels)

training_args = TrainingArguments(num_train_epochs=5,per_device_train_batch_size=64,per_device_eval_batch_size=32,output_dir="test_trainer", evaluation_strategy="epoch")

trainer = Trainer(
    model=model,
    args=training_args,
    train_dataset=train_dataset,
    eval_dataset=val_dataset,
    compute_metrics=compute_metrics,
)
trainer.train()

How would I be able to plot the loss in a notebook?
(Perhaps Is it possible to get a list of the loss)

like image 761
Sahar Millis Avatar asked Jun 30 '26 04:06

Sahar Millis


1 Answers

It is possible to get a list of losses. You can access the history of logs after training is complete with: trainer.state.log_history

like image 165
deadmau5p Avatar answered Jul 02 '26 19:07

deadmau5p



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!