Class 10 AI Unit 6: Natural Language Processing (NLP) – Notes, Bag of Words, TF-IDF | CBSE Code 417

Class 10 · AI (417) · Part B · Unit 6
Natural Language Processing

Why human language is hard for machines, stages of NLP, chatbots, text normalisation, Bag of Words and TF-IDF, explained step by step.

8 Marks (Theory)20 hrs Theory + 7 hrs PracticalNumericals Asked
In this chapter
  1. Why is human language hard for computers?
  2. Applications of NLP
  3. Stages of NLP
  4. Chatbots: script bots vs smart bots
  5. Text normalisation
  6. Bag of Words and TF-IDF
  7. Sentiment analysis in Orange
๐Ÿ“– "Nice, very nice."

Your friend breaks your pen and you say, "Nice. Very nice." Everyone around you knows you're annoyed. But a computer reading those words sees two happy words! Human language is full of tone, sarcasm, slang and double meanings. Natural Language Processing (NLP) is the branch of AI that tries to make sense of all this.

1. What is NLP?

๐Ÿ”‘ Definition

NLP is the domain of AI that enables computers to understand, interpret and respond to human language, in both text and speech.

Why natural language is tricky

  • Same words, different meanings: "I saw her bat" — a cricket bat or the animal?
  • Perfect grammar, no sense: "Chickens feed extravagantly while the moon drinks tea." Grammatically fine, meaningless.
  • Different word order, different meaning: "Dog bites man" vs "Man bites dog".
  • Context and tone: sarcasm, idioms ("break a leg"), slang and mixed languages (Hinglish!).
"I saw her bat" ๐Ÿ Meaning 1: a cricket bat ๐Ÿฆ‡ Meaning 2: the flying animal Same words… which meaning? You use context. A computer has to learn that.

2. Applications of NLP

๐Ÿ—ฃ️

Voice assistants

Alexa, Siri, Google Assistant understand spoken commands.

๐ŸŒ

Machine translation

Google Translate converts Hindi to English and more.

๐Ÿ˜Š

Sentiment analysis

Finds if reviews/tweets are positive, negative or neutral.

๐Ÿ—‚️

Text classification

Spam filters sort emails; news apps sort articles by topic.

๐Ÿ”‘

Keyword extraction

Pulls out the most important words from a long text.

๐Ÿ“

Captions & summaries

YouTube auto-captions; apps that summarise long articles.

3. Stages of NLP

1. Lexicalwords / tokens 2. Syntacticgrammar / order 3. Semanticmeaning 4. Discourselink sentences 5. Pragmaticreal intent
Each stage understands a bit more, from single words up to what the speaker really means.
StageWhat happensExample
Lexical analysisBreaks text into words/tokens and identifies their structure."I love AI" → [I] [love] [AI]
Syntactic analysis (parsing)Checks grammar and word arrangement."We are to the zoo going tomorrow" ✘ → "We are going to the zoo tomorrow" ✔
Semantic analysisChecks whether the sentence makes sense (meaning)."Hot ice cream" is grammatical but odd in meaning.
Discourse integrationConnects the meaning of a sentence with previous ones."Riya won. She was happy." → "she" = Riya
Pragmatic analysisUnderstands the real intended meaning in context."Can you pass the salt?" is a request, not a yes/no question.

4. Chatbots

A chatbot is a program that chats with humans in natural language. The handbook asks you to try chatbots like Elizabot, Mitsuku, Cleverbot and Singtel and compare them.

Script botSmart bot
Works on a fixed script / pre-written replies.Uses AI and NLP; flexible and learns from data.
Easy to make; little or no coding.Complex to build; needs lots of data and coding.
Limited functions; gets stuck on unexpected questions.Handles a wide range of questions and improves over time.
Example: customer-care bot with menu options, a bank's FAQ bot.Example: Alexa, Siri, Google Assistant, ChatGPT.
๐Ÿ“œ Script bot (fixed script) Hi! Choose: 1) Fees 2) Timings3) Holidays 4) Contact Is school open if it rains? Sorry, I didn't understand. ๐Ÿ˜•Please choose 1, 2, 3 or 4. …but it's raining a lot! ❌ Stuck in a loop ๐Ÿค– Smart bot (AI + NLP) Hi! How can I help you today? Is school open if it rains? Yes, school stays open in normal rain.If there's a heavy-rain holiday, theschool will SMS parents by 7 AM. ☔ Thanks! ๐Ÿ˜Š ✅ Understands meaning
Same question, two bots. The script bot only knows its menu; the smart bot understands what you mean.

5. Text Normalisation

Before a computer can count words, we clean up the text. All the text from all documents together is called the corpus.

