Unicode normalization
Quick answer
Unicode normalization makes canonically equivalent text comparable before tokenization. For multilingual NLP, preserve meaningful characters and use an explicit, language-aware normalization policy. Examples are static Python snippets tested locally on CPU; scikit-learn or PyTorch is required for selected examples. ByteMind execution is unverified.
Canonical equivalence
import unicodedata as ua="e\u0301"; b="\u00e9"print(a==b,u.normalize("NFC",a)==u.normalize("NFC",b),len(u.normalize("NFC",a)))Expected output (locally tested): False True 1. NFC changes the representation without changing canonical meaning.
How it works
Python strings contain Unicode code points. The same visible letter can have composed and decomposed forms: U+00E9 and U+0065 U+0301. NFC composes canonical equivalents; NFKC also folds compatibility distinctions and may alter meaning. Unicode normalization does not automatically unify Arabic yeh U+064A with Persian yeh U+06CC or Arabic kaf U+0643 with Persian kaf U+06A9. For a Persian-specific field, map these two variants explicitly if the data owner approves. Preserve U+200C ZERO WIDTH NON-JOINER (ZWNJ), used in Persian morphology, and avoid indiscriminately removing combining marks or format characters. Casefold is useful for caseless English comparison, but can change string length. Store originals and policy version; NER offsets on normalized text may differ from original offsets. Use the same deterministic transformation in train and inference. The examples use Unicode escapes to expose invisible characters.
Persian-specific mapping
import unicodedata as us="\u0645\u064a\u200c\u0631\u0648\u062f"t=u.normalize("NFC",s).translate({0x64a:0x6cc,0x643:0x6a9})print([hex(ord(c)) for c in t])Expected output (locally tested): ['0x645', '0x6cc', '0x200c', '0x631', '0x648', '0x62f']. The explicit mapping preserves the non-joiner.
Common mistakes
Do not assume ASCII conversion is harmless. Do not strip every format character, equate NFC with transliteration, or normalize annotated text without remapping offsets.
Practice and next steps
Compare composed/decomposed accents and check that a Persian ZWNJ survives a targeted mapping. Confirm idempotence on the supplied strings.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Unicode normalization — knowledge check
Apply unicode normalization to small examples and debugging scenarios.
What does NFC preserve?
What should happen to Persian ZWNJ under the stated policy?
Does NFC unify Arabic and Persian yeh?
Why retain original text for NER?
When should inference normalize text?