Skip to content
Home » Natural language processing

Natural language processing

Natural Language Processing (NLP)

1. Introduction to NLP

Natural Language Processing (NLP) is a branch of Artificial Intelligence that enables computers to understand, process, interpret and generate human language.

Human languages such as English, Hindi and Punjabi are called natural languages because they have developed naturally through human communication.

Exam Definition

Natural Language Processing is a branch of Artificial Intelligence that deals with the interaction between computers and humans using natural language. It enables computers to analyze, understand, interpret and generate human language.

Examples of NLP

  • ChatGPT and AI chatbots
  • Google Search
  • Google Translate
  • Voice assistants such as Siri and Alexa
  • Spam detection
  • Sentiment analysis
  • Question-answering systems
  • Speech-to-text systems
  • Text summarization
  • Grammar checking

2. Major Stages of Natural Language Processing

For your syllabus, the four important concepts are:

  1. Grammars
  2. Parsing
  3. Semantic Analysis
  4. Pragmatics

A useful overall flow is:

                 NATURAL LANGUAGE TEXT
                         |
                         ↓
                   +-------------+
                   |  Grammar    |
                   +-------------+
                         |
                         ↓
                   +-------------+
                   |   Parsing   |
                   +-------------+
                         |
                         ↓
                   +-------------+
                   |  Semantic   |
                   |   Analysis  |
                   +-------------+
                         |
                         ↓
                   +-------------+
                   |  Pragmatics |
                   +-------------+
                         |
                         ↓
                 UNDERSTANDING / MEANING

These stages can be understood through the sentence:

“Ravi opened the door.”

  • Grammar: Is the sentence structurally valid?
  • Parsing: What is the relationship between Ravi, opened and door?
  • Semantic analysis: What does the sentence mean?
  • Pragmatics: Why did Ravi open the door? What does the sentence mean in the particular context?

3. Grammars in NLP

3.1 What is Grammar?

A grammar is a set of rules that describes how words can be combined to form valid sentences in a language.

In NLP, grammar provides the structural rules required for a computer to analyze sentences.

For example:

The boy plays cricket.

A simple grammar might say:

Sentence → Noun Phrase + Verb Phrase

Noun Phrase → Determiner + Noun

Verb Phrase → Verb + Noun Phrase

Therefore:

Sentence
   |
   +-------------------+
   |                   |
 Noun Phrase       Verb Phrase
   |                   |
   |              +----+-----+
   |              |          |
  The boy       plays      cricket

4. Components of Grammar

A grammar generally contains four major components:

Grammar
   |
   +---- Terminals
   |
   +---- Non-terminals
   |
   +---- Production Rules
   |
   +---- Start Symbol

4.1 Terminals

Terminals are the actual words or tokens appearing in a sentence.

Example:

the
boy
plays
cricket

They cannot normally be further expanded by grammar rules.


4.2 Non-Terminals

Non-terminals represent grammatical categories.

Examples:

S  = Sentence
NP = Noun Phrase
VP = Verb Phrase
N  = Noun
V  = Verb
Det = Determiner

4.3 Production Rules

Production rules describe how one grammatical component can be expanded.

Example:

S  → NP VP
NP → Det N
VP → V NP

Additional rules:

Det → the
N   → boy
N   → cricket
V   → plays

4.4 Start Symbol

The start symbol represents the complete sentence.

Usually:

S → Sentence

or simply:

S

5. Context-Free Grammar (CFG)

One of the most important grammar models in classical NLP is the Context-Free Grammar (CFG).

Definition

A Context-Free Grammar is a formal grammar in which each production rule has a single non-terminal symbol on the left-hand side. CFGs are widely used for representing the syntactic structure of natural-language sentences.

Example:

S  → NP VP
NP → Det N
VP → V NP
Det → the
N → boy
N → cricket
V → plays

Using these rules:

S
→ NP VP
→ Det N VP
→ the boy VP
→ the boy V NP
→ the boy plays Det N
→ the boy plays the cricket

