Natural Language Processing – Computational Linguistics Pipeline

B.Tech Computer Science and Engineering

Natural Language Processing

Computational Linguistics Pipeline

Learn how computers process human language through lexical, syntactic, semantic, discourse and pragmatic analysis. Progress from foundational concepts to Python implementation using spaCy.

📘 Course: NLP 🎓 B.Tech CSE ⏱ Estimated time: 90–120 minutes 💻 Python + spaCy

Learning objectives

By the end of this lesson, students should be able to:

  • Explain the five major levels of language analysis.
  • Differentiate lexical, morphological, syntactic and semantic analysis.
  • Understand discourse integration and pragmatic interpretation.
  • Explain tokenization, lemmatization and POS tagging.
  • Interpret dependency labels such as nsubj, obj and amod.
  • Write basic NLP programs using Python and spaCy.

Learning journey

LEVEL 1: REMEMBER → LEVEL 2: UNDERSTAND → LEVEL 3: APPLY → ANSWER KEY
LEVEL 1 · REMEMBER

What should I know?

Build a strong foundation by understanding the important terms and definitions used in computational linguistics.

1. Introduction to NLP

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

Humans communicate using languages such as English, Telugu and Hindi. Computers process information through numerical representations and computational operations. NLP provides techniques that help computers work with human language data.

Computational linguistics: The interdisciplinary study of human language using computational methods. It combines linguistics, computer science, mathematics and artificial intelligence to model and process language.
Important distinction: Machine learning can process text represented as features, tokens, vectors or embeddings. NLP provides language-oriented methods for analysing and representing that text. Not every machine-learning task involving text requires a complete NLP pipeline.

2. Five levels of language analysis

1. Lexical and Morphological Analysis

Lexical analysis identifies and processes individual words or tokens in a text.

Morphological analysis studies the internal structure of words, including roots, prefixes, suffixes and grammatical forms.

Example: students → student + plural suffix -s.

Example: developing → base form develop.

Key terms: Tokenization · Root · Prefix · Suffix · Lemma

2. Syntactic Analysis

Syntactic analysis examines how words are arranged and related according to grammatical rules. It identifies sentence structure and grammatical relationships.

Example: Students develop applications.

  • Students = subject
  • develop = verb
  • applications = object
Key terms: Parsing · Grammar · Subject · Verb · Object

3. Semantic Analysis

Semantic analysis deals with the meaning of words, phrases and sentences. It examines relationships between words and whether an interpretation is meaningful.

Example:

  • Students develop applications. – A meaningful sentence in a typical context.
  • Students drink applications. – Grammatically possible, but semantically unusual in an ordinary context.
Key terms: Meaning · Word sense · Semantic roles

4. Discourse Integration

Discourse integration analyses how multiple sentences are connected. It uses context from earlier sentences to interpret later expressions.

Example:

Ravi purchased a laptop. He uses it for programming.

  • He → Ravi
  • it → laptop

Identifying these references is known as coreference resolution.

Key terms: Context · Coreference · Pronoun resolution

5. Pragmatic Analysis

Pragmatic analysis interprets the intended meaning of an expression using the situation, speaker intention and context.

Example: "Can you open the window?"

Literal meaning: A question about someone's ability. Intended meaning in an ordinary conversation: A polite request to open the window.

Key terms: Intention · Context · Implied meaning

3. Comparison of the five levels

LevelMain focusQuestion answered
Lexical / MorphologicalWords and their internal structureWhat are the words and their forms?
SyntacticGrammatical structureHow are the words related?
SemanticMeaningWhat does the sentence mean?
DiscourseConnections across sentencesHow are sentences connected?
PragmaticIntention and situationWhat does the speaker intend?

4. Important NLP terminology

TermMeaningExample
TokenizationSplitting text into tokens"I study NLP." → I, study, NLP, .
StemmingReducing words using rule-based truncationstudies → studi (possible stem)
LemmatizationFinding the dictionary base formstudents → student
POS taggingAssigning grammatical word categoriesstudent → NOUN
ParsingIdentifying grammatical structureSubject–verb–object
Coreference resolutionFinding expressions referring to the same entityRavi → He
Stemming vs. Lemmatization: Stemming may produce a truncated form that is not a valid dictionary word. Lemmatization uses linguistic information to identify a base form. In spaCy, token.lemma_ provides the lemma; it does not perform stemming.

5. Level 1 – Knowledge check

Attempt all five questions. Select one option and check your answers to receive feedback.

Q1. Which NLP level studies the internal structure of words?
Q2. Which level identifies subject–verb–object relationships?
Q3. Which level focuses on the meaning of a sentence?
Q4. Identifying that 'He' refers to Ravi is an example of:
Q5. Understanding 'Can you open the window?' as a polite request is:

Complete the five questions to finish Level 1.

LEVEL 2 · UNDERSTAND

How does it work?

Explore how human language moves through different stages of computational analysis.

1. NLP processing workflow

Consider the sentence:

"Students are developing intelligent applications."
Architecture note: This is a conceptual teaching sequence, not a mandatory fixed software architecture. Real NLP systems may combine, repeat or reorder these operations depending on the task. Modern neural models can learn several kinds of linguistic information jointly.

2. Stage-by-stage example

Stage 1: Lexical and morphological analysis

Input:

Students are developing intelligent applications.

Possible token sequence:

Students
are
developing
intelligent
applications
.

Possible lemma forms:

Students     → student
are          → be
developing   → develop
intelligent  → intelligent
applications → application

Tokenization identifies individual tokens. Lemmatization maps inflected words to their base forms.

Stage 2: Syntactic analysis

The system analyses the grammatical relationships among tokens.

Example: Students develop intelligent applications.

  • Students is the subject of develop.
  • develop is the main verb.
  • applications is the direct object of develop.
  • intelligent describes applications.

These relationships can be represented using a dependency parse.

Stage 3: Semantic analysis

The system examines what the sentence expresses, including word meanings and semantic relationships.

For example, in "Students develop applications", the verb develop describes an action associated with the object applications.

Semantic interpretation is more complex than simply checking whether a sentence sounds natural. Meaning can depend on domain knowledge, word sense and context.

Stage 4: Discourse integration

Consider two sentences:

Ravi purchased a laptop.
He uses it for programming.

A discourse system may identify:

  • He refers to Ravi.
  • it refers to laptop.

This requires information from more than one sentence.

Stage 5: Pragmatic analysis

Consider the sentence:

Can you open the window?

Depending on the situation, it may be interpreted as a polite request rather than a question about physical ability.

Pragmatics considers speaker intention, social context and conversational circumstances.

3. Understanding POS tagging

Part-of-Speech (POS) tagging assigns a grammatical category to each token.

POS tagMeaningExample
NOUNNoun: person, place, object, animal, concept or ideaStudents
VERBAction or statedevelop
ADJAdjective: describes a nounintelligent
ADVAdverb: modifies a verb, adjective or another adverbquickly
PRONPronounHe
DETDeterminerthe

4. Understanding dependency parsing

Dependency parsing identifies grammatical relationships between words. In spaCy, token.dep_ returns the dependency label associated with a token.

Dependency parsing: A syntactic analysis technique that represents sentence structure through directed relationships between words, typically connecting each dependent word to its syntactic head.

Three important dependency labels

nsubj

Nominal subject

Identifies the nominal subject associated with a verb.

Example: Students in "Students develop applications."

dobj / obj

Direct object

Identifies the direct object of a verb.

Example: applications in "Students develop applications."

amod

Adjectival modifier

Identifies an adjective modifying a noun.

Example: intelligent in "intelligent applications."

ROOT

Root of the dependency tree

Identifies the central syntactic head of the sentence.

Example: develop in "Students develop applications."

Dependency relationship – conceptual view

Students develop intelligent applications.

develop — ROOT (main verb)
Students → develop
nsubj
applications → develop
obj / dobj
intelligent → applications
amod

Conceptual relationships; the exact printed labels depend on the model and spaCy version.

Technical correction: Older English dependency schemes commonly use dobj for a direct object. Newer Universal Dependencies-style spaCy models commonly use obj. The grammatical purpose is the same. Always inspect the output of the installed model rather than assuming a particular label.

