08-lstm-tensorflow.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:albemarle 作者: SeanTater 项目源码 文件源码
def RNN(tensor, lens, n_hidden, n_summary, name, reuse):
    with tf.variable_scope(name, reuse) as scope:
        # Define weights
        weights = {
            'out': tf.Variable(tf.random_normal([n_hidden, n_summary]), name=name+"_weights")
        }
        biases = {
            'out': tf.Variable(tf.random_normal([n_summary]), name=name+"_biases")
        }

        # Define a lstm cell with tensorflow
        lstm_cell = rnn_cell.LSTMCell(n_hidden, forget_bias=1.0, state_is_tuple=True)
        # Get lstm cell output
        outputs, states = rnn.rnn(lstm_cell, tensor, sequence_length=lens, dtype=tf.float32, scope=scope)
        # Linear activation, using rnn inner loop last output
        return tf.matmul(outputs[-1], weights['out']) + biases['out']


# Now for parts specific to this data


# Parameters
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号