// Internal states
//
h = tf.zeros([batch_size, num_cells])
n = tf.zeros([batch_size, num_cells])
d = tf.zeros([batch_size, num_cells])
// Define model
//
error = tf.zeros([batch_size])
h += activation(tf.expand_dims(s, 0))
for i in range(max_steps):
x_step = x[:,i,:]
xh_join = tf.concat(1, [x_step, h]) // Combine the features and hidden state into one tensor
g = tf.matmul(xh_join, W_g)+b_g
u = tf.matmul(x_step, W_u)+b_u
q = tf.matmul(xh_join, W_a)+b_a
q_greater = tf.maximum(q, 0.0) // Greater of the exponent term or zero
scale = tf.exp(-q_greater)
a_scale = tf.exp(q-q_greater)n = tf.mul(n, scale)+tf.mul(tf.mul(u, tf.nn.tanh(g)), a_scale) // Numerically stable update of numerator
d = tf.mul(d, scale)+a_scale // Numerically stable update of denominator
h = activation(tf.div(n, d))