In [1]:
import tensorflow as tf
import numpy as np
from tensorflow.contrib import rnn
sess = tf.InteractiveSession()
In [2]:
h = [1,0,0,0]
e = [0,1,0,0]
l = [0,0,1,0]
o = [0,0,0,1]
In [3]:
with tf.variable_scope("one_variable") as scope:
hidden_size = 2
cell = tf.contrib.rnn.BasicRNNCell(num_units = hidden_size)
print(cell.output_size, cell.state_size)
print(cell)
x = np.array([[h, h],
[e, e],
[l, l],
], dtype = np.float32)
print(x)
output, _state = tf.nn.dynamic_rnn(cell, x,sequence_length= [2,1,1], dtype = tf.float32)
sess.run(tf.global_variables_initializer())
print(sess.run(output))
print(sess.run(_state))
In [ ]: