# Beyond one-hot encoding for LSTM model in Keras

I have an LSTM model in Keras for categorical classification (20 possible categories). In many cases, my data can fit multiple categories.

Obviously, my current model uses one-hot encoding and fits on that - that gives me accuracy and validation rates in the 50-60% but I want to improve that by comparing how the model does against the top 3 categories that the algorithm chooses.

Right now, I use Keras with categorical_crossentropy. I presume that this checks to see if the label is the top match and bases the accuracy on that matching. How can I modify the fit/training of the model to allow the labeled category to be in the top 3 (or top X-number) of matches for the accuracy score?

• Are you talking about multi-label categorical classification then? If yes this will change how you think. – TwinPenguins Oct 31 '18 at 7:19

If you're doing multilabel, you should do binary-crossentropy and sigmoid in a final layer. You must score your labels separately. Here's an example.