5. Python and spaCy introduction

spaCy is a Python library for practical NLP tasks such as tokenization, lemmatization, POS tagging and dependency parsing.

Install spaCy and its English model in your Python environment:

pip install spacy
python -m spacy download en_core_web_sm

Example 1: Tokenization

import spacy

nlp = spacy.load("en_core_web_sm")

text = "Students are learning Natural Language Processing."

doc = nlp(text)

for token in doc:
    print(token.text)

Explanation:

  • import spacy imports the library.
  • spacy.load(...) loads the English language model.
  • nlp(text) processes the text and creates a Doc object.
  • for token in doc iterates through tokens.
  • token.text prints the original token text.

Illustrative output:

Students
are
learning
Natural
Language
Processing
.

Example 2: Lemmatization

import spacy

nlp = spacy.load("en_core_web_sm")

text = "Students are developing applications."

doc = nlp(text)

for token in doc:
    print(token.text, "->", token.lemma_)

Explanation: token.lemma_ returns the lemma or dictionary base form assigned by the language model.

Typical output:

Students -> student
are -> be
developing -> develop
applications -> application
. -> .

Example 3: POS tagging

import spacy

nlp = spacy.load("en_core_web_sm")

text = "Students develop intelligent applications."

doc = nlp(text)

for token in doc:
    print(token.text, "->", token.pos_)

Illustrative output:

Students -> NOUN
develop -> VERB
intelligent -> ADJ
applications -> NOUN
. -> PUNCT

Example 4: Dependency parsing

import spacy

nlp = spacy.load("en_core_web_sm")

text = "Students develop intelligent applications."

doc = nlp(text)

for token in doc:
    print(token.text, "->", token.dep_)

Explanation:

  • token.text gives the word.
  • token.dep_ gives its grammatical dependency label.
  • token.head.text gives the syntactic head of the token.

Typical relationships include a nominal subject for Students, a root for develop, an adjectival modifier for intelligent and a direct-object relation for applications. Exact labels may vary by model.

Scope limitation: The examples above demonstrate tokenization, lemmatization, POS tagging and syntactic dependency parsing. Loading en_core_web_sm does not automatically perform full discourse integration, general semantic understanding or pragmatic reasoning. Those tasks require additional models, methods and context.

6. Real-world applications

ApplicationHow NLP helps
ChatbotsInterpreting user questions and conversational context.
Machine translationAnalysing and generating language across languages.
Sentiment analysisClassifying opinions expressed in text.
Information extractionIdentifying names, dates, entities and relationships.
Question answeringFinding information relevant to a question.
Document searchRepresenting and matching text with search queries.

7. Level 2 – Understanding check

Q1. What is the primary purpose of tokenization?
Q2. In spaCy, which attribute provides the lemma of a token?
Q3. What does POS tagging identify?
Q4. What does the dependency label nsubj generally represent?
Q5. In 'intelligent applications', what relationship does intelligent have to applications?

Complete the five questions to finish Level 2.

LEVEL 3 · APPLY

How can I implement it?

Practise the concepts through Python programs. Try each exercise before opening its solution.

EXERCISE 1 · BEGINNER

Tokenization using spaCy

Objective: Split a sentence into tokens and display each token.

Sample input:

Students are learning Natural Language Processing.

Expected output:

Students
are
learning
Natural
Language
Processing
.

Task: Complete the program using spaCy.

Show starter code
import spacy

nlp = spacy.load("en_core_web_sm")

text = "Students are learning Natural Language Processing."

doc = nlp(text)

for token in doc:
    # Print the original token
    print(__________)
Hint

Use the token attribute that returns the original text of each token.

View solution
import spacy

nlp = spacy.load("en_core_web_sm")

text = "Students are learning Natural Language Processing."

doc = nlp(text)

for token in doc:
    print(token.text)
EXERCISE 2 · BEGINNER TO DEVELOPING

Lemmatization

Objective: Display each token and its lemma.

Sample input:

Students are developing applications.

Expected illustrative output:

Students -> student
are -> be
developing -> develop
applications -> application
Starter code
import spacy

nlp = spacy.load("en_core_web_sm")

text = "Students are developing applications."
doc = nlp(text)

