title: Building a LSTM Cell using Keras
body: <p>I'm trying to build a RNN for text generation. I'm stuck at building my LSTM cell. The data is shaped like this- X is the input sparse matrix of dim(90809,2700) and Y is the output matrix of dimension(90809,27). The following is my code for defining the LSTM Cell-</p>
  
  <pre><code>model = Sequential()
  model.add(LSTM(128, input_shape=(X.shape[0], X.shape[1])))
  model.add(Dropout(0.2))
  model.add(Dense(Y.shape[1], activation='softmax'))
  model.compile(loss='categorical_crossentropy', optimizer='adam')
  </code></pre>
  
  <p>My understanding is that the input_shape should be the dimension of the input matrix, and the dense layer should be the size of the output for each observation, i.e 27 in this case. However, I get the following error-</p>
  
  <pre><code>Exception: Error when checking model input: expected lstm_input_3 to have 3 dimensions, but got array with shape (90809, 2700)
  </code></pre>
  
  <p>I'm not able to figure out what is going wrong. Can anyone please help me figure out why is the lstm_input expecting 3 dimensions?</p>
  
  <p>I tried the following as well-</p>
  
  <pre><code>X= np.reshape(np.asarray(dataX), (n_patterns, n_vocab*seq_length,1))
  Y=np.reshape(np.asarray(dataY), (n_patterns, n_vocab,1))
  </code></pre>
  
  <p>This gave me the following error-</p>
  
  <pre><code>Exception: Error when checking model input: expected lstm_input_7 to have shape (None, 90809, 2700) but got array with shape (90809, 2700, 1)
  </code></pre>
  
  <p>Any help will be appreciated. Thanks!</p>