在 LSTM 中使用 tanh 的直觉是什么?

What is the intuition of using tanh in LSTM?

在一个LSTM网络(Understanding LSTMs)中,为什么输入门和输出门使用tanh?

这背后的直觉是什么?

只是非线性变换?如果是,我可以将两者都更改为另一个激活函数(例如 ReLU)吗?

Sigmoid 具体用作 LSTM 中三个门(in、out 和 forget)的门函数,因为它输出的值介于 0 之间和 1,它可以让信息在整个门中不流动或完全流动。

另一方面,为了克服梯度消失问题,我们需要一个函数,它的二阶导数可以在趋于零之前维持很长的范围。 Tanh与上面的属性.

是一个很好的函数

一个好的神经元单元应该是有界的、容易区分的、单调的(有利于凸优化)并且易于处理。如果您考虑这些品质,那么我相信您可以使用 ReLU 代替 tanh 函数,因为它们是彼此非常好的替代品。

但是在选择激活函数之前,你必须知道你的选择相对于其他人的优势和劣势是什么。我将简要描述一些激活函数及其优点。

Sigmoid

数学表达式:sigmoid(z) = 1 / (1 + exp(-z))

一阶导数:sigmoid'(z) = -exp(-z) / 1 + exp(-z)^2

优点:

(1) The sigmoid function has all the fundamental properties of a good activation function.

tanh

数学表达式:tanh(z) = [exp(z) - exp(-z)] / [exp(z) + exp(-z)]

一阶导数:tanh'(z) = 1 - ([exp(z) - exp(-z)] / [exp(z) + exp(-z)])^2 = 1 - tanh^2(z)

优点:

(1) Often found to converge faster in practice
(2) Gradient computation is less expensive

Hard Tanh

数学表达式:hardtanh(z) = -1 if z < -1; z if -1 <= z <= 1; 1 if z > 1

一阶导数:hardtanh'(z) = 1 if -1 <= z <= 1; 0 otherwise

优点:

(1) Computationally cheaper than Tanh
(2) Saturate for magnitudes of z greater than 1

ReLU

数学表达式:relu(z) = max(z, 0)

一阶导数:relu'(z) = 1 if z > 0; 0 otherwise

优点:

(1) Does not saturate even for large values of z
(2) Found much success in computer vision applications

Leaky ReLU

数学表达式:leaky(z) = max(z, k dot z) where 0 < k < 1

一阶导数:relu'(z) = 1 if z > 0; k otherwise

优点:

(1) Allows propagation of error for non-positive z which ReLU doesn't

This paper 解释了一些有趣的激活函数。你可以考虑看看。

LSTM 管理一个内部状态向量,当我们添加某些函数的输出时,其值应该能够增加或减少。 Sigmoid 输出总是非负的;该州的价值只会增加。 tanh 的输出可以是正数或负数,允许状态增加和减少。

这就是为什么使用 tanh 来确定要添加到内部状态的候选值。 LSTM 的 GRU 表亲没有第二个 tanh,因此从某种意义上说,第二个不是必需的。查看 Chris Olah 的 Understanding LSTM Networks 中的图表和解释了解更多信息。

相关问题 "Why are sigmoids used in LSTMs where they are?" 也根据函数的可能输出进行了回答:"gating" 是通过乘以 0 到 1 之间的数字来实现的,这就是 sigmoid 输出。

sigmoid 和 tanh 的导数之间并没有真正有意义的区别; tanh 只是一个重新缩放和移动的 sigmoid:参见 Richard Socher 的 Neural Tips and Tricks。如果二阶导数相关,我想知道如何。