Words → numbers, the right way
Before feeding text to a neural network, convert raw strings to dense numerical vectors. Two-step process: tokenize and encode to integers with TextVectorization, then map integers to dense vectors with an Embedding layer.
TextVectorization is a preprocessing layer that lives inside your model graph. This means tokenization is saved with the model and runs at inference without external scripts — a big advantage for production deployment.
The Embedding layer maps each integer token ID to a dense vector. These vectors are learned during training — semantically similar words end up near each other in embedding space. mask_zero=True tells downstream layers to ignore padding tokens (ID 0).
king - man + woman ≈ queen holds because directions in embedding space correspond to meaning. For production NLP in 2026, start with pretrained KerasHub embeddings (BERT, GPT-2, Gemma) rather than learning from scratch.