liveBook · Manning

Tokenization

As explained in Data Without Labels

Tokenization is the process of splitting text into discrete units such as words or punctuation marks called tokens.

Tokenization breaks text into discrete units called tokens. It is a basic step in preparing text for analysis: tokens can be collected into a vocabulary—the set of unique tokens in a corpus—and used in text representations such as bag of words. section 7.8 section 7.7

Choose token boundaries to suit the task:

  • Word tokenization separates words; punctuation may appear as separate tokens unless it is removed first. section 7.8 section 7.12
  • Subword tokenization can split “raining” into “rain” and “ing”; character tokenization splits it into individual letters. section 7.8
  • Available approaches also split on whitespace or blank lines, or use patterns to identify tokens and separators. section 7.8
import nltk
text_d = "Hey!!! How are you doing? And how is your health! Bye, take care."
nltk.tokenize.word_tokenize(text_d)

Run the NLTK example to inspect how word_tokenize separates a short sentence, including its punctuation marks. section 7.12

Inspect and clean the input according to the intended representation. The Python examples normalize spaces, remove punctuation or lowercase text before tokenizing when those changes are wanted. Once words are tokenized, they can be filtered for stop words or processed with stemming or lemmatization. Removing punctuation is a choice, not a requirement: the uncleaned example retains punctuation as tokens. section 7.12

Customer-review sentiment

A review workflow lowercases and cleans review text, removes stop words and frequent words, tokenizes a review with NLTK, and lemmatizes the text before calculating sentiment with TextBlob. Tokenization is one preparation step; the sentiment score comes later. section 7.15

How Data Without Labels covers it

How deep it goes
Defines word, subword, and character tokens, surveys boundary methods, and demonstrates NLTK calls without detailing tokenizer internals.
Examples
Uses a sentence split into tokens, Python cleaning snippets, and tokenized customer reviews in a sentiment workflow.
What it assumes
Defines tokens and vocabulary from the ground up while using Python library calls for implementation.
What you can do after
Apply it via NLTK to inspect tokens and prepare cleaned text for further processing.
How it connects
Links tokenization to vocabulary, bag of words, stop-word removal, stemming, lemmatization, and sentiment analysis.

Also explained in

Compare how 25 books explain tokenization →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Data Without Labels. The section links point to the parts of the book it draws on.