Hello, I’m new to Hugging Face and I have a question regarding the huggingface.transformers Trainer class. How do we get the predicted labels per epoch or step for the huggingface.transformers Trainer?
Thank you.
I think you need to define a compute metric function which get your prediction and return the accuracy.
def compute_metrics(pred):
labels = pred.label_ids
preds = pred.predictions.argmax(-1)
precision, recall, f1, _ = precision_recall_fscore_support(labels, preds)
precision_ma, recall_ma, f1_ma, _ = precision_recall_fscore_support(labels, preds, average=‘macro’)
precision_mi, recall_mi, f1_mi, _ = precision_recall_fscore_support(labels, preds, average=‘micro’)
acc = accuracy_score(labels, preds)
return {
‘accuracy’: acc,
‘f1’: f1} and pass it to the trainer