Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

How can you implement LSTM network in tensorflow ?

Answer Posted / Mrrcy Sagar

To implement an LSTM network in TensorFlow, you can use the Long Short-Term Memory (LSTM) cell from the tf.contrib.rnn module. Here's a simple example:nn```pythonnimport tensorflow as tfnn# Input datandata = tf.placeholder(tf.float32, shape=[None, timesteps, features])nlabels = tf.placeholder(tf.int64, shape=[None])nn# Define LSTM cellnlstm_cell = tf.contrib.rnn.BasicLSTMCell(num_units)nn# Define input and output projections for the LSTM cellninput_proj_w = tf.Variable(tf.truncated_normal([features, num_units], stddev=0.1))ninput_proj_b = tf.Variable(tf.zeros([num_units]))noutput_proj_w = tf.Variable(tf.truncated_normal([num_units, vocab_size]))noutput_proj_b = tf.Variable(tf.zeros([vocab_size]))nn# Define LSTM input and output functionsndef lstm_input(_):n return tf.matmul(data, input_proj_w) + input_proj_bndef lstm_output(_):n return tf.matmul(lstm_cell.output, output_proj_w) + output_proj_bnn# Define the LSTM RNNnlstm_rnn = tf.contrib.rnn.static_rnn(lstm_cell, lstm_input, data)nn# Define the softmax loss functionndropout_keep_prob = tf.placeholder(tf.float32)ndropped_output = tf.nn.dropout(lstm_rnn[0], dropout_keep_prob)ndist = tf.nn.softmax(dropped_output)nloss = tf.reduce_mean(-tf.reduce_sum(labels * tf.log(dist), reduction_indices=[1]))nn# Define training procedurenoptimizer = tf.train.AdamOptimizer().minimize(loss)

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the apis outside tensorflow project?

4