liveBook · Manning

Token

As explained in Natural Language Processing in Action, Second Edition

A discrete lexical unit obtained by splitting source text into identifiable pieces, including individual characters in character-based processing.

A token is a discrete piece of text that a tokenizer can count. Tokens may be words or n-grams, and can include punctuation, emoticons, and Chinese characters. Counting token occurrences turns text into a numerical representation that machine-learning systems can use. section 2.0

A bag-of-words representation assigns tokens to vocabulary slots and counts them, much like sorting coins into bins. It keeps the counts but loses word order, which can make the original sentence hard to understand. section 1.5.3

Treating every token as a separate vocabulary term has limitations:

  • Ignoring token sequences loses co-occurrence information. section 2.3
  • Treating related forms such as “swim” and “swimming” as different tokens can weaken tasks such as finding relevant articles. section 2.3
Figure 1.5 Canadian coin sorter
figure

The coin sorter illustrates how tokens can be sorted into bins before their counts are represented as a vector. section 1.5.3

How Natural Language Processing in Action, Second Edition covers it

How deep it goes
Defines tokens and their role in numerical representations, then notes that simple vocabularies lose sequence and word-form relationships.
Examples
Compares programming-language and natural-language tokens, uses a coin sorter analogy, and names n-grams, punctuation, emoticons, and Chinese characters.
What you can do after
Apply token counts to represent documents numerically for keyword detection, search, retrieval, classification, or comparison.
How it connects
Connects tokens to tokenization, tokenizers, bag-of-words vectors, search, information retrieval, and sentiment analysis.

Also explained in

Compare how 31 books explain token →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Natural Language Processing in Action, Second Edition. The section links point to the parts of the book it draws on.