I have a multi class single label text classification problem (i.e. lots of classes, only 1 is correct). The following code snippet calculates the “top-1 accuracy” score. However, I require “top-5 accuracy” (or in deed k) as well to be reported. Since the only input is eval_pred I am not sure how I can add this. Can someone please assist or point me toward the docs that show this (have looked cannot find)
def compute_metrics(eval_pred):
metric = evaluate.load("accuracy")
logits, labels = eval_pred
predictions = np.argmax(logits, axis=-1)
return metric.compute(predictions=predictions, references=labels)