title: Sparse matrix in LSTM
body: <p>I am building a small LSTM model for binary classification with <code>tf-idf</code> transformation. And I am getting this warning and it's taking a long time to train:</p>
  
  <blockquote>
    <p><strong>UserWarning:</strong> Converting sparse IndexedSlices to a dense Tensor of unknown shape. This may consume a large amount of memory.
      "Converting sparse IndexedSlices to a dense Tensor of unknown shape. "</p>
  </blockquote>
  
  <p>My code looks like this </p>
  
  <pre><code>xtrain_tfv = tfv.transform(xtrain)
  xvalid_tfv = tfv.transform(xvalid)
  </code></pre>
  
  <pre><code>model = Sequential()
  model.add(Embedding(xtrain_tfv.shape[0], 128))
  model.add(LSTM(128, dropout=0.2, recurrent_dropout=0.2))
  model.add(Dense(1, activation='sigmoid'))
  
  # try using different optimizers and different optimizer configs
  model.compile(loss='binary_crossentropy',
                optimizer='adam',
                metrics=['accuracy'])
  
  print('Train...')
  model.fit(xtrain_tfv, ytrain,
            batch_size=32,
            epochs=15,
            validation_data=(xvalid_tfv, yvalid))
  score, acc = model.evaluate(xtest_tfv, ytest,
                              batch_size=32)
  </code></pre>
  
  <p><code>xtrain_tfv</code> has a shape of <code>(6851, 9122)</code>
  . How to handle this?</p>