HI team , i am using hugging face AutoModelForSequenceClassification , model is roberta , using it for text classification.
there are 3 classes
output is [-3.7550,-4.4172,7.8079]
i need to convert this to probabilities
should I apply soft max to this to get the probabilities , if i do that i am getting outputs greater than one
[9.51,4.90,0.99]
@Prajwal,
should I apply soft max to this to get the probabilities
Yes, we should apply softmax.
if i do that i am getting outputs greater than one
If you check the below code you can see that the output of softmax returns probabilities.
For checking whether we are getting probabilities, sum all the elements of the output should be 1
import tensorflow as tf
import numpy as np
check = tf.constant([-3.7550,-4.4172,7.8079])
layer = tf.keras.layers.Softmax()
output=layer(check)
print(output)
print(tf.math.reduce_sum(output))
Output:
tf.Tensor([9.512394e-06 4.905694e-06 9.999856e-01], shape=(3,), dtype=float32)
tf.Tensor(1.0, shape=(), dtype=float32)
Thank you!