How NLP works
Computers only understand numbers, so NLP follows a pipeline: clean the text (preprocessing), turn it into numbers (feature extraction), then let a model learn patterns from those numbers and make a prediction or write a reply.
Everyday analogy
Cooking dal: first you wash and sort the lentils (preprocessing), then measure them into the cooker (turning into numbers), then cook with the recipe (the model) to get the dish (the answer).
Example
A review that says "I'm LOVING this new phone!!! 😍 #happy" is cleaned into the words love, new, phone, happy, turned into numbers, and a model labels it positive.
The NLP pipeline
Preprocessing one sentence, step by step
| Step | What happens | Result |
|---|---|---|
| Raw text | As the user wrote it | I'm LOVING this new phone!!! 😍 #happy |
| Tokenise | Split into pieces | [I, 'm, LOVING, this, new, phone, !, !, !, 😍, #happy] |
| Lowercase & clean | Make case consistent; remove punctuation; keep the hashtag word | [i, 'm, loving, this, new, phone, happy] |
| Remove stop words | Drop very common words that carry little meaning | [loving, new, phone, happy] |
| Stem / lemmatise | Reduce words to a root form | [love, new, phone, happy] |
Modern transformer models need less of this cleaning, because they learn from text almost as it is.
Stemming vs lemmatisation
Stemming
Chops word endings by simple rules. Fast but rough.
studies → studi · running → run · better → better
Lemmatisation
Uses a dictionary to find the real base word. Slower but accurate.
studies → study · running → run · better → good
Turning text into numbers
Bag of words
Count how many times each word appears, ignoring order.
"good phone, good price" → good: 2, phone: 1, price: 1
TF-IDF
Like word counts, but words that appear in almost every document (like "the") get a lower score, and rare, telling words get a higher score.
"refund" in a complaint scores high; "the" scores low
Word embeddings
Each word becomes a list of numbers that captures its meaning, so similar words have similar numbers.
"happy" and "joyful" end up close together
Contextual embeddings
Transformers give a word different numbers depending on the sentence around it.
"bank" in "river bank" vs "bank loan"
Try it yourself
About 15 minPreprocess a sentence by hand
- Take: The cats are running quickly to the gardens!
- Lowercase it, remove punctuation and stop words, and cut words to their roots (cats → cat).
- Compare with what an AI chatbot produces when asked to do the same.
What you should see: You did the cleaning step that NLP pipelines run on every text.
Use any free AI chatbot (ChatGPT, Claude, Gemini or Copilot). Never paste private or confidential information.