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.

📄Raw text"The catsran!"🧹Cleanlowercase,punctuation✂️Tokenisethe · cats ·ran🌱Normalisecats → cat🔢Vectorisenumbers🤖Modelprediction
The classic NLP pipeline, from raw text to a prediction.

The NLP pipeline

1. Raw textReviews, emails, chats, speech turned into text
→
2. PreprocessSplit into tokens, lowercase, remove noise and stop words, reduce words to their root
→
3. Represent as numbersBag of words, TF-IDF or word embeddings
→
4. ModelLogistic regression, Naive Bayes, neural network or transformer
→
5. OutputA label, a score, a translation or a written reply

Preprocessing one sentence, step by step

StepWhat happensResult
Raw textAs the user wrote itI'm LOVING this new phone!!! 😍 #happy
TokeniseSplit into pieces[I, 'm, LOVING, this, new, phone, !, !, !, 😍, #happy]
Lowercase & cleanMake case consistent; remove punctuation; keep the hashtag word[i, 'm, loving, this, new, phone, happy]
Remove stop wordsDrop very common words that carry little meaning[loving, new, phone, happy]
Stem / lemmatiseReduce 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 min

Preprocess a sentence by hand

  1. Take: The cats are running quickly to the gardens!
  2. Lowercase it, remove punctuation and stop words, and cut words to their roots (cats → cat).
  3. 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.

Build it for real · guided projectBuild a sentiment analyser for product reviewsAbout 60 min · Copy-paste code · step by step
Test what you learned

Take a quick quiz, or look up any word in the glossary.