简体   繁体   English

Tensorflow:了解LSTM模型的层结构

[英]Tensorflow: Understanding the layer structure of LSTM model

I'm new to tensorflow and LSTM and I'm having some trouble understanding the shape and structure of the network (weights, biases, shape of inputs and logs). 我是tensorflow和LSTM的新手,在理解网络的形状和结构(权重,偏差,输入和日志的形状)时遇到一些麻烦。

In this specific piece of code taken from 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. Can someone please explain why we need to convert x to this specific format (transpose -> reshape -> split) 有人可以解释为什么我们需要将x转换为这种特定格式(转置->重塑->拆分)

  2. Why weights are defined as [rnn_size, n_classes] and biases defined as [n_classes]. 为什么将权重定义为[rnn_size,n_classes],将偏差定义为[n_classes]。

  3. What is the exact structure of the network that is being formed and how are the weights connected, I don't understand that properly. 正在形成的网络的确切结构是什么,以及权重是如何连接的,我不太了解。

  4. Is there any site or reference that I could read that would help? 有没有我可以阅读的网站或参考资料对您有帮助?

Thanks. 谢谢。

For the general network structure, LSTMs are an extension of RNN networks. 对于一般的网络结构,LSTM是RNN网络的扩展。 For explanation of RNN network structure, take a look at this classic blog post 有关RNN网络结构的说明,请参阅此经典博客文章

For the actual LSTMs, try this post (which also has an RNN explanation) 对于实际的LSTM,请尝试这篇文章(也有RNN的说明)

These are not very formal, but they should be much easier to read and understand than academic papers. 这些不是很正式,但是它们应该比学术论文更容易阅读和理解。

Once you read these, the rest should not be very hard. 阅读这些内容后,其余的内容就不会很难了。 The reason for the transformations of X is because that is the format static_rnn expects. X转换的原因是因为这是static_rnn期望的格式。 And rnn_size is the size of the LSTM cell, so thats why the weights are shaped that way. rnn_size是LSTM单元的大小,因此这就是为什么权重采用这种方式成形的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM