title: How to use TF IDF vectorizer with LSTM in Keras Python
body: <p>I am trying to train a Seq2Seq model using LSTM in Keras library of Python. I want to use TF IDF vector representation of sentences as input to the model and getting an error. </p>
  
  <pre><code>X = ["Good morning", "Sweet Dreams", "Stay Awake"]
  Y = ["Good morning", "Sweet Dreams", "Stay Awake"]
  
  vectorizer = TfidfVectorizer()
  vectorizer.fit(X)
  vectorizer.transform(X)
  vectorizer.transform(Y)
  tfidf_vector_X = vectorizer.transform(X).toarray() #shape - (3,6)
  tfidf_vector_Y = vectorizer.transform(Y).toarray() #shape - (3,6)
  tfidf_vector_X = tfidf_vector_X[:, :, None] #shape - (3,6,1) since LSTM cells expects ndims = 3
  tfidf_vector_Y = tfidf_vector_Y[:, :, None] #shape - (3,6,1)
  
  X_train, X_test, y_train, y_test = train_test_split(tfidf_vector_X, tfidf_vector_Y, test_size = 0.2, random_state = 1)
  model = Sequential()
  model.add(LSTM(output_dim = 6, input_shape = X_train.shape[1:], return_sequences = True, init = 'glorot_normal', inner_init = 'glorot_normal', activation = 'sigmoid'))
  model.add(LSTM(output_dim = 6, input_shape = X_train.shape[1:], return_sequences = True, init = 'glorot_normal', inner_init = 'glorot_normal', activation = 'sigmoid'))
  model.add(LSTM(output_dim = 6, input_shape = X_train.shape[1:], return_sequences = True, init = 'glorot_normal', inner_init = 'glorot_normal', activation = 'sigmoid'))
  model.add(LSTM(output_dim = 6, input_shape = X_train.shape[1:], return_sequences = True, init = 'glorot_normal', inner_init = 'glorot_normal', activation = 'sigmoid'))
  adam = optimizers.Adam(lr = 0.001, beta_1 = 0.9, beta_2 = 0.999, epsilon = None, decay = 0.0, amsgrad = False)
  model.compile(loss = 'cosine_proximity', optimizer = adam, metrics = ['accuracy'])
  model.fit(X_train, y_train, nb_epoch = 100)
  </code></pre>
  
  <p>The above code throws:</p>
  
  <pre><code>Error when checking target: expected lstm_4 to have shape (6, 6) but got array with shape (6, 1)
  </code></pre>
  
  <p>Could someone tell me what's wrong and how to fix it? </p>