title: LSTM autoencoder for variable length text input in keras
body: <p>Here padded_docs.shape=(736,50). As it is an autoencoder input and output are same. The output of last LSTM layer is 3-dimensional however, the  padded_docs which is kept as an output is 2-dimensional. How to fix this?  </p>
  
  
  
  <pre class="lang-python prettyprint-override"><code>df1=pd.read_csv('snapdeal_data.csv')
  
  
  df1=df1.head(1000)
  df2=df1['Review_Text']
  labels=df1['B_Helpfulness']
  
  # encode full sentence into vector
  encoded_docs=[one_hot(d,vocab_size) for d in X_train]
  print encoded_docs
  
  #####Padding encoded sequence of words
  max_length=50
  padded_docs = sequence.pad_sequences(encoded_docs, maxlen=max_length, padding='pre')
  print padded_docs
  
  model = Sequential()
  timesteps = padded_docs.shape[1]
  input_dim = max_length
  #inputs = Input(shape=(input_dim,))
  model.add(Embedding(vocab_size+1, 100,weights=[embedding_matrix],input_length=max_length,trainable=False))
  model.add(LSTM(200,return_sequences = True))
  model.add(LSTM(100,return_sequences = True))
  model.add(LSTM(50))
  model.add(RepeatVector(timesteps)) 
  model.add(LSTM(100,return_sequences = True))
  model.add(LSTM(200,return_sequences = True))
  model.add(LSTM(input_dim,return_sequences = True))
  
  model.compile(loss='mean_squared_error', optimizer='Adam')
  model.summary()
      `model.fit(padded_docs,padded_docs,epochs=100,batch_size=1,shuffle=True, verbose=2)`
  
  
  ValueError: Error when checking target: expected lstm_6 to have 3 dimensions, but got array with shape (736, 50)
  </code></pre>