为了区分LSTM,我希望在我的代码中给出BasicLSTMCell变量的名称。但它报告了以下错误:
num_units=self.config.num_lstm_units, state_is_tuple=True, name="some_basic_lstm")
TypeError: __init__() got an unexpected keyword argument 'name'
我在库中找到了我的tensorflow安装。在文件rnn_cell_impl.py中:
class BasicLSTMCell(RNNCell):
"""Basic LSTM recurrent network cell.
The implementation is based on: http://arxiv.org/abs/1409.2329.
We add forget_bias (default: 1) to the biases of the forget gate in order to
reduce the scale of forgetting in the beginning of the training.
It does not allow cell clipping, a projection layer, and does not
use peep-hole connections: it is the basic baseline.
For advanced models, please use the full @{tf.nn.rnn_cell.LSTMCell}
that follows.
"""
def __init__(self, num_units, forget_bias=1.0,
state_is_tuple=True, activation=None, reuse=None):
"""Initialize the basic LSTM cell.
Args:
num_units: int, The number of units in the LSTM cell.
forget_bias: float, The bias added to forget gates (see above).
Must set to `0.0` manually when restoring from CudnnLSTM-trained
checkpoints.
state_is_tuple: If True, accepted and returned states are 2-tuples of
the `c_state` and `m_state`. If False, they are concatenated
along the column axis. The latter behavior will soon be deprecated.
activation: Activation function of the inner states. 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.
这是我的张量流版本中的错误吗?我怎么能给它一个"名称"?
答案 0 :(得分:0)
我认为@aswinids在评论中提供了最佳答案,但让我解释为什么它不应该被视为错误。 LSTM单元由至少4个变量组成(还有一些变量用于控制流程等)。 LSTM中发生了4个子网络操作。 Colah博客下面的图表说明了LSTM单元格的内部结构(http://colah.github.io/posts/2015-08-Understanding-LSTMs/):
每个黄色框都有一组分配给它的权重,实际上是一个单层神经网络操作(以有趣的方式连接在一起,由LSTM架构定义)。
命名这些的好方法是tf.variable_scope('some_name')
,这样LSTM中定义的所有4个变量都有一个共同的基本命名结构,例如:
lstm_cell/f_t
lstm_cell/i_t
lstm_cell/C_t
lstm_cell/o_t
我怀疑之前他们刚刚这样做并硬编码lstm_cell
或者他们用作LSMT单元下所有变量的前缀的名称。在@ashwinids指出的后续版本中,有一个名称变量,我怀疑刚刚替换了我在此处示例中使用的lstm_cell
。