Skip to content
Advertisement

Prediction with keras embedding leads to indices not in list

I have a model that I trained with

JavaScript

For the embedding I use Glove as a pre-trained embedding dictionary. Where I first build the tokenizer and text sequence with: t = Tokenizer() t.fit_on_texts(all_text)

JavaScript

and then I’m calculating the embedding matrix with:

JavaScript

now I’m using a new dataset for the prediction. This leads to an error:

Node: ‘model/synopsis_embedd/embedding_lookup’ indices[38666,63] = 136482 is not in [0, 129872) [[{{node model/synopsis_embedd/embedding_lookup}}]] [Op:__inference_predict_function_12452]

I do all of the steps for the prediction step again. Is that wrong and do I have to reuse the tokenizer from the training? Or why are the indices during prediction not existing?

Advertisement

Answer

You are probably getting this error because you are not using the same tokenizer and embedding_matrix during inference. Here is an example:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement