实测用LSTMcell替换掉最简单的RNNcell的意义

来源:互联网 发布:剑网三明教脸型数据 编辑:程序博客网 时间:2024/06/08 08:44
import tensorflow as tffrom tensorflow.contrib import rnnx = tf.constant([[1]], dtype = tf.float32)x2 = tf.constant([[0]], dtype = tf.float32)rnn_cell = rnn.BasicRNNCell(2)lstm_cell = rnn.BasicLSTMCell(2)outputs1, states1 = rnn.static_rnn(rnn_cell, [x,x2,x2,x2,x2,x2,x2,x2,x2], dtype=tf.float32)outputs2, states2 = rnn.static_rnn(lstm_cell, [x,x2,x2,x2,x2,x2,x2,x2,x2], dtype=tf.float32)init = tf.global_variables_initializer()with tf.Session() as sess:    sess.run(init)    outouts_print1 = sess.run(outputs1)    states_print1 = sess.run(states1)    print(outouts_print1)    outouts_print2 = sess.run(outputs2)    states_print2 = sess.run(states2)    print(outouts_print2)

print结果:

[array([[-0.72937429, 0.54721737]], dtype=float32),
array([[-0.06861426, 0.71071303]], dtype=float32),
array([[ 0.47969401, 0.19322841]], dtype=float32),
array([[ 0.45349428, -0.45451662]], dtype=float32),
array([[-0.04894456, -0.51678276]], dtype=float32),
array([[-0.42092162, -0.03447074]], dtype=float32),
array([[-0.31019336, 0.42457983]], dtype=float32),
array([[ 0.12409887, 0.38893288]], dtype=float32),
array([[ 0.3786993 , -0.06912003]], dtype=float32)]

[array([[-0.04175898, 0.12050378]], dtype=float32),
array([[-0.03201877, 0.08375908]], dtype=float32),
array([[-0.0199711 , 0.05475891]], dtype=float32),
array([[-0.01223832, 0.0354035 ]], dtype=float32),
array([[-0.00733993, 0.02265788]], dtype=float32),
array([[-0.00429717, 0.01438016]], dtype=float32),
array([[-0.0024411, 0.0090563]], dtype=float32),
array([[-0.0013303 , 0.00565884]], dtype=float32),
array([[-0.00068016, 0.00350584]], dtype=float32)]

可见最简单的RNNcell的每次output之间没有任何规律可言,而LSTMcell的每次output表现了信息在有规律的减弱

原创粉丝点击