NATURAL LANGUAGE PROCESSING · INTERVIEW QUESTION
What are the key text preprocessing steps for NLP?
🟢 beginner · Text Preprocessing
Hint: Tokenization, lowercasing, stopwords, stemming/lemmatization.
Answer
Common preprocessing pipeline:
Interview reasoning
-
Tokenization: split text into tokens (words, subwords, or characters).
-
Lowercasing: reduces vocabulary but loses case information (e.g., 'Apple' company vs 'apple' fruit).
-
Stopword removal: remove common words (the, is, at). Useful for bag-of-words, harmful for modern embeddings.
-
Stemming: reduce words to root form (running→run). Fast but crude (porter stemmer).
-
Lemmatization: reduce to dictionary form using POS tags (better→good). More accurate than stemming.
-
Special character/HTML removal.
-
Normalization: unicode, accents, contractions.
Important: for transformer-based models (BERT, GPT), minimal preprocessing is needed — the tokenizer handles subword splitting. Over-preprocessing can hurt these models.
Always match preprocessing between training and inference.
Preprocessing must preserve information needed for the task and match the model's training conventions. Tokenization affects sequence length and offsets; normalization can alter identifiers, numbers or negation. Change one step at a time and inspect representative domain inputs before assuming a generic cleanup recipe improves accuracy.
Worked example. Clinical negation, punctuation and capitalization can carry meaning; retain them unless the task and model justify removal. For extraction, keep a reversible offset map to the original text so a normalized prediction can identify the correct source span.
Validation
Test domain strings, token/character offsets and training-serving parity; ablate transformations on held-out task slices. Include identifiers, numbers, Unicode variants and empty inputs in the fixture set.
Common pitfalls
A shorter or cleaner-looking input is not automatically better. Swapping a tokenizer without compatible pretrained embeddings can break model semantics.