Skip to content

Instantly share code, notes, and snippets.

@hadifar
Created December 6, 2018 08:32
Show Gist options
  • Save hadifar/05222e8f10206d2eede2d39736bd801a to your computer and use it in GitHub Desktop.
Save hadifar/05222e8f10206d2eede2d39736bd801a to your computer and use it in GitHub Desktop.
# rnn_cell = tf.contrib.rnn.BasicRNNCell(rnn_size) # will remove in tensorflow 2.0
rnn_cell = tf.keras.layers.SimpleRNNCell(rnn_size)
outputs, states = tf.nn.dynamic_rnn(rnn_cell, embed, dtype=tf.float32)
# RNN outputs: [batch_size * seq_len * hidden_size]
# split and extract only last output
last_rnn_output = outputs[:, -1, :]
# Dense layers
dense1 = tf.layers.dense(last_rnn_output, 16, activation='relu')
logit = tf.layers.dense(last_rnn_output, 2)
pred = tf.nn.softmax(logit)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment