0Pricing
Learn AI with Python · Lesson

Tokenization and Normalization

Text preprocessing techniques.

Tokenization and Normalization is a free Learn AI with Python lesson on CoddyKit — lesson 2 of 5. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Learn AI with Python learning path, one of 5 lessons in the course, and your progress syncs across the web and the CoddyKit app.

1

Tokenization and Normalization

Text preprocessing is a crucial step in NLP. It involves transforming raw text into a structured format for analysis. Key preprocessing steps include tokenization and normalization.

Tokenization and Normalization — illustration 1

2

What is Tokenization?

Tokenization is the process of breaking down text into smaller units, called tokens. Tokens can be words, sentences, or characters.

For example:

Text: "NLP is amazing!"

Tokens: ["NLP", "is", "amazing", "!"]

3

Tokenization Example in Python

Using the NLTK library, we can tokenize text into words or sentences:

from nltk.tokenize import word_tokenize, sent_tokenize

# Example text
text = "Tokenization is a key step in NLP. Let's learn it!"

# Word Tokenization
word_tokens = word_tokenize(text)
print("Word Tokens:", word_tokens)

# Sentence Tokenization
sentence_tokens = sent_tokenize(text)
print("Sentence Tokens:", sentence_tokens)

4

What is Normalization?

Normalization involves cleaning and standardizing text. Common normalization techniques include:

  • Lowercasing: Converting all text to lowercase.
  • Removing Punctuation: Eliminating punctuation marks.
  • Stemming: Reducing words to their root form (e.g., "running" → "run").
  • Lemmatization: Reducing words to their base form using context (e.g., "better" → "good").

5

Lowercasing and Removing Punctuation

Here’s how to normalize text by converting it to lowercase and removing punctuation:

import string

# Example text
text = "Normalization in NLP is Important!"

# Lowercasing
text = text.lower()

# Removing Punctuation
text = text.translate(str.maketrans('', '', string.punctuation))
print("Normalized Text:", text)

6

Stemming and Lemmatization

Stemming: Reduces words to their root by chopping off suffixes. It is rule-based and may not always produce valid words.

Lemmatization: Uses a vocabulary and grammar rules to reduce words to their meaningful base form.

from nltk.stem import PorterStemmer, WordNetLemmatizer

# Example text
word = "running"

# Stemming
stemmer = PorterStemmer()
print("Stemmed Word:", stemmer.stem(word))

# Lemmatization
lemmatizer = WordNetLemmatizer()
print("Lemmatized Word:", lemmatizer.lemmatize(word, pos='v'))

7

Stopword Removal

Stopwords are common words (e.g., "is", "and", "the") that often don’t carry significant meaning. Removing them can simplify text analysis:

from nltk.corpus import stopwords

# Example text
text = "This is a simple NLP example."

# Tokenize text
words = word_tokenize(text)

# Remove stopwords
stop_words = set(stopwords.words('english'))
filtered_words = [word for word in words if word.lower() not in stop_words]
print("Filtered Words:", filtered_words)

8

9

Challenges in Text Preprocessing

Text preprocessing can be challenging due to:

  • Ambiguity: Words like "lead" can have multiple meanings.
  • Context: Lemmatization requires understanding the word’s context.
  • Language Variance: Handling different languages and dialects.

10

Summary and Next Steps

In this lesson, we:

  • Learned about tokenization and normalization.
  • Explored techniques like stemming, lemmatization, and stopword removal.
  • Practiced text preprocessing with Python.

Next, we’ll analyze text patterns using N-Gram models.

Tokenization and Normalization — illustration 10

Frequently asked questions

Is the “Tokenization and Normalization” lesson free?

Yes — the full text of “Tokenization and Normalization” is free to read here on the web, and the Learn AI with Python course includes 5 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Learn AI with Python course, upgrade to CoddyKit PRO.

What will I learn in “Tokenization and Normalization”?

Text preprocessing techniques. You practise Learn AI with Python with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Learn AI with Python?

No prior experience is required. Learn AI with Python on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 5, so you can start here or from the beginning and move at your own pace.

How long does the “Tokenization and Normalization” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Learn AI with Python lesson?

Yes. Every Learn AI with Python lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Working with Text Data
  2. Tokenization and Normalization
  3. N-Gram Models
  4. Sentiment Analysis Concepts
  5. Transformer-Based Models
← Back to Learn AI with Python