Created
March 23, 2019 12:33
-
-
Save shubham0204/4a08c2fde09e61eb981f48516096f67e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tensorflow as tf | |
encoder_inputs = tf.keras.layers.Input(shape=( None , )) | |
encoder_embedding = tf.keras.layers.Embedding( num_tokens, 200 , mask_zero=True) (encoder_inputs) | |
encoder_outputs , state_h , state_c = tf.keras.layers.LSTM( 200 , return_state=True )( encoder_embedding ) | |
encoder_states = [ state_h , state_c ] | |
decoder_inputs = tf.keras.layers.Input(shape=( None , )) | |
decoder_embedding = tf.keras.layers.Embedding( num_tokens, 200 , mask_zero=True) (decoder_inputs) | |
decoder_lstm = tf.keras.layers.LSTM( 200 , return_state=True , return_sequences=True ) | |
decoder_outputs , _ , _ = decoder_lstm ( decoder_embedding , initial_state=encoder_states ) | |
decoder_dense = tf.keras.layers.Dense( num_tokens , activation=tf.keras.activations.softmax ) | |
output = decoder_dense ( decoder_outputs ) | |
model = tf.keras.models.Model([encoder_inputs, decoder_inputs], output ) | |
model.compile(optimizer=tf.keras.optimizers.RMSprop(), loss='categorical_crossentropy') | |
model.summary() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment