Natural Language Processing
Computers only understand numbers. NLP is the bridge that lets them read, understand and write human language.
By the end of this lesson you will be able to
- explain how a computer turns a sentence into numbers
- name the major NLP tasks and where you meet them
- explain why context makes language hard, and how modern models handle it
Natural Language Processing (NLP) is the branch of AI that lets computers understand, interpret, analyse and generate human languages like English, Hindi, French or Tamil.
The goal is simple: let humans and computers communicate naturally, in speech or writing.
| Human | Computer |
|---|---|
| Understands words | Understands numbers |
| Uses grammar | Uses mathematical models |
| Learns language from experience | Learns from training data |
| Understands emotions | Predicts patterns in text |
| Speaks naturally | Generates text with AI models |
Write “I love AI.” on the board. What language is it? Is the speaker happy or angry? Everyone answers instantly. Now ask: how does a computer know that “love” is positive? Because it has learned patterns from billions of sentences during training.
How NLP works, step by step
First the text is split into smaller pieces called tokens: ["I", "love", "Machine", "Learning"]. Each token gets an ID number (I → 152, love → 849, …), and each ID becomes a vector of numbers. The AI never works with letters directly; it only works with numbers. You can try a live tokeniser in lesson 9.
Why is language so hard for computers?
Because language is ambiguous, and meaning depends on context.
“I saw a man with a telescope.”
Who has the telescope: the man, or me? Humans use context; computers must learn to.
“Apple”
🍎 a fruit, or 💻 Apple Inc.? The AI decides from the surrounding words.
“Bank”
“The bank approved my loan” (money) vs “The fisherman sat on the bank” (river side).
“Bat”
🦇 a flying mammal, 🏏 a cricket bat, or ⚾ a baseball bat.
Major NLP tasks
1. Text classification
“This movie is amazing.” → Positive review
Spam detection, email categories, news topics
2. Sentiment analysis
“I love this phone” → Positive 😊. “Worst product ever” → Negative 😞
Product reviews, social media monitoring, feedback
3. Machine translation
English → French, Hindi → English
Google Translate, Microsoft Translator, Amazon Translate
4. Text summarisation
Long article → short summary
News, research papers, meeting notes
5. Question answering
“Who is the Prime Minister of India?” → the answer
ChatGPT, customer support, virtual assistants
6. Text generation
“Write a poem on nature.” → a poem
ChatGPT, Gemini, Claude
7. Named Entity Recognition
“Rahul works at Amazon in Bengaluru.” → Person, Organisation, Location
Resume parsing, medical records, search engines
8. Speech recognition
Speech → text
Alexa, Siri, Google Assistant, voice notes
9. Text-to-speech
Text → natural voice
GPS navigation, audiobooks, accessibility
How NLP evolved
| Era | How it worked | Limitation |
|---|---|---|
| Rule-based | Dictionaries and hand-written rules: IF text contains “good” THEN positive | Hard to maintain, fails on ambiguity and context (“not good”) |
| Machine learning | Learns from labelled examples: 10,000 reviews → classifier → spam / not spam | Still needs hand-crafted features |
| Deep learning | Neural networks: RNN, LSTM, GRU, then Transformers | Needs lots of data and compute |
| Large Language Models | ChatGPT, Gemini, Claude, Llama, DeepSeek, trained on trillions of tokens | Can confidently make mistakes (“hallucinate”) |
The three ideas behind modern NLP
Tokenisation
Models read tokens, not whole sentences. Common words are one token; rare words are split: unbelievable → un + believ + able. This lets the model handle new and rare words.
Embeddings
Each token becomes a vector, like King → [0.23, 0.51, …]. Words with similar meanings get similar vectors, so King sits close to Queen, Doctor near Nurse, Paris near France. The model learns these relationships automatically.
Attention
In “The cat chased the mouse because it was hungry”, who was hungry? The model uses attention to decide which earlier words matter most for each word. This made NLP dramatically more accurate, and it is the heart of the Transformer.
Real-world applications
| Application | NLP task |
|---|---|
| ChatGPT | Text generation |
| Google Translate | Machine translation |
| Gmail | Spam detection |
| Alexa | Speech recognition |
| Siri | Question answering |
| Grammarly | Grammar correction |
| Amazon reviews | Sentiment analysis |
| Banking chatbots | Customer support |
| WhatsApp voice messages | Speech-to-text |
| Meeting assistants | Summarisation |
ChatGPT does not look answers up in a giant database. It predicts the next most probable token based on your prompt and the patterns it learned in training. Lessons 9 and 10 show exactly how.
For each sentence decide the sentiment, or which “Apple” / “bank” is meant: “I love this movie.” “This movie is terrible.” “Apple launched a new iPhone.” “I ate an apple after lunch.” “The bank approved my loan.” “The fisherman sat on the river bank.” Then ask: how did you figure it out? From context. NLP models learn to use context mathematically through embeddings and attention.
Key takeaways
- AI makes machines intelligent; ML learns from data; deep learning uses neural networks; NLP applies them to human language.
- Text → tokens → numbers (vectors) → model → prediction.
- Language is ambiguous; embeddings and attention let models use context.
- NLP turns human language into maths, so machines can understand, translate, summarise and generate text.
Check your understanding
1. “Rahul works at Amazon in Bengaluru” → Person, Organisation, Location. Which task is this?
NER finds and labels the important names in text.
2. Why do models split “unbelievable” into un + believ + able?
Sub-word tokens let a fixed vocabulary cover almost any word.
3. What makes “The bank approved my loan” understandable to a Transformer?
Attention lets “bank” pick up meaning from “loan” and “approved”.