Thus:

The boy plays the cricket.

is generated by the grammar.


6. Grammar and NLP

Grammar helps an NLP system answer questions such as:

  • Is this sentence grammatically valid?
  • Which words form a noun phrase?
  • Which word is the main verb?
  • What is the subject?
  • What is the object?
  • How are words related?

For example:

The student reads a book.

Grammar identifies:

Subject → The student
Verb    → reads
Object  → a book

7. Types of Grammar Used in NLP

Some important grammar approaches include:

GrammarMain Idea
Regular GrammarSimple patterns and sequences
Context-Free GrammarPhrase/syntactic structure
Context-Sensitive GrammarMeaning/structure depends on context
Dependency GrammarRelationships between words
Transformational GrammarTransformations between structures
Probabilistic CFGGrammar rules have probabilities

For the classical AI/NLP syllabus, Context-Free Grammar and parsing are particularly important.


8. Parsing

8.1 What is Parsing?

Parsing is the process of analyzing a sentence according to a grammar to determine its syntactic structure.

Exam Definition

Parsing is the process of analyzing a natural-language sentence according to a grammar and constructing its syntactic structure, usually represented as a parse tree.

For example:

The boy eats an apple.

The parser determines:

Sentence
   |
   +---------------------+
   |                     |
  NP                     VP
   |                 +---+------+
   |                 |          |
  The boy           eats        NP
                               |
                            an apple

9. Parse Tree

A parse tree is a tree representation showing the grammatical structure of a sentence.

For:

The boy plays cricket.

A simplified parse tree is:

                  S
                /   \
              NP     VP
             / \     / \
           Det  N   V   NP
           |    |   |    |
          The  boy plays cricket

This tells us:

S
├── NP
│   ├── Det → The
│   └── N   → boy
│
└── VP
    ├── V   → plays
    └── NP  → cricket

10. Why Parsing is Important

Parsing helps an NLP system understand the syntactic relationships between words.

Consider:

The teacher praised the student.

Parsing identifies:

Subject → The teacher
Verb    → praised
Object  → the student

This becomes important when the computer needs to understand who performed an action and who received it.


11. Types of Parsing

There are two major approaches traditionally discussed in NLP:

11.1 Top-Down Parsing

Top-down parsing starts with the start symbol and tries to generate the input sentence.

S
↓
NP + VP
↓
Det + N + VP
↓
The + boy + VP
↓
The boy + V + NP
↓
The boy plays cricket

Direction

Grammar
   ↓
S
   ↓
Sentence

It starts from the overall sentence structure and works toward individual words.


11.2 Bottom-Up Parsing

Bottom-up parsing starts with the words of the sentence and combines them into larger grammatical structures.

The   boy   plays   cricket
 |     |      |       |
 ↓     ↓      ↓       ↓
Det    N      V       N
  \    /              |
   NP                 NP
       \             /
             VP
              |
              S

Direction

Words
  ↓
Phrases
  ↓
Sentence

12. Top-Down vs Bottom-Up Parsing

FeatureTop-DownBottom-Up
Starting pointStart symbolInput words
DirectionGeneral → specificSpecific → general
Starts withSTokens
GoalGenerate sentenceBuild sentence structure
Main ideaPredict structureCombine observed words

13. Ambiguity in Parsing

Natural language is often ambiguous.

Consider:

I saw the man with a telescope.

This can have two meanings.

Meaning 1

I used the telescope to see the man.

I → saw → man
       \
      telescope

Meaning 2

The man had a telescope.

I → saw → [man with telescope]

Therefore, the same sentence can have multiple parse trees.

This is called syntactic ambiguity.


14. Types of Ambiguity in NLP

Ambiguity is a major NLP challenge.

14.1 Lexical Ambiguity

A word has multiple meanings.

Example:

I went to the bank.

Bank could mean:

  • financial institution
  • river bank

14.2 Syntactic Ambiguity

A sentence can have more than one grammatical structure.

Example:

