1

I'm working with this example but am confused on how to make the separate decoder model.

from keras.layers import Input, LSTM, RepeatVector
from keras.models import Model

inputs = Input(shape=(timesteps, input_dim))
encoded = LSTM(latent_dim)(inputs)

decoded = RepeatVector(timesteps)(encoded)
decoded = LSTM(input_dim, return_sequences=True)(decoded)

sequence_autoencoder = Model(inputs, decoded)
encoder = Model(inputs, encoded)

I understand how to make the encoder, but how do we make a separate decoder? I can define all the layers and make the encoder and decoder separately but is there a simpler way to do it like we've done with the encoder model?

1
  • You could try just: decoder = Model(encoder.output,decoded) (Never tried this, but I'll add an answer with what I know that works) Commented May 7, 2017 at 16:34

1 Answer 1

1

Create the encoder:

inputs = Input(shape=(timesteps, input_dim))
encoded = LSTM(latent_dim)(inputs)
encoder = Model(inputs, encoded)

Create the decoder:

decInput = Input((the shape of the encoder's output))    
decoded = RepeatVector(timesteps)(decInput)
decoded = LSTM(input_dim, return_sequences=True)(decoded)
decoder = Model(decInput,decoded)

Joining models:

joinedInput = Input(shape=(timesteps, input_dim))
encoderOut = encoder(joinedInput)    
joinedOut = decoder(encoderOut)
sequence_autoencoder = Model(joinedInput,joinedOut)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.