Adding accuracy, precision, recall and f1 score metrics during training

hi, you can define your computing metric function and pass it into the trainer. Here is an example of computing metrics.

define accuracy metrics function

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, average=‘weighted’)
acc = accuracy_score(labels, preds)
return {
‘accuracy’: acc,
‘f1’: f1,
‘precision’: precision,
‘recall’: recall
}