I saw the man with a telescope.


14.3 Semantic Ambiguity

The grammatical structure is clear, but the meaning can have multiple interpretations.


14.4 Pragmatic Ambiguity

The intended meaning depends heavily on context.

Example:

Can you open the window?

Literally, it asks whether the person has the ability to open the window.

In normal conversation, it is usually a request to open it.


15. Semantic Analysis

After determining the syntactic structure, an NLP system needs to understand meaning.

This is the role of semantic analysis.

Definition

Semantic analysis is the process of determining the meaning of words, phrases and sentences and identifying the relationships between the concepts expressed in them.

Example:

Ravi bought a laptop.

Semantic analysis identifies:

Person  → Ravi
Action  → bought
Object  → laptop

A more structured representation could be:

BUY
 |
 +---- Buyer  → Ravi
 |
 +---- Object → Laptop

16. Syntax vs Semantics

This is a very important distinction.

Syntax

Deals with:

How is the sentence structured?

Semantics

Deals with:

What does the sentence mean?

Example:

The cat chased the mouse.

Syntax:

Subject → cat
Verb    → chased
Object  → mouse

Semantics:

CAT
  |
CHASES
  |
MOUSE

Meaning:

The cat performed the chasing action and the mouse was the entity being chased.


17. Semantic Analysis Tasks

Semantic analysis may involve several tasks.

17.1 Word Sense Disambiguation

Determining the correct meaning of a word from context.

Example:

I deposited money in the bank.

Here:

bank = financial institution

Whereas:

We sat near the bank of the river.

Here:

bank = land beside a river

17.2 Semantic Role Labelling

Identifying the role played by each entity.

Example:

Ravi bought a laptop from Amazon.

Possible semantic roles:

EntityRole
RaviBuyer
LaptopObject
AmazonSeller/Source

17.3 Named Entity Recognition

Identifying entities such as:

  • Person
  • Organization
  • Location
  • Date
  • Money
  • Product

Example:

Balvinder visited Delhi on Monday.

Balvinder → PERSON
Delhi     → LOCATION
Monday    → DATE

17.4 Semantic Similarity

Determining how similar two sentences or words are.

Example:

The car is fast.

and

The automobile is quick.

These sentences have similar meanings.


17.5 Semantic Representation

The meaning of a sentence can be represented using:

  • Predicate logic
  • Semantic networks
  • Frames
  • Knowledge graphs
  • Logical representations

Example:

Ravi is a student.

Predicate representation:\[ Student(Ravi) \]

Example:

Ravi likes AI.

\[ Likes(Ravi,AI) \]

This creates a bridge between NLP and Knowledge Representation.


18. Semantic Analysis Example

Consider:

The boy opened the door.

Step 1: Identify entities

boy → Person
door → Object

Step 2: Identify action

opened → Open

Step 3: Identify semantic roles

Agent  → boy
Action → open
Object → door

Representation:\[ Open(Boy,Door) \]

or:

OPEN
 |
 +---- Agent  → Boy
 |
 +---- Object → Door

19. Pragmatics

19.1 What is Pragmatics?

Pragmatics deals with the intended meaning of language in a particular context.

It goes beyond the literal meaning of words.

Exam Definition

Pragmatics is the study of how context, speaker intention, situation and background knowledge influence the interpretation of language. In NLP, pragmatic analysis attempts to determine what the speaker actually intends to communicate.


20. Example of Pragmatics

Consider:

“Can you pass the salt?”

Literal interpretation

The speaker is asking:

Are you physically capable of passing the salt?

Intended interpretation

The speaker is actually requesting:

Please pass the salt.

Understanding this difference is pragmatic understanding.


21. Another Example

Person A:

Is the door open?

Person B:

It’s very cold outside.

Literally, Person B did not answer:

Yes / No.

But pragmatically, Person B may be communicating:

The door should probably be closed.

The NLP system needs context and common-sense knowledge to interpret this.


22. Important Concepts in Pragmatics

22.1 Context

