Trainer gives error after 1st epoch and evaluation
Hi I have managed to get my code working for training, yet after 1 epoch I am getting weird results for the evaluation and also an errorTrainer is attempting to log a value of "[0. 0. 0. 1. 0.]" of type 
<class 'numpy.ndarray'> for key "eval/recall" as a scalar. This 
invocation of Tensorboard's writer.add_scalar() is incorrect 
so we dropped this attribute.and then an errorTypeError: Object of type ndarray is not JSON serializableI used the compute_metrics (measure accuracy, f1, precision and accuracy) provided by the tutorial and I am doing a classification task with 5 task.
2021-02-25T13:44:32Z
I used the compute_metrics (measure accuracy, f1, precision and accuracy) provided by the tutorial and I am doing a classification task with 5 task.Could you tell us which tutorial? From the error message, it seems your metric value is a NumPy array, so sharing yourcompute_metricfunction would also help.
2021-02-25T14:32:58Z
Of course. it is from theTraining and Finetuningtutorial and this is my code:# Metrics
from sklearn.metrics import accuracy_score, precision_recall_fscore_support

def compute_metrics(pred):
    labels = pred.label_ids
    preds = pred.predictions.argmax(-1)
   precision, recall, f1, _ = precision_recall_fscore_support(labels, preds)
   acc = accuracy_score(labels, preds)
   return {
        'accuracy': acc,
        'f1': f1,
        'precision': precision,
       'recall': recall
    }
2021-02-25T14:37:56Z
precision_recall_fscore_supportrequires an argument average to return simple numbers (and not arrays). See thedocto choose the one that suits your need here.
2023-06-02T14:40:55Z
I ran into an issue like this when I inadvertently logged a metric in the trainer that was a Tensor instead of just a float. I did something likeaverage_scores.mean(), which returned a Tensor object, which was somehow affixed toTrainer.stateand then broke json-saving. I changed the metric computation toaverage_scores.mean().item()and this fixed the issue.