I am building a small LSTM model for binary classification with tf-idf transformation. And I am getting this warning and it's taking a long time to train:
UserWarning: 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. "
My code looks like this
xtrain_tfv = tfv.transform(xtrain)
xvalid_tfv = tfv.transform(xvalid)
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)
xtrain_tfv has a shape of (6851, 9122)
. How to handle this?
tf-idfinstead ofone hothas resolved your issue? Thanks. - Tensorflow Support