【问题标题】:Tensorflow: Understanding the layer structure of LSTM modelTensorflow:了解LSTM模型的层结构
【发布时间】:2018-08-14 13:06:47
【问题描述】:

我是 tensorflow 和 LSTM 的新手,在理解网络的形状和结构(权重、偏差、输入和日志的形状)时遇到了一些麻烦。

在这段取自here的特定代码中

def recurrent_neural_network(x):
    layer = {'weights':tf.Variable(tf.random_normal([rnn_size,n_classes])),
         'biases':tf.Variable(tf.random_normal([n_classes]))}

    x = tf.transpose(x, [1,0,2])
    x = tf.reshape(x, [-1, chunk_size])
    x = tf.split(x, n_chunks, 0)

    lstm_cell = rnn_cell.BasicLSTMCell(rnn_size,state_is_tuple=True)
    outputs, states = rnn.static_rnn(lstm_cell, x, dtype=tf.float32)

    output = tf.matmul(outputs[-1],layer['weights']) + layer['biases'])

    return output
  1. 谁能解释一下为什么我们需要将 x 转换为这种特定格式(转置 -> 重塑 -> 拆分)

  2. 为什么权重定义为 [rnn_size, n_classes] 而偏差定义为 [n_classes]。

  3. 正在形成的网络的确切结构是什么以及权重是如何连接的,我不太理解。

  4. 是否有任何网站或参考资料可供我阅读?

谢谢。

【问题讨论】:

    标签: python tensorflow machine-learning lstm rnn


    【解决方案1】:

    对于一般的网络结构,LSTMs 是 RNN 网络的扩展。 RNN网络结构的解释可以看this classic blog post

    对于实际的 LSTM,try this post (which also has an RNN explanation)

    这些不是很正式,但它们应该比学术论文更容易阅读和理解。

    一旦您阅读了这些内容,其余部分应该不会很难。 X 转换的原因是因为这是 static_rnn 期望的格式。而 rnn_size 是 LSTM 单元的大小,这就是为什么权重是这样形成的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-12-25
      • 2020-04-16
      • 2019-09-25
      • 1970-01-01
      • 2016-08-24
      • 2017-01-12
      • 2011-09-19
      相关资源
      最近更新 更多