How to do it...

We proceed with the recipe as follows:

  1. If you want to create a one-to-one mapping, this is not an RNN but instead a dense layer. Suppose to have a model already defined and you want to add a Dense network. Then this is easily implemented in Keras:
model = Sequential()
model.add(Dense(output_size, input_shape=input_shape))
  1. If you want to create a one-to-many option, this can be achieved with RepeatVector(...). Note that return_sequences is a boolean to decide whether to return the last output in the output sequence, or the full sequence:
model = Sequential()
model.add(RepeatVector(number_of_times,input_shape=input_shape))
model.add(LSTM(output_size, return_sequences=True))
  1. If you want to create a many-to-one option, this can be achieved with the following LSTM code snippet:
model = Sequential()
model.add(LSTM(1, input_shape=(timesteps, data_dim)))
  1. If you want to create a many-to-many option, this can be achieved with the following LSTM code snippet when length of input and output matches the number of recurrent steps:
model = Sequential() 
model.add(LSTM(1, input_shape=(timesteps, data_dim), return_sequences=True))
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.220.112.56