Machine Translation with Keras
Thushan Ganegedara
Data Scientist and Author
Repeat the context vector from the encoder N-many times
RepeatVector layer:
2 x 3
)2 x 3 x 3
)from tensorflow.keras.layers import RepeatVector
rep = RepeatVector(5)
r_inp = Input(shape=(3,))
r_out = rep(r_inp)
repeat_model = Model(inputs=r_inp, outputs=r_out)
rep = RepeatVector(5)
r_out = rep(r_inp)
r_out = RepeatVector(5)(r_inp)
Predicting with the model
x = np.array([[0,1,2],[3,4,5]])
y = repeat_model.predict(x)
print('x.shape = ',x.shape,'\ny.shape = ',y.shape)
x.shape = (2, 3)
y.shape = (2, 5, 3)
Defining the decoder
de_inputs = RepeatVector(fr_len)(en_state)
decoder_gru = GRU(hsize, return_sequences=True)
Fixing the initial state of the decoder
gru_outputs = decoder_gru(de_inputs, initial_state=en_state)
enc_dec = Model(inputs=en_inputs, outputs=gru_outputs)
Machine Translation with Keras