# Plotting train accuracy and loss with Trainer

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fplotting-train-accuracy-and-loss-with-trainer%2F74525%3E%5C
**Category:** 🤗Transformers\
**Created:** [February 23, 2024, 3:28pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fplotting-train-accuracy-and-loss-with-trainer%2F74525 "2024-02-23T15:28:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Starlightt](https://avatars.discourse-cdn.com/v4/letter/s/76d3ee/32.png) [@Starlightt](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FStarlightt)%5C
**Post date:** [February 23, 2024, 3:28pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fplotting-train-accuracy-and-loss-with-trainer%2F74525%2F1 "2024-02-23T15:28:48Z")

</div>

can anyone help me for this code, I want build plot the training and validation loss, as well as the training and validation accuracy in Trainer(), but i have some problem to displaying training accuracy? how could i display the train accuracy? and this is my code

```auto

from transformers import TrainingArguments

training_args = TrainingArguments(
    "test_trainer",
    per_device_train_batch_size=2,
    learning_rate=1e-05,
    num_train_epochs=2.0,
    evaluation_strategy = "epoch", #To calculate metrics per epoch
    logging_strategy="epoch" #Extra: to log training data stats for loss
)

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)

torch.cuda.empty_cache()

trainer = Trainer(
    model=model,
    args=training_args,
    train_dataset=train_dataset_cluster_1,
    eval_dataset=eval_dataset_cluster_1,
    compute_metrics=compute_metrics,
)
training_history = trainer.train()

```

---

<div class="post-metadata">

**Author:** ![nielsr](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/nielsr/32/39617_2.png) [@nielsr](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fnielsr)%5C
**Post date:** [February 25, 2024, 9:03pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fplotting-train-accuracy-and-loss-with-trainer%2F74525%2F2 "2024-02-25T21:03:00Z")

</div>

Hi,

Refer to this thread: [Metrics for Training Set in Trainer](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fmetrics-for-training-set-in-trainer%2F2461)

---

<div class="post-metadata">

**Author:** ![Starlightt](https://avatars.discourse-cdn.com/v4/letter/s/76d3ee/32.png) [@Starlightt](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FStarlightt)%5C
**Post date:** [February 27, 2024, 12:38pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fplotting-train-accuracy-and-loss-with-trainer%2F74525%2F3 "2024-02-27T12:38:52Z")

</div>

can u help me in personal? im just newbie in machine learning and im so confused to adjust my coding with ur recommendation, I have tried the code you suggested but doesn’t still work
