softmax函数学习【转载】

转自:https://blog.csdn.net/red_stone1/article/details/80687921

2020-6-3更新————————

1.指数特性

https://zhuanlan.zhihu.com/p/105722023

上图是y=e^x的图像,当x发生微小的变化的时候y的变化会很大,softmax就能够更好的捕获x的差异。

import tensorflow as tf

print(tf.__version__) # 2.0.0
a = tf.constant([2, 3, 5], dtype = tf.float32)

b1 = a / tf.reduce_sum(a) # 不使用指数
print(b1) # tf.Tensor([0.2 0.3 0.5], shape=(3,), dtype=float32)

b2 = tf.nn.softmax(a) # 使用指数的Softmax
print(b2) # tf.Tensor([0.04201007 0.11419519 0.8437947 ], shape=(3,), dtype=float32)

一组数经过softmax之后就可以拉开更大的距离。 

但是如果数值过大,就可能会存在溢出的现象,且softmax分母是求和。

//链接中后半部分的求导,我还没看,不知道面试会不会问。

原文地址:https://www.cnblogs.com/BlueBlueSea/p/10539464.html