Notes

Text Normalization

Two strings that look identical to a reader are routinely different to a computer — café typed as one character or as an e plus a combining accent, a straight quote against a curly one, a double space nobody can see. Text normalization is the step that makes such variants agree.

What the step actually does
It is a set of deliberate collapses applied before anything downstream looks at the text:

  • Unicode normalisation — reduce composed and decomposed forms to one canonical encoding, the fix that makes string comparison honest.
  • Case folding — lowercase, so Apple and apple share a vocabulary entry.
  • Whitespace and punctuation — collapse runs of spaces, strip or standardise marks, unify quotes and dashes.
  • Surface rewrites — expand contractions, map digits, dates and currency into standard forms, correct obvious misspellings.

Every collapse costs something
The gain is a smaller vocabulary, fewer unseen words and less sparsity, which is why count-based models needed this step so badly. The loss is information you may want: capitalisation is one of the strongest cues for named entity recognition, and stripping it measurably hurts a tagger, while punctuation carries sentence boundaries and, in a product review, a good deal of sentiment. So normalisation is chosen per task rather than applied by habit — and with subword tokenisers absorbing spelling variation on their own, a modern transformer pipeline normalises far less than a TF-IDF pipeline does. One rule has no exceptions: whatever you do at training time must be done identically at inference, or the model meets a distribution it never learned. In Python, unicodedata and ftfy cover the encoding half; spaCy and NLTK the linguistic half.

Text normalization is the preprocessing stage that reduces superficial variation in raw text so that strings meaning the same thing are represented identically — lowercasing, standardising Unicode forms and whitespace, expanding or stripping punctuation and contractions, and mapping numbers, dates and spellings to canonical forms. It controls what the downstream vocabulary contains: without it, café, Café and cafe become three unrelated tokens and sparse counts fragment.

Imagine a shop with thousands of customer records where the same town arrives as St. Albans, st albans and ST. ALBANS. To a person these are obviously one place. To software they are three different things, so every count is split three ways.

Text normalization is the tidying-up pass that fixes exactly that. Before software reads a pile of text, it smooths out the harmless differences: it makes capital letters consistent, settles on one way of writing accents and odd characters, trims stray spaces, and tidies punctuation. Nothing important is meant to change — the words are just made to look the same when they mean the same, so what follows is counting ideas rather than typing habits.