import tensorflow as tf
import numpy as np
steps=2
batch_size=4
input_size=3
encoder_inputs = tf.placeholder("float", [None, steps, input_size])
decoder_inputs = tf.placeholder("float", [None, steps, input_size])
en_input=np.zeros(shape=[batch_size,steps,input_size])
de_input=np.zeros(shape=[batch_size,steps,input_size])
cell=tf.nn.rnn_cell.BasicLSTMCell(5)
def get_result(encoder_inputs,decoder_inputs,cell):
encoder_inputs=tf.unstack(encoder_inputs,axis=1)
decoder_inputs=tf.unstack(decoder_inputs,axis=1)
result=tf.contrib.legacy_seq2seq.basic_rnn_seq2seq(
encoder_inputs,
decoder_inputs,
cell,
dtype=tf.float32,
scope=None
)
return result
result=get_result(encoder_inputs,decoder_inputs,cell)
print(len(result))
init=tf.global_variables_initializer()
with tf.Session() as sess:
sess.run(init)
result_value=sess.run(result,feed_dict={encoder_inputs:en_input,decoder_inputs:de_input})
print(len(result_value))
print(result_value)
print('-----------------')
print(type(result_value))
print(result_value[0])
print('------------------')
print(result_value[1])
WARNING:tensorflow:From <ipython-input-2-369e707092eb>:14: BasicLSTMCell.__init__ (from tensorflow.python.ops.rnn_cell_impl) is deprecated and will be removed in a future version.
Instructions for updating:
This class is deprecated, please use tf.nn.rnn_cell.LSTMCell, which supports all the feature this cell currently has. Please replace the existing code with tf.nn.rnn_cell.LSTMCell(name='basic_lstm_cell').
2
2
([array([[0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0.]], dtype=float32), array([[0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0.]], dtype=float32)], LSTMStateTuple(c=array([[0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0.]], dtype=float32), h=array([[0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0.]], dtype=float32)))
-----------------
<class 'tuple'>
[array([[0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0.]], dtype=float32), array([[0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0.]], dtype=float32)]
------------------
LSTMStateTuple(c=array([[0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0.]], dtype=float32), h=array([[0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0.]], dtype=float32))