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

1 vue (au cours des 30 derniers jours)
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?

Réponse acceptée

MathWorks Support Team
MathWorks Support Team le 31 Mai 2022
Modifié(e) : MathWorks Support Team le 31 Mai 2022
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.
This has also been documented in the "Tips" section for importKerasNetwork, importKerasLayers, importTensorFlowNetwork, and importTensorFlowLayers:
https://www.mathworks.com/help/deeplearning/ref/importkerasnetwork.html#d123e88361

Plus de réponses (0)

Catégories

En savoir plus sur Data Types dans Help Center et File Exchange

Tags

Aucun tag saisi pour le moment.

Community Treasure Hunt

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

Start Hunting!

Translated by