How to plot loss when using HugginFace's Trainer?
Asked Answered
G

1

7

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)

Gatt answered 23/5, 2022 at 15:8 Comment(0)
M
4

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

Mullen answered 24/10, 2022 at 17:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.