CHAPTER PDF
Complete curriculum textbook chapter document for reading and offline study.
NOTES
Complete conceptual breakdown, formulas, diagrams, and memory aids.
Unit 6: Natural Language Processing
Complete textbook-aligned notes, activities, worked examples, objective questions, competency-based practice and board-examination revision.
Unit overview
Lesson title: Natural Language Processing (NLP) · Approach: Session + Activity.
This unit introduces NLP, its importance and applications; the five stages of NLP; text normalisation; Bag of Words; TFIDF; sentiment analysis; and no-code tools such as Orange Data Mining.
Learning objectives
- Understand NLP and its importance.
- Identify applications of NLP.
- Explain the stages of NLP.
- Understand text-processing techniques.
- Identify no-code NLP tools.
- Explain Bag of Words.
- Understand TFIDF.
- Explore Orange Data Mining.
Learning outcomes
- Describe why NLP data is pre-processed.
- Recognise the steps of NLP pre-processing.
- List no-code NLP applications and tools.
- Outline Bag of Words.
- Explain TFIDF.
- Explain sentiment analysis.
6.1 Introduction
What is a natural language?
A natural language is a language that human beings use to communicate, such as English, French, Spanish and Japanese.
Features of natural languages
- Rules: Natural languages follow rules involving syntax (grammar and arrangement), lexicon (words and phrases) and semantics (meaning).
- Redundancy: The same information can be communicated in more than one way.
- Change over time: Vocabulary, expressions and usage evolve over generations.
Same-sounding words can have different meanings
Pronunciation alone may not tell us which word is intended. Context helps us decide.
| Sentence / prompt | Correct word | Reason |
|---|---|---|
| I am so tired; I want to take a ___. | break | A break means a rest. A brake is used to slow or stop a vehicle. |
| Let’s ___ her a letter. | write | Write means to form words. Right means correct or a direction. |
Meaning depends on context
- “His face turned red after he found out that he took the wrong bag.” Red may indicate embarrassment or anger; the surrounding situation helps interpret it.
- “The red car zoomed past his nose.” Red refers to the car’s colour.
- “His face turns red after consuming the medicine.” It may describe a physical reaction, such as flushing or an allergy. The sentence alone does not prove the cause.
Computer language
A computer language is a language used to give instructions to a computer. Examples include Python, C++, Java and HTML.
Can computers understand our language?
Computers need instructions in a form they can process. Human language is flexible, ambiguous and context-dependent. A computer program converts or analyses human-language input so that a machine can process it.
Why is NLP important?
Computers ultimately process electronic information in digital/binary form. NLP helps bridge the gap between human communication and computer processing. Its purpose is to make communication between people and computer systems possible while helping systems interpret intent and context.
Think and answer: Give two examples of words with multiple meanings.
Bank: “I deposited money in the bank.” (financial institution); “We sat on the river bank.” (side of a river).
Light: “Switch on the light.” (illumination); “This bag is light.” (not heavy).
6.2 Applications of Natural Language Processing
NLP is used in everyday AI systems to understand speech or text, identify information, classify content and respond to people.
1. Voice assistants
Voice assistants receive spoken language, process the request and provide an output or perform a task.
Examples: “Hey Google, set an alarm at 3:30 pm”; “Hey Alexa, play some music”; “Hey Siri, what’s the weather today?”
2. Auto-generated captions
Speech is converted into text in real time or near real time. Captions improve accessibility and help viewers follow video content.
Examples: YouTube captions and captions in Google Meet.
3. Language translation
Text or speech is converted from one language into another, supporting communication between people who use different languages.
Example: Google Translate.
4. Sentiment analysis
Sentiment analysis identifies whether an opinion expressed in text is positive, negative or neutral. Businesses can analyse customer opinions about products, services or a brand.
5. Text classification
Text classification places a sentence or document into a predefined category. For example, news articles can be grouped as Food, Sports or Politics.
6. Keyword extraction
Keyword extraction automatically identifies important words or phrases in a text. It can help reveal the main topics in customer feedback and social-media posts.
It is useful in document summarisation, information retrieval and content analysis.
Activity 1: Keyword Extraction
Purpose: Learn how an API can perform keyword extraction from a website.
- Open Google Cloud Natural Language.
- Open the Natural Language API demonstration and choose Analyse.
- Observe the highlighted keywords in the sample paragraph (the textbook illustration shows words such as “Google” and “Mountain View”).
- Try other available analysis options.
- Enter your own paragraph and compare the output.
6.3 Stages of Natural Language Processing (NLP)
The textbook presents five stages. They help a system move from identifying words to interpreting intended meaning.
1. Lexical Analysis
It identifies the structure of input text by dividing a large body of text into paragraphs, sentences and words. Lexicon means the collection of words and phrases used in a language.
Example: “The quick brown fox jumped over the lazy dog” can be broken into individual word units: The | quick | brown | fox | jumped | over | the | lazy | dog.
2. Syntactic Analysis / Parsing
It checks the grammatical structure of sentences and phrases and establishes relationships among words. It can identify grammatically incorrect word arrangements.
Example: “The quick brown jumped fox over the lazy dog” has an incorrect word arrangement. “The quick brown fox jumped over the lazy dog” is grammatically structured correctly.
3. Semantic Analysis
It checks whether words and phrases make sense in meaning. A sentence may be grammatically correct but semantically unusual or meaningless.
Example: “hot ice cream” is presented in the textbook as a phrase whose meaning is contradictory in the usual sense. “The fox jumped into the dog” is also used as an example of an unusual meaning.
4. Discourse Integration
It checks the relationship between a sentence and the sentences before and after it. This helps form a coherent flow of ideas and resolve references.
Example: “The quick brown fox jumped over the lazy dog. Then it went into the thick bushes.” In context, “it” refers to the fox. Without the earlier sentence, the reference may be unclear.
5. Pragmatic Analysis
It checks the intended meaning in a real-world situation. It goes beyond the literal meaning of words and considers the speaker’s purpose or intent.
Example: “Relax! I’m just pulling your leg” means “I am joking”, not that someone is physically pulling a leg.
| Stage | Main question | What it does |
|---|---|---|
| Lexical | What are the text units? | Breaks text into paragraphs, sentences and words. |
| Syntactic | Is the arrangement grammatical? | Checks grammar and relationships among words. |
| Semantic | Does it make sense? | Checks literal meaning and meaningfulness. |
| Discourse | How do sentences connect? | Uses preceding and succeeding sentences for coherence. |
| Pragmatic | What does the speaker intend? | Interprets practical, contextual and intended meaning. |
6.4 Chatbots
A chatbot is a computer program designed to simulate human conversation through voice commands, text chats or both. It may answer questions, troubleshoot customer problems, qualify prospects, generate sales leads and support online shopping.
Activity 2: Play with chatbots
Purpose: Identify and interact with different chatbots.
Textbook examples:
Interact with one or more chatbots and discuss: Which chatbot did you try? What is its purpose? How was the interaction? Did it feel human-like or robotic, and why? Did it appear to have a personality?
Types of chatbots
| Script bot (traditional chatbot) | Smart bot (AI-powered chatbot) |
|---|---|
| Easy to make. | More flexible and powerful. |
| Works around a predefined script. | Can work on larger databases and other resources directly. |
| Often free and easy to integrate into a messaging platform. | Can learn from more data. |
| Little or no language-processing skill. | Requires coding to set up, as described in the textbook. |
| Limited functionality. | Wide functionality. |
6.5 Text Processing
Human languages are convenient for people but complex for computers. Since computers process numerical representations, text is cleaned and converted into a simpler, structured form before analysis. The textbook introduces Text Normalisation as the first major step in this process.
Corpus
Text Normalisation — six steps
1. Sentence Segmentation
The corpus is divided into individual sentences. Each sentence is treated as a separate data unit.
Input: “In CBT, we learn to decipher the lies we are undermining ourselves with. I’m never going to make any friends.”
Output: Sentence 1: “In CBT, we learn to decipher the lies we are undermining ourselves with.”
Sentence 2: “I’m never going to make any friends.”
2. Tokenization
Each sentence is divided into tokens. A token may be a word, number or special character. Each is treated separately.
“In CBT, we learn.” → In | CBT | , | we | learn | .
3. Removing stop words, special characters and numbers
Stop words occur frequently but usually contribute little to the topic being analysed. Examples shown in the textbook include: a, an, and, are, as, for, it, is, into, in, if, on, or, such, that, the, there, to.
Removing these words helps a computer focus on meaningful terms. Special characters and numbers may also be removed when they are not useful. However, the decision depends on the corpus: for an email-address dataset, symbols and numbers may be important and should be retained.
4. Converting text to a common case
Text is converted to a consistent case, preferably lowercase. This prevents a case-sensitive system from treating “HELLO”, “Hello” and “hello” as different words.
5. Stemming
Stemming removes affixes (such as suffixes) to reduce words to a stem or base-like form. It does not check whether the result is a meaningful dictionary word, so it is generally faster.
| Word | Affix removed | Stem |
|---|---|---|
| healed | -ed | heal |
| healing | -ing | heal |
| healer | -er | heal |
| studies | -es | studi |
| studying | -ing | study |
6. Lemmatization
Lemmatization also reduces words by removing or changing affixes, but it ensures that the resulting lemma is a meaningful word. It usually takes longer than stemming because it considers the valid base form.
| Word | Affix removed | Lemma |
|---|---|---|
| healed | -ed | heal |
| healing | -ing | heal |
| healer | -er | heal |
| studies | -es | study |
| studying | -ing | study |
Bag of Words (BoW)
The “bag” metaphor means that the sequence or order of words is ignored. The model focuses on which words occur and how often they occur.
What does Bag of Words produce?
- Vocabulary: A list of all unique words in the corpus.
- Word frequency: The number of times each vocabulary word occurs.
Steps of the Bag of Words algorithm
- Text processing: Collect and preprocess the text.
- Create a dictionary: List all unique words in the corpus. This is the vocabulary.
- Create document vectors: For each document, count how many times each vocabulary word occurs.
- Repeat for all documents: Create one vector for every document in the corpus.
Worked textbook example
Step 1 — Documents after text normalisation
| Document | Normalised tokens |
|---|---|
| Document 1 | aman, and, avni, are, stressed |
| Document 2 | aman, went, to, a, therapist |
| Document 3 | avni, went, to, download, a, health, chatbot |
Step 2 — Create the dictionary
The vocabulary contains each unique token once. For clarity, this table uses the same vocabulary as the textbook:
Step 3 — Create the vector for Document 1
Put 1 where the vocabulary word occurs and 0 where it does not occur. If a word occurs more than once, record its count (not merely 1).
| Word | aman | and | avni | are | stressed | went | to | a | therapist | download | health | chatbot |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Doc 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
Step 4 — Create vectors for all documents
| Document | aman | and | avni | are | stressed | went | to | a | therapist | download | health | chatbot |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Doc 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| Doc 2 | 1 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 | 0 |
| Doc 3 | 0 | 0 | 1 | 0 | 0 | 1 | 1 | 1 | 0 | 1 | 1 | 1 |
TFIDF: Term Frequency and Inverse Document Frequency
Bag of Words counts words, but very common words may not be useful for distinguishing one document from another. TFIDF estimates how important a word is to a particular document within a corpus.
The textbook graph on page 21 distinguishes:
- Stop words: Extremely common words with negligible value for the topic.
- Frequent words: Words that occur adequately and often describe the subject.
- Rare / valuable words: Words that occur less often but may carry more information.
1. Term Frequency (TF)
Term Frequency is the number of times a word occurs in one document. In the document-vector table, it is the count in the relevant document row.
2. Document Frequency (DF)
Document Frequency is the number of documents in which a word occurs, regardless of how many times it occurs in each document.
3. Inverse Document Frequency (IDF)
The textbook calculates IDF by dividing the total number of documents by the document frequency.
4. TFIDF formula used in the textbook
The logarithm is base 10. The textbook notes that a calculator’s log function can be used.
Worked example based on the textbook’s three-document corpus
There are 3 documents. The words aman, avni, went, to, a occur in 2 documents each; the other vocabulary words occur in 1 document each.
| Word | DF | IDF = 3/DF | log10(IDF) |
|---|---|---|---|
| aman, avni, went, to, a | 2 | 1.5 | 0.176 |
| and, are, stressed, therapist, download, health, chatbot | 1 | 3 | 0.477 |
Multiply each document’s TF by the corresponding log10(IDF) value. For example, in Document 1, TF(aman)=1 and log10(3/2)=0.176, so TFIDF(aman)=1 × 0.176 = 0.176. For “and”, TF=1 and log10(3/1)=0.477, so TFIDF= 0.477.
Interpretation and textbook illustration
- A word appearing in every document has IDF = N/N = 1, so log10(1)=0 and its TFIDF becomes 0 under this formula.
- A word appearing in fewer documents has a larger IDF and can receive a higher value when it occurs in a particular document.
- A high TFIDF value indicates that the word is important to a document but is not common throughout the corpus.
Applications of TFIDF
| Application | Use |
|---|---|
| Document classification | Helps classify the type or genre of a document. |
| Topic modelling | Helps predict or identify the topic of a corpus. |
| Information retrieval system | Helps extract important information from a corpus and rank relevant text. |
| Stop-word filtering | Helps identify and remove words that contribute little information. |
6.6 Natural Language Processing: Use Case Walkthrough
Purpose: Introduce no-code tools for NLP and use Orange Data Mining to explore sentiment analysis.
Code NLP tools
- NLTK (Natural Language Toolkit): A Python package containing functions and modules for text processing and NLP.
- spaCy: An open-source NLP library for building NLP applications. Features include tokenisation, part-of-speech tagging, named-entity recognition and dependency parsing.
No-code NLP tools
- Orange Data Mining: A machine-learning and data-analysis tool that supports visual programming. Users can perform operations through drag-and-drop widgets.
- MonkeyLearn: A text-analysis platform offering NLP and machine-learning tools for classification, sentiment analysis and entity recognition. It supports custom or pre-trained models.
Sentiment analysis
Sentiment analysis is an NLP technique used to analyse whether textual data is positive, negative or neutral. It can help detect customer opinions and emotions in feedback about products, services or brands.
Applications of sentiment analysis
Automatically detects customer sentiment during interactions and helps organisations understand customer reactions.
Analyses customer feedback to produce actionable insights and measure the gap between customer expectations and actual experience.
Orange Data Mining case walkthrough
The textbook provides a guided project resource:
- Short link: https://bit.ly/OrangeNLP
- Long link: Google Drive case-walkthrough folder
Textbook Test Yourself and Quiz — solved
Section 6.1: Choose the right word (page 2)
1. I am so tired; I want to take a ____.
2. Let’s ____ her a letter.
Section 6.3: Choose the right answer (page 10)
1. Syntax refers to the grammatical structure of a sentence. Yes or No?
2. Which technique is used to assess the meaningfulness of the input text?
Section 6.4: Quiz Time (pages 12–13)
1. NLP majorly deals with which type of processing?
2. Which NLP tool expresses whether sentiment is positive, negative or neutral?
3. What is the first stage of NLP?
4. Words filtered out before text analysis are called what?
5. What does discourse integration involve?
Section 6.6: Test Yourself (pages 26–28)
1. Primary challenge faced by computers in understanding human languages?
2. How do voice assistants use NLP?
3. Which is NOT a step in Text Normalisation?
4. What is the purpose of tokenisation?
5. What distinguishes lemmatization from stemming?
6. Primary purpose of Bag of Words?
7. What are stop words?
8. Characteristic of rare or valuable words?
9. What information does a document-vector table provide?
10. Primary purpose of TFIDF?
11. Assertion–Reason: Pragmatic analysis checks practical applicability; it considers intended meaning rather than only literal meaning. Choose the correct option.
12. Assertion–Reason: Lowercasing text creates uniform word representation and prevents case variants being treated as distinct. Choose the correct option.
Reflection Time — complete textbook answers
1. Mention a few features of natural languages.
Natural languages have the following features:
- They follow rules such as syntax, lexicon and semantics.
- They are redundant, which means the same information can be expressed in different ways.
- They change over time as vocabulary and usage develop.
- The meaning of a word can depend on the context in which it is used.
2. What is the significance of NLP?
NLP is important because it enables computers to process and understand human language. Computers work with digital information, whereas people communicate through natural languages. NLP helps bridge this gap. It is used in voice assistants, translation, captions, chatbots, sentiment analysis and text classification.
3. What do you mean by lexical analysis in NLP?
Lexical analysis is the first stage of NLP. It identifies the structure of input text by dividing a large text into paragraphs, sentences and words. The term lexicon refers to the collection of words and phrases in a language. For example, a sentence can be separated into individual word tokens.
4. What do you mean by a chatbot?
A chatbot is a computer program designed to simulate conversation with a human through text messages, voice commands or both. It can answer questions, provide customer support, troubleshoot problems and help users complete tasks. Chatbots may be script-based or AI-powered.
5. What does “Bag of Words” refer to in NLP?
Bag of Words is a model that represents text using the unique words in a corpus and their frequencies. It first creates a vocabulary and then creates a numerical vector for each document by counting how often each vocabulary word occurs. It ignores the order of words and is used to extract features for machine-learning algorithms.
6. Describe two practical uses of NLP in real-world scenarios.
1. Voice assistants: Tools such as Google Assistant, Alexa and Siri process spoken requests, understand the user’s intent and perform tasks such as setting alarms or playing music.
2. Language translation: Tools such as Google Translate convert text or speech from one language into another, helping people communicate across language barriers.
7. Explain stemming and lemmatization with an example.
Stemming removes affixes to produce a stem without checking whether the result is a meaningful word. For example, “studies” may become “studi”.
Lemmatization reduces a word to a meaningful base form (lemma). For example, “studies” becomes “study”. In the textbook’s comparison, “caring” becomes “car” through stemming but “care” through lemmatization. Stemming is usually faster, whereas lemmatization aims for a meaningful result.
8. Describe any four applications of TFIDF.
- Document classification: Helps identify the type or genre of a document by assigning importance to its terms.
- Topic modelling: Helps identify or predict the topics represented in a collection of documents.
- Information retrieval: Helps find and rank documents containing terms important to a user’s search.
- Stop-word filtering: Helps identify very common words that contribute little information and can be filtered.
9. Samiksha must normalise the two given documents. Show the steps.
Given documents:
Document 1: “Akash and Ajay are best friends.”
Document 2: “Akash likes to play football but Ajay prefers to play online games.”
Step 1 — Sentence segmentation: Each given sentence is already one sentence, so each document remains one sentence.
Step 2 — Tokenisation:
Doc 1: Akash | and | Ajay | are | best | friends | .
Doc 2: Akash | likes | to | play | football | but | Ajay | prefers | to | play | online | games | .
Step 3 — Remove stop words and punctuation: Using the textbook’s common stop-word examples, remove “and”, “are” and “to”; remove the full stop. “But” may also be treated as a stop word by a chosen NLP stop-word list, but it is not explicitly included in the textbook’s displayed examples. To keep the result reproducible, this worked answer removes only the listed words.
Doc 1: Akash, Ajay, best, friends
Doc 2: Akash, likes, play, football, but, Ajay, prefers, play, online, games
Step 4 — Convert to lowercase:
Doc 1: akash, ajay, best, friends
Doc 2: akash, likes, play, football, but, ajay, prefers, play, online, games
Step 5 — Stemming: Apply a stemmer to reduce inflected forms. These words are already mostly in base form; a stemmer may leave them unchanged. “friends” may be reduced to “friend”.
Step 6 — Lemmatization: Convert remaining words to meaningful dictionary forms. Example: “friends” → “friend”; the other listed words remain in their base forms.
One clear final normalised representation:
Doc 1: akash, ajay, best, friend
Doc 2: akash, like, play, football, but, ajay, prefer, play, online, game
10. Calculate TFIDF for the given four-document corpus, step by step.
Documents:
- Johny Johny Yes Papa
- Eating sugar? No Papa
- Telling lies? No Papa
- Open your mouth, Ha! Ha! Ha!
Step 1 — Text normalisation: Convert to lowercase and remove punctuation. For this worked calculation, retain the meaningful words (including “your”) so the assumptions are clear.
| Document | Tokens |
|---|---|
| D1 | johny, johny, yes, papa |
| D2 | eating, sugar, no, papa |
| D3 | telling, lies, no, papa |
| D4 | open, your, mouth, ha, ha, ha |
Step 2 — Create vocabulary: eating, ha, johny, lies, mouth, no, open, papa, sugar, telling, yes, your.
Step 3 — Calculate TF (word count in each document):
| Document | eating | ha | johny | lies | mouth | no | open | papa | sugar | telling | yes | your |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| D1 | 0 | 0 | 2 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 1 | 0 |
| D2 | 1 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 1 | 0 | 0 | 0 |
| D3 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 0 |
| D4 | 0 | 3 | 0 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 1 |
Step 4 — Document Frequency (DF): Count the number of documents containing each word. There are 4 documents in total.
| Word(s) | DF | IDF = 4/DF | log10(IDF) |
|---|---|---|---|
| eating, ha, johny, lies, mouth, open, sugar, telling, yes, your | 1 | 4 | 0.602 |
| no | 2 | 2 | 0.301 |
| papa | 3 | 1.333 | 0.125 |
Step 5 — Apply formula: TFIDF = TF × log10(4/DF).
Examples:
- D1, johny: TF=2, DF=1 → TFIDF = 2 × log10(4) = 2 × 0.602 = 1.204.
- D2, no: TF=1, DF=2 → TFIDF = 1 × log10(2) = 0.301.
- D1, papa: TF=1, DF=3 → TFIDF = 1 × log10(4/3) ≈ 0.125.
- D4, ha: TF=3, DF=1 → TFIDF = 3 × 0.602 = 1.806.
Step 6 — Final TFIDF vectors (rounded to 3 decimal places):
| Document | Non-zero TFIDF values |
|---|---|
| D1 | johny = 1.204; papa = 0.125; yes = 0.602 |
| D2 | eating = 0.602; no = 0.301; papa = 0.125; sugar = 0.602 |
| D3 | lies = 0.602; no = 0.301; papa = 0.125; telling = 0.602 |
| D4 | ha = 1.806; mouth = 0.602; open = 0.602; your = 0.602 |
Conclusion: Words such as “johny”, “eating”, “sugar”, “lies”, “telling” and “ha” are specific to individual documents and receive higher IDF weights. “Papa” occurs in three documents and therefore has a lower IDF weight. “No” occurs in two documents and has an intermediate weight.
Additional CBSE Board Examination Practice
A. Multiple-choice questions
1. Which NLP stage checks the grammatical arrangement of words?
2. Which stage interprets “pulling your leg” as joking?
3. Which process divides a sentence into words, numbers and symbols?
4. Which process converts “studies” into “study” as a meaningful base word?
5. Which model ignores word order and counts vocabulary terms?
6. A word appears in every document. Under the textbook IDF formula, what is log10(IDF)?
7. Which tool is a visual drag-and-drop no-code data-mining tool?
8. Which sentiment category indicates neither a positive nor a negative opinion?
B. Assertion–Reason practice
1. Assertion: Stemming may produce a non-dictionary word. Reason: Stemming removes affixes without checking whether the result is meaningful.
2. Assertion: A word with high document frequency always has a high IDF. Reason: IDF is calculated as total documents divided by document frequency.
3. Assertion: Discourse integration connects sentences. Reason: It considers relationships with preceding and succeeding sentences.
4. Assertion: Lowercasing can prevent “HELLO” and “hello” from being treated as separate tokens. Reason: It standardises text case.
C. Short-answer questions (2–3 marks)
1. Differentiate between syntax and semantics.
Syntax deals with the grammatical arrangement and relationship of words in a sentence. Semantics deals with the meaning of words and phrases and checks whether the sentence makes sense. A sentence can be grammatically correct but still have an unusual or incorrect meaning.
2. Why are stop words removed during text processing?
Stop words occur very frequently but usually add little information about the topic. Removing them reduces unnecessary tokens and allows a computer to focus on meaningful words. Their removal depends on the task; a word should be retained if it carries useful information.
3. What is the difference between a corpus and a document?
A document is one individual text item. A corpus is a collection of documents considered together for processing and analysis.
4. State two differences between script bots and smart bots.
Script bots follow predefined scripts and have limited functionality. Smart bots use AI capabilities, are more flexible and can handle a wider range of inputs. Script bots are generally simpler to create, while smart bots usually require more sophisticated development.
5. What is the role of document frequency in TFIDF?
Document frequency counts how many documents contain a term. It is used to calculate inverse document frequency. A term appearing in many documents receives a lower IDF, while a term appearing in fewer documents receives a higher IDF.
D. Long-answer questions (4–5 marks)
1. Explain the five stages of NLP with examples.
- Lexical analysis: Breaks text into paragraphs, sentences and words.
- Syntactic analysis: Checks grammar and word arrangement.
- Semantic analysis: Checks whether the sentence has meaningful content.
- Discourse integration: Connects a sentence with preceding and succeeding sentences to maintain coherence.
- Pragmatic analysis: Interprets the speaker’s intended meaning using real-world context, such as understanding “pulling your leg” as joking.
2. Explain all six steps of text normalisation.
- Sentence segmentation divides the corpus into sentences.
- Tokenization divides each sentence into words, numbers and special characters.
- Stop words, unnecessary special characters and numbers are removed where appropriate.
- Text is converted to a common case, usually lowercase.
- Stemming removes affixes to produce a stem, which may not be a meaningful word.
- Lemmatization produces a meaningful base word or lemma.
3. Explain Bag of Words and its implementation steps.
Bag of Words is a feature-extraction model that represents text using a vocabulary and the frequency of each vocabulary word. First, collect and preprocess the corpus. Next, create a dictionary of unique words. Then count each vocabulary word in every document and create a document vector. Repeat for all documents. The resulting table can be used as numerical input for machine-learning algorithms. Word order is not represented.
4. Explain TFIDF and its applications.
TFIDF estimates the importance of a word in a document relative to a corpus. TF is the count of a word in one document. DF is the number of documents containing that word. IDF is N/DF. The textbook formula is TFIDF(W)=TF(W)×log10(IDF(W)). Words common to all documents receive a low or zero IDF weight, while words concentrated in fewer documents receive a higher weight. Applications include document classification, topic modelling, information retrieval and stop-word filtering.
E. Competency-based / case-based questions
Case 1: A school analyses 500 student feedback comments. It wants to know whether comments are positive, negative or neutral. Identify the NLP application and explain its value.
Application: Sentiment analysis. It classifies feedback by polarity—positive, negative or neutral. The school can identify common areas of satisfaction and concern and use the results to improve services. Human review may still be needed for sarcasm or ambiguous comments.
Case 2: A news website automatically places articles into Sports, Politics and Business. Which NLP application is used? Explain.
Application: Text classification. The system analyses an article and assigns it to one of the predefined categories. This makes news easier to organise and search.
Case 3: A search system finds the word “and” in almost every document but finds “photosynthesis” in only two documents. Which term is likely to have higher IDF, and why?
Answer: “Photosynthesis” is likely to have higher IDF because it appears in fewer documents. “And” appears in many documents, so N/DF is close to 1 and its logarithm is close to 0.
Case 4: A chatbot always responds using a fixed set of menu options. Another chatbot understands varied questions and uses AI to generate responses. Compare them.
The first is a script bot because it follows predefined rules and fixed paths. The second is a smart bot because it uses AI/NLP to handle more varied language and has broader functionality.
Case 5: A sentence is grammatically correct, but the phrase “hot ice cream” is unusual. Which stage examines this problem?
Answer: Semantic analysis. It examines the meaning and meaningfulness of words and phrases, not just grammatical structure.
F. Numerical practice
1. A corpus contains 20 documents. A term occurs in 5 documents and 3 times in Document A. Calculate its IDF and TFIDF in A using the textbook formula.
N=20, DF=5, TF=3.
IDF=20/5=4.
log10(4)≈0.602.
TFIDF=3×0.602=1.806.
2. A term occurs in all 8 documents and 4 times in one document. Calculate its IDF and TFIDF.
N=8, DF=8, TF=4. IDF=8/8=1. log10(1)=0. Therefore TFIDF=4×0=0.
Quick Revision Notes
Important definitions
| Term | Definition to learn |
|---|---|
| Natural language | A human language used for communication, such as English or French. |
| NLP | An AI sub-field that enables computers to analyse, understand and process human language. |
| Lexicon | The collection of words and phrases used in a language. |
| Corpus | A collection of written text from multiple documents. |
| Token | A word, number or special character treated as a separate unit. |
| Stop words | Frequent words that often contribute little to the topic being analysed. |
| Stemming | Removing affixes to produce a stem without checking whether it is a meaningful word. |
| Lemmatization | Reducing a word to a meaningful base form called a lemma. |
| Bag of Words | A model that represents text through unique vocabulary words and their frequencies. |
| TF | Number of times a term occurs in one document. |
| DF | Number of documents in which a term occurs. |
| IDF | Total number of documents divided by document frequency, as used in this textbook. |
| Sentiment analysis | Analysis that classifies textual opinion as positive, negative or neutral. |
Formula sheet
Where: N = total number of documents; DF(W) = number of documents containing word W; TF(W) = frequency of W in the selected document.
High-priority distinctions
| Compare | Difference |
|---|---|
| Syntax vs Semantics | Grammar/arrangement vs meaning. |
| Discourse vs Pragmatic | Connections between sentences vs intended meaning in real-world context. |
| Stemming vs Lemmatization | May produce a non-word vs produces a meaningful lemma. |
| Script bot vs Smart bot | Predefined script and limited functions vs AI-enabled flexibility and wider functions. |
| TF vs DF | Count in one document vs count of documents containing the word. |
| BoW vs TFIDF | Represents word counts vs weights terms by local frequency and corpus-wide rarity. |
- Learn the five NLP stages in the correct order.
- Practise all six text-normalisation steps.
- Know the examples “studies → studi” (stemming) and “studies → study” (lemmatization).
- Be able to build a vocabulary and document-vector table.
- Memorise the TFIDF formula and practise DF, IDF and logarithm calculations.
- Prepare examples of voice assistants, captions, translation, sentiment analysis, text classification and keyword extraction.
Source coverage and verification
These notes follow the order and content of the uploaded 29-page PDF, Unit 6: Natural Language Processing. The page-by-page coverage checklist below records the material incorporated.
| PDF page(s) | Content covered in these notes |
|---|---|
| 1 | Unit summary, objectives, outcomes, prerequisites and key concepts. |
| 2–3 | 6.1 Introduction, natural-language features, break/brake and right/write, context examples, computer language and importance of NLP. |
| 4–6 | NLP definition; applications; keyword extraction activity and Google Cloud Natural Language demonstration steps. |
| 7–10 | Five NLP stages, diagrams/sequence, examples, summary and Test Yourself questions. |
| 11–13 | 6.4 Chatbots, activity, named chatbot examples, script bot vs smart bot, Quiz Time. |
| 13–17 | 6.5 Text Processing, corpus, six text-normalisation steps, stop words, case conversion, stemming and lemmatization tables/examples. |
| 18–20 | Bag of Words definition, purpose, algorithm steps, Aman–Avni three-document worked example and document vectors. |
| 20–24 | TFIDF, stop/frequent/rare words, TF, DF, IDF, formula, worked values and applications. |
| 24–26 | 6.6 Code/no-code tools, sentiment analysis, customer service, Voice of the Customer and Orange walkthrough links. |
| 26–28 | All 12 Test Yourself MCQs and Assertion–Reason questions with answers and explanations. |
| 28–29 | All 10 Reflection Time questions, including normalisation and the four-document TFIDF numerical. |
Prepared as a learning resource from the supplied textbook PDF. Students should follow their teacher’s instructions if a classroom activity uses a particular stop-word list, software version or calculation convention.
TEXTBOOK SOLUTION
Step-by-step solved textbook exercises, derivations, and solutions.
Unit 6: Natural Language Processing (NLP)
Complete textbook back-exercise solutions · Test Yourself · Assertion–Reason · Reflection Time · Worked Numericals
About these solutions
This document answers the textbook exercise from the uploaded Unit 6: Natural Language Processing PDF, especially the end-of-unit questions on pages 26–29. Answers are written in simple English for Class 10 students. Long-answer questions are explained in sufficient detail, and numerical questions show the steps and formulas.
1. Test Yourself — Multiple-Choice Questions (Pages 26–28)
Explanation: Human languages contain ambiguity, different meanings, context, grammar, slang and changing expressions. The same word can have different meanings in different situations. Computers need NLP techniques to process these complexities.
Explanation: Voice assistants such as Google Assistant, Alexa and Siri process spoken commands, identify the user's intention and respond or perform a requested task.
Explanation: Text normalisation cleans and standardises text through steps such as tokenisation, removing unnecessary punctuation and stop words, converting text to lowercase, stemming and lemmatisation. Document summarisation is a separate NLP task.
Explanation: Tokenisation divides text into smaller units called tokens. A token may be a word, number or special character. For example, “I love AI!” can be tokenised as I, love, AI, !.
Explanation: Stemming removes word endings using simple rules and may produce a word fragment such as studi from studies. Lemmatisation uses vocabulary and grammatical information to produce a meaningful base word, such as study.
Explanation: Bag of Words converts text into a numerical representation by creating a vocabulary of unique words and recording how frequently each word occurs in each document. Machine-learning algorithms can then use these numerical features.
Explanation: Stop words are commonly occurring words that usually add little topic-specific information, such as “the”, “is”, “and” and “of”. They are often removed so that the system can focus on more meaningful words. The exact stop-word list depends on the task.
Explanation: Rare or valuable words occur in fewer documents but may describe a document's specific subject. They can therefore receive a higher IDF value and contribute strongly to the TFIDF score.
Explanation: Each row of a document-vector table represents one document, and each column represents a vocabulary word. The value in a cell tells how many times that word occurs in that particular document.
Explanation: TFIDF assigns a numerical importance score to a word in a document. A word receives a higher score when it occurs frequently in a particular document but appears in relatively few documents across the corpus.
Options: A) Both true and Reason correctly explains Assertion. B) Assertion true, Reason false. C) Both true, but Reason does not correctly explain Assertion. D) Assertion false, Reason true.
Explanation: Pragmatic analysis studies the intended meaning of a sentence in its real-life context. It considers the speaker's purpose and the situation in which the sentence is used. The Reason explains why pragmatic analysis goes beyond the literal meaning of individual words.
Options: A) Both true and Reason correctly explains Assertion. B) Assertion true, Reason false. C) Both true, but Reason does not correctly explain Assertion. D) Assertion false, Reason true.
Explanation: Converting text to lowercase makes words such as “Hello”, “HELLO” and “hello” appear in the same form. This reduces unnecessary differences in the vocabulary and makes text analysis more consistent. It is a common preprocessing step, although case may need to be preserved in tasks where capitalisation carries useful information.
2. Reflection Time — Descriptive Questions (Pages 28–29)
Natural languages are the languages that human beings use to communicate with one another, such as English, Hindi, Gujarati, French, Spanish and Japanese. Some important features are:
- They follow rules: Natural languages follow rules of syntax (sentence structure), lexicon (vocabulary) and semantics (meaning).
- They are redundant: The same information can often be communicated in different ways. For example, “Please close the door” and “Could you shut the door?” communicate a similar message.
- They change over time: New words, expressions and meanings are added as society, technology and culture change.
- They depend on context: A word or sentence can have different meanings depending on the situation in which it is used.
- They can be ambiguous: One word or sentence may have more than one possible meaning.
Conclusion: Natural languages are flexible and context-dependent. These features make human communication rich, but they also make it challenging for computers to understand language correctly.
Natural Language Processing (NLP) is a sub-field of Artificial Intelligence that enables computers to analyse, understand and process human languages to obtain meaningful information.
NLP is significant because computers mainly process information in digital and numerical forms, whereas humans communicate using spoken and written languages. NLP helps bridge this gap and makes communication between humans and computer systems easier.
Importance of NLP:
- It allows computers to understand human text and speech.
- It makes voice assistants such as Google Assistant, Alexa and Siri possible.
- It supports language translation between different languages.
- It helps generate captions and convert speech into text.
- It analyses customer reviews and feedback through sentiment analysis.
- It helps classify documents, extract keywords and find useful information.
- It supports chatbots that answer questions and help users.
Conclusion: NLP makes human-computer communication more natural and useful. It is widely used in education, business, healthcare, customer service and many other fields.
Lexical analysis is the first stage of Natural Language Processing. It deals with identifying and analysing the structure of the input text by breaking a large piece of text into smaller units such as paragraphs, sentences and words.
The word “lexicon” refers to the collection of words and phrases used in a language. During lexical analysis, the system identifies the words or tokens present in the input so that later stages can process them.
Example: The sentence “Students are learning NLP” can be divided into the tokens Students, are, learning and NLP.
Conclusion: Lexical analysis organises the input text into smaller language units and prepares it for further NLP stages such as syntactic and semantic analysis.
A chatbot is a computer program designed to simulate a conversation with a human through text messages, voice commands or both. It uses predefined rules, artificial intelligence and, in many cases, Natural Language Processing to understand a user's message and provide a suitable response.
Uses of chatbots:
- Answer frequently asked questions.
- Provide customer support and troubleshoot common problems.
- Help users find products or services on e-commerce websites.
- Generate sales leads and guide customers.
- Provide information and assistance at any time.
Types of chatbots:
- Script-bot: A traditional chatbot that follows predefined rules, scripts and decision paths. It generally responds to specific keywords or selected options.
- Smart-bot: An AI-powered chatbot that uses NLP and machine-learning techniques to understand messages more flexibly and generate or select relevant responses.
Examples: Website customer-support chatbots, banking support bots and AI conversational assistants.
Conclusion: Chatbots make communication between users and organisations faster and more convenient by providing automated assistance.
Bag of Words (BoW) is a text-representation technique in NLP that converts documents into numerical features. It creates a vocabulary containing all unique words in a collection of documents and records the frequency of each vocabulary word in each document.
It is called a “bag” because the order and grammar of the words are ignored. The model focuses mainly on which words occur and how many times they occur.
Example:
- Document 1: “AI is useful”
- Document 2: “AI is powerful”
Vocabulary: AI, is, useful, powerful.
| Document | AI | is | useful | powerful |
|---|---|---|---|---|
| Document 1 | 1 | 1 | 1 | 0 |
| Document 2 | 1 | 1 | 0 | 1 |
Uses: The numerical vectors can be used by machine-learning algorithms for tasks such as text classification and document analysis.
NLP is used in many applications that help computers understand, interpret and respond to human language. Two practical uses are:
1. Voice Assistants: Voice assistants such as Google Assistant, Amazon Alexa and Apple Siri use NLP to understand spoken commands. For example, when a user says, “Set an alarm for 6 AM”, the assistant processes the sentence, identifies the user's intention and sets the alarm.
2. Language Translation: NLP is used by translation systems such as Google Translate to convert text or speech from one language into another. It helps people who speak different languages communicate and understand information.
Other examples: Automatic captions convert speech into text, sentiment analysis identifies positive or negative opinions, and chatbots answer customer questions.
Conclusion: NLP reduces language barriers and makes digital services easier to use in everyday life.
Stemming and lemmatisation are text-normalisation techniques used to reduce related words to a common base form. They help reduce the number of different word forms that a computer needs to process.
1. Stemming: Stemming removes prefixes or suffixes (affixes) from a word using simple rules. It may produce a word that is not a proper dictionary word.
Examples:
| Original word | Affix removed | Stem |
|---|---|---|
| healed | -ed | heal |
| healing | -ing | heal |
| healer | -er | heal |
| studies | -es | studi |
Notice that “studi” is not the correct dictionary word. Stemming may produce such fragments because it mainly removes affixes.
2. Lemmatisation: Lemmatisation converts a word into its meaningful dictionary base form, known as a lemma. It uses vocabulary and grammatical information to select the correct base word. It is generally more accurate but can take more processing time than stemming.
| Original word | Lemma |
|---|---|
| healed | heal |
| healing | heal |
| healer | heal |
| studies | study |
| studying | study |
Difference: Stemming removes word endings mechanically and may create an incomplete word, whereas lemmatisation finds a meaningful dictionary form by considering the word and its grammatical use.
TFIDF stands for Term Frequency–Inverse Document Frequency. It assigns an importance score to a word by considering how often it occurs in a particular document and how common it is across the entire collection of documents.
Four applications of TFIDF are:
- Document Classification: TFIDF converts documents into numerical features. A machine-learning model can use these features to classify documents into categories such as sports, politics, education or business.
- Topic Modelling: TFIDF helps identify important words in documents. These words can provide clues about the main topics discussed in a collection of documents.
- Information Retrieval System: Search systems can use TFIDF to identify documents containing important query terms and rank relevant documents. Words that are more informative can receive higher weights.
- Stop-Word Filtering: TFIDF can help identify words that occur in nearly all documents and have little distinguishing value. Such words can be considered for filtering, depending on the task.
Conclusion: TFIDF helps computers identify important words and represent documents numerically, making it useful in search, classification and text analysis.
Document 1: Akash and Ajay are best friends.
Document 2: Akash likes to play football but Ajay prefers to play online games.
We will apply the textbook's normalisation steps in order. For this worked answer, common stop words such as “and”, “are”, “to” and “but” are removed; punctuation is removed; text is converted to lowercase; and words are lemmatised to meaningful base forms.
Step 1: Sentence segmentation
The two sentences are already provided separately, so they form two documents.
Step 2: Tokenisation
Each sentence is divided into individual word tokens.
Document 2: [Akash, likes, to, play, football, but, Ajay, prefers, to, play, online, games, .]
Step 3: Remove stop words and punctuation
Remove “and”, “are”, “to”, “but” and the full stop. These words and punctuation marks are not needed for this example's content representation.
Document 2: [Akash, likes, play, football, Ajay, prefers, play, online, games]
Step 4: Convert all words to lowercase
Document 2: [akash, likes, play, football, ajay, prefers, play, online, games]
Step 5: Apply lemmatisation
Convert inflected words into meaningful base forms. For example, “likes” becomes “like”, “friends” becomes “friend”, “prefers” becomes “prefer” and “games” becomes “game”. The word “play” is already in its base form.
Document 2: [akash, like, play, football, ajay, prefer, play, online, game]
Document 1:
[akash, ajay, best, friend]Document 2:
[akash, like, play, football, ajay, prefer, play, online, game]Note: A stop-word list and lemmatisation output can vary by tool and language model. The important point is to apply the same rules consistently to all documents.
3. Reflection Time Q10 — Step-by-Step TFIDF Numerical (Page 29)
Document 1: Johny Johny Yes Papa
Document 2: Eating sugar? No Papa
Document 3: Telling lies? No Papa
Document 4: Open your mouth, Ha! Ha! Ha!
We will follow the TFIDF method explained in the textbook. First, remove punctuation and common stop words (“yes”, “no”, “your”), and convert the remaining words to lowercase. Repeated words are retained because their frequency matters.
Step 1: Text preprocessing
| Document | Original text | After preprocessing |
|---|---|---|
| D1 | Johny Johny Yes Papa | johny, johny, papa |
| D2 | Eating sugar? No Papa | eating, sugar, papa |
| D3 | Telling lies? No Papa | telling, lies, papa |
| D4 | Open your mouth, Ha! Ha! Ha! | open, mouth, ha, ha, ha |
Step 2: Create the vocabulary
List each unique word only once across all four documents.
Step 3: Calculate Term Frequency (TF)
Term Frequency is the number of times a word appears in a particular document.
| Document | johny | papa | eating | sugar | telling | lies | open | mouth | ha |
|---|---|---|---|---|---|---|---|---|---|
| D1 | 2 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| D2 | 0 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 |
| D3 | 0 | 1 | 0 | 0 | 1 | 1 | 0 | 0 | 0 |
| D4 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 3 |
Step 4: Calculate Document Frequency (DF)
Document Frequency tells us the number of different documents in which a word occurs. Count a document only once, even if the word is repeated in it.
| Word | Documents containing the word | DF |
|---|---|---|
| johny | D1 | 1 |
| papa | D1, D2, D3 | 3 |
| eating | D2 | 1 |
| sugar | D2 | 1 |
| telling | D3 | 1 |
| lies | D3 | 1 |
| open | D4 | 1 |
| mouth | D4 | 1 |
| ha | D4 | 1 |
Step 5: Calculate Inverse Document Frequency (IDF)
Total number of documents N = 4.
IDF = log10(4 / DF)
For “johny”: DF = 1, therefore IDF = log10(4/1) = log10(4) = 0.6021.
For “papa”: DF = 3, therefore IDF = log10(4/3) = log10(1.3333) = 0.1249.
Every other vocabulary word occurs in one document, so its IDF is also log10(4) = 0.6021.
| Word | DF | IDF = log10(4/DF) |
|---|---|---|
| johny | 1 | 0.6021 |
| papa | 3 | 0.1249 |
| eating | 1 | 0.6021 |
| sugar | 1 | 0.6021 |
| telling | 1 | 0.6021 |
| lies | 1 | 0.6021 |
| open | 1 | 0.6021 |
| mouth | 1 | 0.6021 |
| ha | 1 | 0.6021 |
Step 6: Calculate TFIDF = TF × IDF
Multiply each word's TF in a document by that word's IDF. Example: In D1, the word “johny” has TF = 2 and IDF = 0.6021.
TFIDF(papa, D1) = 1 × 0.1249 = 0.1249
Final TFIDF table (values rounded to four decimal places):
| Document | johny | papa | eating | sugar | telling | lies | open | mouth | ha |
|---|---|---|---|---|---|---|---|---|---|
| D1 | 1.2042 | 0.1249 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| D2 | 0 | 0.1249 | 0.6021 | 0.6021 | 0 | 0 | 0 | 0 | 0 |
| D3 | 0 | 0.1249 | 0 | 0 | 0.6021 | 0.6021 | 0 | 0 | 0 |
| D4 | 0 | 0 | 0 | 0 | 0 | 0 | 0.6021 | 0.6021 | 1.8063 |
4. Quick Revision — Important NLP Terms
| Term | Easy meaning |
|---|---|
| Natural Language | A language used by humans to communicate, such as English or Hindi. |
| NLP | A branch of AI that helps computers process and understand human language. |
| Lexical Analysis | Breaking input text into language units such as words and tokens. |
| Syntactic Analysis | Checking grammar and relationships among words. |
| Semantic Analysis | Checking the meaning of words and sentences. |
| Discourse Integration | Connecting the meaning of a sentence with preceding and following sentences. |
| Pragmatic Analysis | Understanding intended meaning in a real-world context. |
| Corpus | A collection of text documents used for analysis. |
| Token | A word, number or special character treated as a separate unit. |
| Stop Words | Common words that often contribute little topic-specific information. |
| Stemming | Removing affixes to produce a stem, which may not be a complete word. |
| Lemmatisation | Converting a word into its meaningful dictionary base form. |
| Bag of Words | Representing documents by vocabulary words and their frequencies. |
| TF | Number of times a term occurs in one document. |
| DF | Number of documents containing a term. |
| IDF | Logarithmic measure that gives more weight to terms found in fewer documents. |
| TFIDF | Term Frequency multiplied by Inverse Document Frequency. |
| Sentiment Analysis | Identifying whether text expresses a positive, negative or neutral opinion. |
Stages of NLP — correct order
- Lexical Analysis
- Syntactic Analysis / Parsing
- Semantic Analysis
- Discourse Integration
- Pragmatic Analysis
Text Normalisation — typical order
- Sentence Segmentation
- Tokenisation
- Removal of stop words, unnecessary special characters and numbers (as appropriate)
- Conversion to a common case, usually lowercase
- Stemming or lemmatisation
- Numerical representation using methods such as Bag of Words and TFIDF
5. Exercise Coverage
This document covers the end-of-unit exercise in the supplied 29-page PDF:
- Pages 26–28: all 10 MCQs and both Assertion–Reason questions.
- Pages 28–29: all 10 Reflection Time questions.
- Q9: complete text-normalisation example for both documents.
- Q10: full TFIDF calculation for the four-document “Johny Johny” corpus.
Short “Test Yourself” activities and informal discussion prompts earlier in the chapter are classroom activities rather than the end-of-unit back exercise. The solutions above focus on the complete final exercise and provide supporting revision material.
IMPORTANT QUESTION
High-yield board questions, previous year questions (PYQs), and model answer keys.
Important Questions Being Compiled
Board blueprint and previous years' exam questions for this chapter will be live soon.