SentenceSegmentation Tokenisation Remove stopwords& special chars Convert tocommon case Stemming /Lemmatisation "Riya is Playing! She played well." → [riya, play, play, well] (stopwords like "is", "she" removed; lowercase; "playing/played" → "play")
"Riya is Playing! She played well." ① TOKENS RiyaisPlaying!Sheplayedwell. red tokens (stopwords & punctuation) fall away ② LOWERCASE + LEMMATISE riyaplayplaywell
Text normalisation in action: split → remove noise → lowercase → reduce to root words.
StepWhat it does
Sentence segmentationSplits the corpus into sentences.
TokenisationSplits sentences into tokens (words, numbers, symbols).
Removing stopwords, special characters, numbersRemoves very common words (a, an, the, is, and) and symbols that add little meaning.
Converting to common caseMakes everything lowercase so "Hello" and "hello" count as one word.
StemmingChops off word endings. Fast, but the result may not be a real word: "studies" → "studi".
LemmatisationReduces to the proper dictionary word (lemma): "studies" → "study". Slower but meaningful.

6. Bag of Words (BoW)

Bag of Words counts how many times each word appears in each document, ignoring grammar and order. Just like tipping all the words into a bag and counting them.

amananilwenttoamanto ๐Ÿ›️ BAG Word counts aman2 anil1 went1 to2
Bag of Words forgets the order and only counts how often each word appears.

Steps: 1) Text normalisation → 2) Create the dictionary (all unique words) → 3) Create document vectors (count of each word per document) → 4) Create document vectors for all documents.

๐Ÿงฎ Solved example

D1: "Aman and Anil are stressed" · D2: "Aman went to a therapist" · D3: "Anil went to download a health chatbot"

Docamanandanilarestressedwenttoatherapistdownloadhealthchatbot
D1111110000000
D2100001111000
D3001001110111
DF212112221111

The dictionary has 12 unique words. Each row is a document vector. DF (document frequency) = in how many documents the word appears.

Try it yourself

๐Ÿงช Bag of Words Lab — type your own documents

Edit the three documents and press Build. The lab lowercases the text, removes punctuation and (optionally) stopwords, then builds the dictionary, document vectors and TF-IDF (log base 10).

TF-IDF: which words really matter?

Words like "to" and "a" appear everywhere, so they tell us little. Rare words like "stressed" or "therapist" say a lot about a document. TF-IDF gives more weight to such words.

TermMeaning / formula
TF (Term Frequency)How many times a word appears in a document.
DF (Document Frequency)Number of documents in which the word appears.
IDF (Inverse Document Frequency)log(N ÷ DF), where N = total number of documents.
TF-IDFTF × log(N ÷ DF)
๐Ÿงฎ Using our example (N = 3)

"aman" in D1: TF = 1, DF = 2 → 1 × log(3/2) = 1 × 0.176 = 0.176
"stressed" in D1: TF = 1, DF = 1 → 1 × log(3/1) = 1 × 0.477 = 0.477
"stressed" scores higher, so it's more important for D1. That matches common sense!

✅ Exam tip

A word that appears in all documents gets IDF = log(1) = 0, so its TF-IDF is 0. That's why stopwords end up with the lowest value. Use log base 10 in board answers.

7. Sentiment Analysis with Orange (Practical)

In the practical, you'll use Orange's Text Mining add-on on a dataset of reviews:

Corpus (load text) → Preprocess Text (normalise) → Sentiment Analysis (score each review) → Data Table / Word Cloud (see results). Positive reviews get positive scores, negative reviews negative scores.

๐Ÿ˜"Loved it! Best phone ever."๐Ÿ˜"It's okay, nothing special."๐Ÿ˜ก"Worst service, very slow." NegativeNeutralPositive
Sentiment analysis gives each review a score: the dot slides to where the feeling belongs.
๐Ÿ’ฌ
Try it: chat with a script bot (any bank's FAQ bot) and a smart bot (Google Assistant or ChatGPT). Ask both the same tricky question, like "Can you suggest a good movie for a rainy day?" Notice which one gets stuck. That's your script bot vs smart bot answer in the exam!

Quick Check

Q1. "We are to the zoo going tomorrow" — which stage catches this error?

Syntactic analysis (grammar/word order).

Q2. "studies" → "studi" is stemming or lemmatisation?

Stemming.

Q3. What is the IDF of a word that appears in all 4 documents?

log(4/4) = log 1 = 0.

Q4. Is Alexa a script bot or smart bot?

Smart bot.

⚡ One-minute revision

  • NLP = AI that understands human language (text and speech).
  • Stages: Lexical → Syntactic → Semantic → Discourse → Pragmatic.
  • Script bot = fixed script; smart bot = AI-powered and flexible.
  • Normalisation: segmentation → tokenisation → remove stopwords → common case → stemming/lemmatisation.
  • BoW: dictionary + document vectors. TF-IDF = TF × log(N/DF).

Done reading? Test yourself on AI Unit 6 in board-exam style.

๐Ÿ“ Take the Practice PaperNext: AI Unit 7 ›๐Ÿ  Class 10 Hub

Comments

๐Ÿงญ Explore AI Topics

Keep learning with our topic guides for CBSE AI (Classes 6–12).

๐Ÿ”„ AI Project Cycle๐Ÿ Python for AI๐Ÿค– Machine Learning๐Ÿ’ฌ NLP๐Ÿ‘️ Computer Vision⚖️ AI Ethics