MATLAB Answers

Why do I need adding "+1" to the input of my Keras LSTM-model?

5 views (last 30 days)
The LSTM-model is trained in Keras. The input comes from 'datfile'. If the trained net is imported to Matlab and the inputs from 'datfile' are added, the outputs of the layers do not match. If '1' is added to the inputs, then they match. Why must '1' be added for the same results?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 8 Oct 2021
Essentially, a 'wordEmbeddingLayer' acts as a lookup table. We assign each word a single index. And that index is used by the lookup table in order to get the corresponding embedding vector. Now the reason why this +1 is required is due to the fact that MATLAB uses 1 based indexing rather than 0 based indexing like python. Because of this, each index is shifted by 1 when we load in the lookup table, so the input data should also be shifted by 1 to accommodate this.

More Answers (0)

Tags

No tags entered yet.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!