I am using tensorflow.keras to predicate what an email is about using the email sender, subject and content.
# Use tokenizers to change email data to model input series
subject_sequence = subject_tk.texts_to_sequences(subject_series)
subject_sequence = sequence.pad_sequences(subject_sequence, maxlen = subject_length)
sender_sequence = subject_tk.texts_to_sequences(sender_series)
sender_sequence = sequence.pad_sequences(sender_sequence, maxlen = sender_length)
body_sequence = body_tk.texts_to_sequences(body_series)
body_sequence = sequence.pad_sequences(body_sequence, maxlen = body_length)
# Run learning model on input series and make predication
predication = email_classification_model.predict([subject_sequence, sender_sequence , body_sequence])
print(predication)
However, I noticed that sometime, like 10%, the model would fail with the following error:
File "mailMonitory.py", line 102, in OnItemAdd
predication = email_classification_model.predict([subject_sequence, sender_sequence , body_sequence])
....
tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name,
tensorflow.python.framework.errors_impl.InvalidArgumentError: indices[0,253] = 3686 is not in [0, 1897)
[[node model/embedding_1/embedding_lookup (defined at mailMonitory.py:102) ]] [Op:__inference_predict_function_4617]
print(sender_sequence)
[[ 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0
693 3686 139 169]]
From my testing, the problem is always my tokenizer converts the sender email into a series that contains a out of bound number for the model. Why is this happening? Does my tokenizer not contain enough data or is there something wrong with my mode? How can I fix this?