How to Combine tfidf with LSTM in keras?

I am classifying emails as spam or ham using LSTM and some of its modified form(by adding constitutional layer at the end). For converting documents into vectors I am using keras.text_to_sequences function.

But now I want to use TfIdf with the LSTM can anyone tell me or share the code how to do it. Please also guide me if it is possible and good approach or not.

If you are wondering why I would like to do this there are two reasons:

  1. I want to see if this improves the results.
  2. Second, my professor asked me to perform Latent Dirichlet Allocation, and use same features for both of the tasks.

Topic keras tfidf lda nlp

Category Data Science


The goal of text_to_sequence + embedding in traditional LSTM is to transform text to word vectors.

If you already have the tfidf transformation, the idea is usually to get rid of the embedding layer in your LSTM when you are constructing the model, and directly connect the input (i.e., tfidf matrix) to the layer followed by the embedding layer.

Not sure if it's a good approach but that's for you to figure it out :P.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.