Meaning depends on the situation.

Example:

It’s hot here.

Possible meanings:

  • Statement about temperature.
  • Request to switch on the fan.
  • Request to open a window.

22.2 Speaker Intention

What does the speaker actually want to communicate?

Example:

Could you send me the report?

The intention is generally a request, not a question about ability.


22.3 Reference Resolution

Determining what a pronoun or expression refers to.

Example:

Ravi met Aman. He gave him a book.

Who is “he”?

Who is “him”?

An NLP system must use context to resolve the references.


22.4 Deixis

Words whose interpretation depends on context.

Examples:

I
you
here
there
today
tomorrow
this
that

Example:

I will meet you here tomorrow.

To understand the complete meaning, the system needs:

  • Who is “I”?
  • Who is “you”?
  • Where is “here”?
  • What date is “tomorrow”?

22.5 Implicature

Sometimes people communicate something without directly saying it.

Example:

A:

Are you coming to the party?

B:

I have an exam tomorrow.

B did not explicitly say:

“No.”

But the implied meaning may be:

I probably won’t come.

This is pragmatic interpretation.


23. Syntax, Semantics and Pragmatics

These three concepts are extremely important for exams.

ConceptMain QuestionFocus
SyntaxHow is it structured?Grammar/structure
SemanticsWhat does it mean?Literal meaning
PragmaticsWhat does the speaker intend in context?Context/intention

Example:

“Can you open the window?”

Syntax

Can + Subject + Verb + Object?

It is grammatically an interrogative sentence.

Semantics

It asks whether the listener has the ability to open the window.

Pragmatics

It is normally interpreted as:

Please open the window.


24. Complete NLP Analysis Example

Consider:

“Ravi didn’t attend the class because he was sick.”

Step 1 — Grammar

Identify structure:

Main Clause
     |
Ravi didn't attend the class

      +

Reason Clause
     |
he was sick

Step 2 — Parsing

Identify:

Subject → Ravi
Verb    → attended
Object  → class
Reason  → he was sick

Step 3 — Semantic Analysis

Determine:

Person → Ravi
Event  → Not Attend
Location/Context → Class
Cause → Sick

Logical representation:

Sick(Ravi)
NOT Attend(Ravi, Class)

Step 4 — Pragmatic Analysis

The system needs to understand:

"he" → Ravi

and understand that:

Ravi’s illness is being presented as the reason for his absence.

Thus:

Text
 ↓
Grammar
 ↓
Parsing
 ↓
Semantic Meaning
 ↓
Context + Intention
 ↓
Complete Understanding

25. Relationship Between Grammar, Parsing, Semantics and Pragmatics

A very important diagram for your students:

                  NATURAL LANGUAGE
                         |
                         ↓
                    GRAMMARS
              "What structures are valid?"
                         |
                         ↓
                     PARSING
              "What is the structure?"
                         |
                         ↓
                SEMANTIC ANALYSIS
                 "What does it mean?"
                         |
                         ↓
                    PRAGMATICS
          "What does it mean in this context?"
                         |
                         ↓
                LANGUAGE UNDERSTANDING

Think of it as four levels:

GRAMMAR    → Rules
PARSING    → Structure
SEMANTICS  → Meaning
PRAGMATICS → Context + Intention

Easy Memory Trick

G → P → S → P

Grammar → Parsing → Semantics → Pragmatics

Or remember:

Rules → Structure → Meaning → Context


26. Comparison: Grammar vs Parsing vs Semantics vs Pragmatics

FeatureGrammarParsingSemantic AnalysisPragmatics
Main concernRulesStructureMeaningContext
QuestionIs it grammatically valid?How is it structured?What does it mean?What is intended?
InputWords/rulesSentenceParsed structureMeaning + context
OutputValid structuresParse treeSemantic representationIntended interpretation
ExampleS → NP VPSubject + Verb + ObjectWho did what?Why/what does speaker intend?

27. Why These Concepts Matter in AI

