BasicRNNCell 如何确定单元状态大小和单元输出大小?
How the cell state size and cell output size is determined in BasicRNNCell?
考虑以下代码:
import tensorflow as tf
cell=tf.contrib.rnn.BasicRNNCell(num_units = rnn_size)
output, state = tf.nn.dynamic_rnn(cell, input, dtype=tf.float32)
根据 documentation of dynamic_rnn,output
和 state
的形状分别为 [batch_size, max_time, cell.output_size]
和 [batch_size, cell.state_size]
。
问题:cell.state_size
和cell.output_size
是如何在BasicRNNCell
中确定的? BasicRNNCell的initilizer中的num_units = rnn_size
与其state_size
和output_size
有什么关系?
在BasicRNNCell
的情况下,您提到的所有数量都是相同的(参考code):
class BasicRNNCell(RNNCell):
"""The most basic RNN cell.
Args:
num_units: int, The number of units in the LSTM cell.
activation: Nonlinearity to use. Default: `tanh`.
reuse: (optional) Python boolean describing whether to reuse variables
in an existing scope. If not `True`, and the existing scope already has
the given variables, an error is raised.
"""
def __init__(self, num_units, activation=None, reuse=None):
super(BasicRNNCell, self).__init__(_reuse=reuse)
self._num_units = num_units
self._activation = activation or math_ops.tanh
@property
def state_size(self):
return self._num_units
@property
def output_size(self):
return self._num_units
考虑以下代码:
import tensorflow as tf
cell=tf.contrib.rnn.BasicRNNCell(num_units = rnn_size)
output, state = tf.nn.dynamic_rnn(cell, input, dtype=tf.float32)
根据 documentation of dynamic_rnn,output
和 state
的形状分别为 [batch_size, max_time, cell.output_size]
和 [batch_size, cell.state_size]
。
问题:cell.state_size
和cell.output_size
是如何在BasicRNNCell
中确定的? BasicRNNCell的initilizer中的num_units = rnn_size
与其state_size
和output_size
有什么关系?
在BasicRNNCell
的情况下,您提到的所有数量都是相同的(参考code):
class BasicRNNCell(RNNCell):
"""The most basic RNN cell.
Args:
num_units: int, The number of units in the LSTM cell.
activation: Nonlinearity to use. Default: `tanh`.
reuse: (optional) Python boolean describing whether to reuse variables
in an existing scope. If not `True`, and the existing scope already has
the given variables, an error is raised.
"""
def __init__(self, num_units, activation=None, reuse=None):
super(BasicRNNCell, self).__init__(_reuse=reuse)
self._num_units = num_units
self._activation = activation or math_ops.tanh
@property
def state_size(self):
return self._num_units
@property
def output_size(self):
return self._num_units