for token in doc:
    print(token.text, "->", __________)
Hint

Use the spaCy attribute that returns the dictionary base form of a word.

View solution
import spacy

nlp = spacy.load("en_core_web_sm")

text = "Students are developing applications."
doc = nlp(text)

for token in doc:
    print(token.text, "->", token.lemma_)
EXERCISE 3 · DEVELOPING

POS tagging

Objective: Identify the grammatical category of each token.

Sample input:

Students develop intelligent applications.

Expected illustrative output:

Students -> NOUN
develop -> VERB
intelligent -> ADJ
applications -> NOUN
Starter code
import spacy

nlp = spacy.load("en_core_web_sm")

text = "Students develop intelligent applications."
doc = nlp(text)

for token in doc:
    print(token.text, "->", __________)
Hint

Use the attribute that returns tags such as NOUN, VERB and ADJ.

View solution
import spacy

nlp = spacy.load("en_core_web_sm")

text = "Students develop intelligent applications."
doc = nlp(text)

for token in doc:
    print(token.text, "->", token.pos_)
EXERCISE 4 · DEVELOPING

Dependency parsing

Objective: Identify the grammatical dependency relationship of each token.

Sample input:

Students develop intelligent applications.

Task: Print the token and its dependency label.

Starter code
import spacy

nlp = spacy.load("en_core_web_sm")

text = "Students develop intelligent applications."
doc = nlp(text)

for token in doc:
    print(token.text, "->", __________)
Hint

Use the dependency attribute of a token. It ends with an underscore.

View solution
import spacy

nlp = spacy.load("en_core_web_sm")

text = "Students develop intelligent applications."
doc = nlp(text)

for token in doc:
    print(token.text, "->", token.dep_)

To inspect the head of each token as well:

for token in doc:
    print(token.text, "->", token.dep_, "->", token.head.text)
EXERCISE 5 · DEVELOPING TO ADVANCED

Interpret dependency relationships

Objective: Understand how dependency labels describe the relationships among words.

Consider:

Students develop intelligent applications.

Answer these questions:

  1. Which word is the nominal subject of the verb?
  2. Which word is the direct object of the verb?
  3. Which word describes the noun applications?
  4. Which word is the main syntactic root?
Hint

Think about WHO performs the action, WHAT receives the action, WHICH word describes the noun and WHICH word is the main verb.

View solution
  1. Students → nsubj
  2. applications → obj or dobj, depending on the model
  3. intelligent → amod
  4. develop → ROOT

6. Debugging challenge

DEBUGGING · DEVELOPING

A student writes the following code:

import spacy

nlp = spacy.load("en_core_web_sm")

text = "Students develop applications."
doc = nlp(text)

for token in doc:
    print(token.lemma)

Question: What is wrong with the last line?

Show correction

For spaCy's string representation of the lemma, use token.lemma_, not token.lemma.

for token in doc:
    print(token.lemma_)

token.lemma is an internal numeric lexical attribute, whereas token.lemma_ returns the readable string.

7. Practical case study

Case: Understanding a student feedback message

Input message:

"Ravi likes the NLP course. He says it is very useful."

Identify the relevant analysis:

  1. Tokenization: identify individual tokens.
  2. Morphology: identify the base form of likes.
  3. Syntax: identify grammatical categories and relationships.
  4. Discourse: determine who He refers to and what it refers to.
  5. Semantics and pragmatics: interpret the positive evaluation in the context of the feedback.
View suggested analysis
  • likes → like (lemma)
  • Ravi is the subject of the first sentence.
  • He refers to Ravi.
  • it refers to the NLP course.
  • very useful expresses a positive evaluation.

These are contextual interpretations; a complete automated system may require coreference and semantic models in addition to basic spaCy parsing.

Implementation reminder: The code examples are intended to run in a Python environment such as Jupyter Notebook, Google Colab or a local Python installation with spaCy and the English model installed. The Blogger post displays code; it does not execute Python.
FINAL SECTION

Answer Key and Solutions

Attempt each question before opening its solution. Quiz explanations are displayed after checking the relevant quiz.

Level 1 – Remember: MCQ answers

