Coding Now – Best AI & Full Stack Courses in Delhi NCR | 100% Placement
Limited Offer: Get 50% OFF on AI & Full Stack Courses
📞 Call Now: +91 9667708830
Back to Deep Learning Notes
Topic #447

Text Preprocessing

Before any text reaches a neural network, it typically passes through a preprocessing pipeline — cleanup and normalization steps that reduce noise and vocabulary size. This note covers the classical toolkit; modern Transformer-based models rely on much less of it than older approaches did.

Common Preprocessing Steps

StepWhat It DoesExample
LowercasingTreats "The" and "the" as identical"The Cat" → "the cat"
Removing punctuationStrips symbols not usually carrying core meaning"Hello, world!" → "Hello world"
Removing stopwordsDrops very common, low-information words"the", "is", "at", "a"
StemmingCrudely chops words to a common root"running", "runner" → "run"
LemmatizationReduces words to their dictionary base form, more carefully than stemming"better" → "good"

Why Modern Deep Learning Uses Much Less of This

Classical NLP pipelines (bag-of-words, TF-IDF, simple feedforward classifiers) benefited significantly from this kind of aggressive normalization, since it reduced vocabulary size and noise for models with no way to learn nuance automatically. Modern subword tokenization (next note) and Transformer-based models learn from raw or lightly-cleaned text directly — over-aggressive preprocessing can actually discard useful signal (like capitalization indicating a proper noun, or punctuation indicating sentiment/tone) that a large pretrained model would otherwise have learned to use.

Code

import re

def basic_clean(text):
    text = text.lower()
    text = re.sub(r'[^\w\s]', '', text)   # strip punctuation
    return text

print(basic_clean("Hello, World! This is GREAT."))
# "hello world this is great"

Common Mistakes

  • Applying aggressive stopword removal and stemming before feeding text into a modern pretrained Transformer (like BERT) — these models were pretrained on raw, natural text, and mismatched preprocessing at fine-tuning/inference time can hurt performance rather than help.
  • Removing punctuation for a sentiment analysis task, where "!!!" or "..." can carry real emotional signal.

Interview Relevance

Q: "Why do modern Transformer-based NLP pipelines generally use much lighter preprocessing than classical bag-of-words approaches?" Classical models had no way to learn nuance from raw text automatically, so aggressive normalization (lowercasing, stemming, stopword removal) reduced noise and vocabulary size in a way that helped. Modern subword-tokenized Transformers learn rich representations directly from large amounts of raw text, and over-aggressive preprocessing can discard genuinely useful signal (capitalization, punctuation, word forms) the model would otherwise learn to use.

Practice Question

For a task classifying whether product reviews are spam, would removing all punctuation and lowercasing everything likely help or hurt? Consider what signals spam text often contains.

Related DL Notes

Want to go beyond the notes?

Join Coding Hubs School of AI's Deep Learning course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available
💬 Talk to Advisor
1
WhatsApp

Latest from Our Blog

Insights on AI, Data Science, Full Stack & Career

View All Articles →