# Transform Logits to probabilities doesn't work

**URL:** <https://discuss.huggingface.co/t/transform-logits-to-probabilities-doesnt-work/14792>\
**Category:** Beginners\
**Created:** [February 16, 2022, 2:18pm UTC](https://discuss.huggingface.co/t/transform-logits-to-probabilities-doesnt-work/14792 "2022-02-16T14:18:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![marlon89](https://avatars.discourse-cdn.com/v4/letter/m/6de8d8/32.png) [@marlon89](https://discuss.huggingface.co/u/marlon89)\
**Post date:** [February 16, 2022, 2:18pm UTC](https://discuss.huggingface.co/t/transform-logits-to-probabilities-doesnt-work/14792/1 "2022-02-16T14:18:19Z")

</div>

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:

```auto
preds_output = trainer.predict(data_encoded['test'])

```

So I am able to get my predicted output with:

```auto
preds_output.predictions

```

This 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 with

```auto
from 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

---

<div class="post-metadata">

**Author:** ![sgugger](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/sgugger/32/2291_2.png) [@sgugger](https://discuss.huggingface.co/u/sgugger)\
**Post date:** [February 16, 2022, 3:36pm UTC](https://discuss.huggingface.co/t/transform-logits-to-probabilities-doesnt-work/14792/2 "2022-02-16T15:36:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![marlon89](https://avatars.discourse-cdn.com/v4/letter/m/6de8d8/32.png) [@marlon89](https://discuss.huggingface.co/u/marlon89)\
**Post date:** [February 16, 2022, 4:22pm UTC](https://discuss.huggingface.co/t/transform-logits-to-probabilities-doesnt-work/14792/3 "2022-02-16T16:22:26Z")

</div>

Thanks for the quick reply. I have built a kind of work around using:

```auto
from scipy.special import softmax

probabilities = softmax(preds_output[0], axis=1)

```

Or am I missing smth here?

---

<div class="post-metadata">

**Author:** ![marlon89](https://avatars.discourse-cdn.com/v4/letter/m/6de8d8/32.png) [@marlon89](https://discuss.huggingface.co/u/marlon89)\
**Post date:** [February 17, 2022, 1:42pm UTC](https://discuss.huggingface.co/t/transform-logits-to-probabilities-doesnt-work/14792/4 "2022-02-17T13:42:43Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![sgugger](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/sgugger/32/2291_2.png) [@sgugger](https://discuss.huggingface.co/u/sgugger)\
**Post date:** [February 17, 2022, 1:53pm UTC](https://discuss.huggingface.co/t/transform-logits-to-probabilities-doesnt-work/14792/5 "2022-02-17T13:53:32Z")

</div>

Yes, that works as well!