Reveal Level 1 answer key
QuestionAnswerExplanation
Q1BMorphological analysis studies roots, prefixes, suffixes and word forms.
Q2CSyntactic analysis studies grammatical relationships such as subject, verb and object.
Q3ASemantic analysis examines sentence and word meaning.
Q4DDiscourse integration connects information across sentences.
Q5BPragmatic analysis interprets intention using context.

Level 2 – Understand: MCQ answers

Reveal Level 2 answer key
QuestionAnswerExplanation
Q1ATokenization splits text into tokens.
Q2Ctoken.lemma_ returns the lemma string.
Q3BPOS tagging assigns grammatical categories.
Q4Dnsubj identifies the nominal subject.
Q5Aamod identifies an adjectival modifier.

Level 3 – Programming solutions

Exercise 1: Tokenization
import spacy

nlp = spacy.load("en_core_web_sm")
text = "Students are learning Natural Language Processing."
doc = nlp(text)

for token in doc:
    print(token.text)

Expected result: Each word and punctuation mark is printed as an individual token.

Exercise 2: Lemmatization
import spacy

nlp = spacy.load("en_core_web_sm")
text = "Students are developing applications."
doc = nlp(text)

for token in doc:
    print(token.text, "->", token.lemma_)

Expected result: Students → student; are → be; developing → develop; applications → application.

Exercise 3: POS tagging
import spacy

nlp = spacy.load("en_core_web_sm")
text = "Students develop intelligent applications."
doc = nlp(text)

for token in doc:
    print(token.text, "->", token.pos_)

Expected result: Students → NOUN; develop → VERB; intelligent → ADJ; applications → NOUN.

Exercise 4: Dependency parsing
import spacy

nlp = spacy.load("en_core_web_sm")
text = "Students develop intelligent applications."
doc = nlp(text)

for token in doc:
    print(token.text, "->", token.dep_)

Expected relationships: Students → nsubj; develop → ROOT; intelligent → amod; applications → obj or dobj, depending on the model.

Exercise 5: Interpret dependency relationships
  1. Students – nominal subject (nsubj).
  2. applications – direct object (obj or dobj).
  3. intelligent – adjectival modifier (amod).
  4. develop – root of the dependency tree (ROOT).
Debugging challenge solution

Incorrect: token.lemma

Correct: token.lemma_

The underscore version returns the readable lemma string.

Case study solution

In "Ravi likes the NLP course. He says it is very useful":

  • likes has lemma like.
  • He refers to Ravi.
  • it refers to the NLP course.
  • very useful expresses a positive evaluation.

Important examination questions

  1. Define Natural Language Processing and computational linguistics.
  2. Explain the five levels of language analysis with examples.
  3. Differentiate stemming and lemmatization.
  4. Explain syntactic and semantic analysis with examples.
  5. What is discourse integration? Explain coreference resolution.
  6. Explain pragmatic analysis using a conversational example.
  7. What is tokenization? Write a Python program using spaCy.
  8. Explain POS tagging and important POS categories.
  9. What is dependency parsing? Explain nsubj, obj/dobj and amod.
  10. Write a Python program to perform tokenization, lemmatization, POS tagging and dependency parsing.

Additional practice questions

  1. How does a computer represent text for machine-learning algorithms?
  2. Why is semantic analysis different from syntactic analysis?
  3. Can a sentence be grammatically correct but semantically unusual? Give an example.
  4. Why does discourse analysis require information from earlier sentences?
  5. How can pragmatic analysis improve chatbot responses?

Final learning summary

🧠 What should I know?

  • Five levels of language analysis.
  • Key NLP terminology.
  • Definitions and examples.

🔍 What should I understand?

  • How language analysis works.
  • POS and dependency relationships.
  • How context influences interpretation.

💻 What should I implement?

  • Tokenization.
  • Lemmatization.
  • POS tagging.
  • Dependency parsing.

🎯 What should I practise?

  • Python programming.
  • Output interpretation.
  • Debugging and case studies.
Remember the five levels:
Lexical = Words
Syntactic = Structure
Semantic = Meaning
Discourse = Connections
Pragmatic = Intention

Post a Comment

0 Comments