These four concepts form an important foundation for intelligent language systems.

                  NLP
                   |
       +-----------+-----------+
       |           |           |
    Syntax      Semantics   Pragmatics
       |           |           |
    Grammar      Meaning     Context
       \           |           /
        \          |          /
         +---------+---------+
                   |
            Language AI
                   |
       +-----------+------------+
       |           |            |
    Chatbots    QA Systems   Translation
       |           |            |
   Voice AI     Search       Summarization

Modern systems such as LLM-based applications perform these tasks using much more sophisticated statistical and neural methods, but the classical NLP concepts remain fundamental for understanding how language processing works.


28. NLP and Your Earlier AI Topics

This topic connects directly with the earlier units of your syllabus.

NLP + Knowledge Representation

Sentence:

Ravi is a student.

Can be represented as:\[ Student(Ravi) \]

NLP + First-Order Logic

Every student studies AI.

\[ ∀x(Student(x) \rightarrow Studies(x,AI)) \]

NLP + Question Answering

Question:

Who is a student?

The system can use its knowledge base to find:

Student(Ravi)

and answer:

Ravi is a student.

Thus:

NLP
 ↓
Language Understanding
 ↓
Knowledge Representation
 ↓
Inference
 ↓
Answer

This is why NLP, Knowledge Representation and Question-Answering are closely connected in AI.


29. Real-World Applications

1. Chatbots

Understand user questions and generate responses.

2. Search Engines

Understand the meaning and intent behind search queries.

3. Machine Translation

Translate one natural language into another.

4. Voice Assistants

Convert speech into language and understand user commands.

5. Sentiment Analysis

Determine whether text expresses positive, negative or neutral sentiment.

6. Question-Answering Systems

Understand questions and retrieve or generate answers.

7. Information Extraction

Extract people, organizations, dates, locations, products, etc.

8. Text Summarization

Understand important information and produce a shorter version.

9. Customer Support

Understand customer queries and provide appropriate responses.

10. Generative AI

Modern language models generate text based on learned patterns, context and representations of language.


30. Important Exam Questions

Short Questions

  1. Define Natural Language Processing.
  2. What is grammar in NLP?
  3. What is Context-Free Grammar?
  4. What is parsing?
  5. What is a parse tree?
  6. Differentiate top-down and bottom-up parsing.
  7. What is semantic analysis?
  8. What is word sense disambiguation?
  9. What is pragmatics?
  10. What is ambiguity in NLP?

Long Questions

  1. Explain Natural Language Processing and its major stages.
  2. Explain grammar and Context-Free Grammar with an example.
  3. Explain parsing and different parsing techniques.
  4. Explain semantic analysis in NLP.
  5. Explain pragmatics with suitable examples.
  6. Differentiate syntax, semantics and pragmatics.
  7. Explain the role of grammar, parsing, semantics and pragmatics in NLP.

31. 5-Mark Exam Answer

Natural Language Processing (NLP) is a branch of Artificial Intelligence that enables computers to process, understand and generate human language. Important stages of NLP include grammar, parsing, semantic analysis and pragmatics. Grammar defines rules for constructing valid sentences. Parsing analyzes a sentence according to these rules and produces its syntactic structure, often using a parse tree. Semantic analysis determines the meaning of words and sentences and identifies relationships between entities. Pragmatics determines the intended meaning of a sentence by considering context, speaker intention and background knowledge. For example, in the sentence “Can you open the window?”, syntax identifies its grammatical structure, semantics gives the literal meaning of ability, while pragmatics interprets it as a request to open the window. These techniques form the foundation of chatbots, question-answering systems, machine translation, search engines and other AI applications.

Quick Revision

NLP
 |
 +-- Grammar       → Rules
 |
 +-- Parsing       → Structure
 |
 +-- Semantics     → Meaning
 |
 +-- Pragmatics    → Context & Intention

One-line memory:

Grammar tells what is allowed, Parsing tells how it is structured, Semantics tells what it means, and Pragmatics tells what the speaker actually intends.