Reputation: 867
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?
Upvotes: 1
Views: 1153
Reputation: 86630
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)
Upvotes: 1