liveBook · Manning

Indexing

As explained in Deep Learning with Python, Third Edition

The stage of text preprocessing that maps tokens to integer indices for numeric model input.

Indexing turns tokens into integer IDs so text can become numeric model input. A vocabulary maps each token to an ID; the mapping is reversible and can be used with different modeling approaches. section 14.2

vocabulary = {
    "[UNK]": 0,
    "the": 1,
    "quick": 2,
    "brown": 3,
    "fox": 4,
    "jumped": 5,
    "over": 6,
    "dog": 7,
    ".": 8,
}
words = split_words("The quick brown fox jumped over the lazy dog.")
indices = [vocabulary.get(word, 0) for word in words]

This Python example looks up each word in a vocabulary and assigns ID 0 to tokens not found there. Here, both “The” and “lazy” map to the [UNK] ID. section 14.2

The resulting IDs can later be mapped into a learned latent space, such as through embeddings. Indexing itself does not perform that mapping. section 14.2 section 14.6

How Deep Learning with Python, Third Edition covers it

How deep it goes
Demonstrates vocabulary lookup and unknown-token handling, then defers mapping IDs into a model's latent space.
Examples
Uses a word-level vocabulary to index a sentence containing an out-of-vocabulary word.
What it assumes
Assumes tokens are split from text and situates indexing within standardization, splitting, and indexing.
What you can do after
Build it from scratch by mapping vocabulary tokens to IDs and assigning a fallback ID to unknown tokens.
How it connects
Links indexing to tokenization, vocabulary construction, and embeddings.

Also explained in

Compare how 15 books explain indexing →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Deep Learning with Python, Third Edition. The section links point to the parts of the book it draws on.