Transform Logits to probabilities doesn't work
Hello,I finetuned a BertforSequenceClassification model in order to perform a multiclass classification. However, when my model is finetuned I predict my test dataset with:preds_output = trainer.predict(data_encoded['test'])So I am able to get my predicted output with:preds_output.predictionsThis should return 2 arrays. One including the logits and another including the predicted classes. Now I want to get the probabilty the classes are predicted with instead of the logits. When I try to do that withfrom torch import nn

probabilities = nn.functional.softmax(preds_output.predictions, dim=-1)
print(probabilities)I get the error that ‘numpy.ndarray’ object has no attribute ‘softmax’. Any idea what can help? Thank you guys
2022-02-16T15:36:58Z
The predictions are a NumPy array, so you need to convert them to a torch Tensor if you want to use PyTorch functions on them.
2022-02-16T16:22:26Z
Thanks for the quick reply. I have built a kind of work around using:from scipy.special import softmax

probabilities = softmax(preds_output[0], axis=1)Or am I missing smth here?
2022-02-17T13:42:43Z
The code above can be used and returns the same probabilities like transforming the array to a torch tensor and applying the code from my original post. Just for everyone who ll stumble upon this post…
2022-02-17T13:53:32Z
Yes, that works as well!