tensorflow - working with rnn basic methods




Creating RNN Cell

#create a basic rnn cell

import tensorflow as tf

# create a BasicRNNCell
rnn_cell = tf.nn.rnn_cell.BasicRNNCell(hidden_size)
# create a LSTMCell
rnn_cell = tf.nn.rnn_cell.LSTMCell(hidden_size)
# create a LSTMCell
rnn_cell = tf.nn.rnn_cell.GRUCell(hidden_size)


Reshape

reshape - reorganizes your tensor for example [1,2,3,4,5,6,7,8,9] into a specific shape.
For example,  if your execute  a = tf.reshape(t, [3, 3]), the array above gets converted into :-

array([[1, 2, 3],
       [4, 5, 6],
       [7, 8, 9]])


Softmax 

The purpose of softmax is to flatten/normalizing input into a sum of 1.

a = tf.constant(np.array([[.1, .3, .5, .9]]))
print(sess.run(tf.nn.softmax(a)))

Outputs

[[ 0.16838508  0.205666    0.25120102  0.37474789]]

Lets walk through the following simple rnn code and you figure out what is going on here.







Comments

Popular posts from this blog

A quick tutorial for OWASP ZAP tool for beginners

ionic2 cordova build android - Unable resolve gradle 2.2.3