问题描述
在张量流中,有一个名为 BasicLSTMCell
的 lstm 实现,它位于 tf.contrib.rnn.BasicLSTMCell
.它有一个参数 num_units
表示 LSTM 单元中的单元数.但我不知道那是什么意思.
in the tensorflow, there is a lstm implementation called BasicLSTMCell
which at tf.contrib.rnn.BasicLSTMCell
. And it has a parameter num_units
which means the number of units in the LSTM cell. But I do not know what that means.
如果我像这样定义一个 lstm 单元格:
If I define a lstm cell like this:
lstm_cell = tf.contrib.rnn.BasicLSTMCell(512).
lstm_cell 是什么样的?是lstm节点还是512节点的lstm层??谁能告诉我这个?
what does the lstm_cell look like? It is a lstm node or a lstm layer with 512 node??Who can tell me about this ?
推荐答案
它是一个 LSTM 层,有 512 个单元.
It is an LSTM layer with` 512 units.
BasicLSTMCell
实现抽象类 RNNCell
.来自文档:
BasicLSTMCell
implements the abstract class RNNCell
. From the documentation:
代表 RNN 单元格的抽象对象.
每个 RNNCell 都必须具有以下属性,并使用签名 (output, next_state) = call(input, state)
实现 call
.
Every RNNCell must have the properties below and implement call
with the signature (output, next_state) = call(input, state)
.
[...]
这个单元格的定义与文献中使用的定义不同.在文献中,单元格"是指具有单个标量输出的对象.此定义指的是此类单元的水平阵列.
This definition of cell differs from the definition used in the literature. In the literature, 'cell' refers to an object with a single scalar output. This definition refers to a horizontal array of such units.
创建 LSTM 层并展开反向传播波谷时间的一种常用方法如下:
A common way of creating the LSTM layer together with the unrolling for Back Propagation Trough Time is the following one:
lstm_cell = tf.contrib.rnn.BasicLSTMCell(512)
outputs, final_state = tf.nn.static_rnn(cell=lstm_cell,
dtype=tf.float32,
inputs=some_input_sequence)
哪里:
some_input_sequence
是num_steps
个大小为[batch_size, input_size]
的张量列表outputs
将包含some_input_sequence
的每个元素之后的层的输出.所以它又是一个num _steps
元素的列表,其大小为[batch_size, 512]
(其中 512 是单元格的单位数)final_state
将包含处理整个序列后的状态.特别是,对于 LSTM,它是一个具有两个元素的命名元组,c
和h
(LSTM 的两个状态).
some_input_sequence
is a list ofnum_steps
tensors of size[batch_size, input_size]
outputs
will contain the output of the layer after each of the elements ofsome_input_sequence
. So it is again a list ofnum _steps
elements of size[batch_size, 512]
(where 512 was the number of units of your cell)final_state
will contain the state after the entire sequence has been processed. In particular, for LSTM, it is a named tuple with two elements,c
andh
(the two states of a LSTM).
这篇关于tf.contrib.rnn.BasicLSTMCell 是单个 LSTM 单元还是 LSTM 层?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!