basicLSTMCELL() num_units参数代表了LSTM输出向量的维数

https://blog.csdn.net/notHeadache/article/details/81164264

如下图片解释的清楚,来自stackoverflow

通俗易懂例子

https://www.knowledgemapper.com/knowmap/knowbook/[email protected](MNISTdataset)

https://i.stack.imgur.com/0Poch.png

标题

其它解释的补充的相当好:LSTM输出并不改变输入的维数,暗示输入输出的维数均为num_units

Good answer, You usually have embeddings for your input data and thus assume for every word for simplicity. So let's say each word has a distributed representation of 150 dimensions which are the features in the above diagram. Then num_units will act as the dimensionality of RNN/LSTM cell (say 128). So 150 -> 128. And hence output dimensions will be 128. Batch size and time_steps remains as it is. – HARSH PATHAK Dec 27 '19 at 16:15

add a comment

扫描二维码关注公众号,回复: 10757520 查看本文章

5

This term num_units or num_hidden_units sometimes noted using the variable name nhid in the implementations, means that the input to the LSTM cell is a vector of dimension nhid (or for a batched implementation, it would a matrix of shape batch_size x nhid). As a result, the output (from LSTM cell) would also be of same dimensionality since RNN/LSTM/GRU cell doesn't alter the dimensionality of the input vector or matrix.

As pointed out earlier, this term was borrowed from Feed-Forward Neural Networks (FFNs) literature and has caused confusion when used in the context of RNNs. But, the idea is that even RNNs can be viewed as FFNs at each time step. In this view, the hidden layer would indeed be containing num_hidden units as depicted in this figure:

Source: Understanding LSTM


More concretely, in the below example the num_hidden_units or nhid would be 3 since the size of hidden state (middle layer) is a 3D vector.

shareeditfollow

edited Sep 28 '18 at 20:11

answered Sep 28 '18 at 20:01

kmario23

29.9k77 gold badges9797 silver badges106106 bronze badges

  • 1

    You say "the input to the LSTM cell is a vector of dimension nhid". But the input is generally of shape [batch, T, input] where the input can be of any shape. So, when input is dynamically unrolled we would have an input of [b,t, input]. RNN would transform it as [b,t, nhid]. So, the output would be shape nhid not the input. – Vedanshu Oct 27 '18 at 11:41

add a comment

1

Most LSTM/RNN diagrams just show the hidden cells but never the units of those cells. Hence, the confusion. Each hidden layer has hidden cells, as many as the number of time steps. And further, each hidden cell is made up of multiple hidden units, like in the diagram below. Therefore, the dimensionality of a hidden layer matrix in RNN is (number of time steps, number of hidden units).

shareeditfollow

answered Jan 30 '19 at 10:05

发布了137 篇原创文章 · 获赞 87 · 访问量 164万+

猜你喜欢

转载自blog.csdn.net/studyvcmfc/article/details/105477759
今日推荐