title: Zero-padding a compressed sparse matrix (for NLP)?
body: <p>I am using a recurrent neural network to classify text sentiment. I used TfidfVectorizer to convert the text into counts. </p>
  
  <p>My code is as follows: </p>
  
  <pre><code>vectorizer = TfidfVectorizer(max_features = 5000) 
  vectorizer.fit(X_train) 
  Xtrain = vectorizer.fit_transform(X_train)
  Xtest = vectorizer.fit_transform(X_test)
  
  # create the model
  model = Sequential()
  model.add(Embedding(5000, 32, input_length=5000))
  model.add(LSTM(100))
  model.add(Dense(1, activation='sigmoid'))
  model.compile(loss='binary_crossentropy', optimizer='adam', metrics ['accuracy'])
  model.fit(Xtrain, y_train['toxic'], validation_data=(Xtest, y_test['toxic']), epochs=3, batch_size=64)
  </code></pre>
  
  <p>However, when I run the last line, I get the error ValueError: setting an array element with a sequence. </p>
  
  <p>I took a closer look at Xtrain and Xtest, which are my vectorized text. Each row has a different number of features, which I gather is what is causing the problem. I am thinking that the solution would be to zero-pad it so that all entries would be the same length as the max features. I am unfamiliar with the compressed sparse matrix. Is there any way to "decompress" it? How do I go about working with it? Thanks</p>