0% found this document useful (0 votes)
4 views36 pages

NLP Lab

The document outlines a lab practical file for DSC 530: Natural Language Processing, submitted by Rohan Singh as part of a Master's degree requirement. It includes a series of experiments focused on various NLP tasks such as text preprocessing, sentiment analysis, named entity recognition, and text classification. Each experiment details the aim, theoretical background, methods, and conclusions related to the respective NLP applications.

Uploaded by

Rohan singh
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views36 pages

NLP Lab

The document outlines a lab practical file for DSC 530: Natural Language Processing, submitted by Rohan Singh as part of a Master's degree requirement. It includes a series of experiments focused on various NLP tasks such as text preprocessing, sentiment analysis, named entity recognition, and text classification. Each experiment details the aim, theoretical background, methods, and conclusions related to the respective NLP applications.

Uploaded by

Rohan singh
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

DSC 530: Natural Language Processing

Lab Practical File


Submitted towards the partial fulfilment of
the requirements of the award of the degree of

Master of Technology
In
Data Science

Submitted by
Rohan Singh
25/DSC/10
II SEM, I Year

Submitted to
Dr. Rahul
Assistant Professor
Department of Software Engineering

Delhi Technological University


(FORMERLY Delhi College of Engineering)
Bawana Road, New Delhi-110042
April 2026
Index

S. No. Experiment Name Date Page No. Remark


1 To build a complete text preprocessing 07/01/26 01-04
pipeline to clean and prepare raw text data
for NLP models

2 Classify customer feedback as positive or 14/01/26 05-08


negative using traditional machine learning
models.

3 Extract entities like company names, dates, 21/01/26 09-12


and invoice amounts from text.
4 Classify news articles into predefined 28/01/26 13-16
categories such as Politics, Sports, and
Technology.
5 Generate concise summaries of lengthy 04/02/26 17-20
legal documents using extractive and
abstractive methods

6 Translate text from one language to another 18/02/26 21-23


using neural machine translation models.

7 Perform sentiment analysis on tweets or 25/02/26 24-26


social media posts using pretrained BERT
Model.

8 Build a system that can answer the questions 18/03/26 27-29


based on a given context.

9 Build a chatbot that can handle basic 01/04/26 30-31


customer queries.

10 Generate human like text for content 15/04/26 32-34


creation using GPT Models.
EXPERIMENT 1
AIM: To build a complete text preprocessing pipeline to clean and prepare raw text data for
NLP models

THEORY:
Within Natural Language Processing (NLP), raw text data is rarely ready for direct use. It is
typically unorganized, contains noise, and varies in format. To make this data suitable for
machine learning or deep learning systems, it must first be cleaned and structured. This
preparation stage is called text preprocessing. It acts as a crucial initial step in NLP
workflows, ensuring that the input becomes consistent, interpretable, and ready for analysis
by computational models. Effective preprocessing significantly enhances model accuracy,
lowers computational load, and removes unnecessary or misleading information. If this step
is ignored, models may incorrectly interpret patterns in text, resulting in unreliable
predictions and weak generalization.

Importance of a Text Preprocessing Pipeline


Real-world textual data such as content from social media, web pages, or documents often
includes irregularities like spelling differences, punctuation, symbols, and irrelevant
characters. Moreover, language itself is complex, involving synonyms, ambiguity, and
varying grammatical structures, all of which can confuse models if not handled properly. A
structured preprocessing pipeline is designed to address these challenges in an organized and
repeatable way. It ensures that every data sample undergoes identical processing steps,
leading to consistency and dependability in how the dataset is prepared.

Tokenization
Tokenization refers to splitting text into smaller components known as tokens. These tokens
may be individual words, phrases, or even sentences. This step is essential because most NLP
techniques operate on these smaller units rather than entire text blocks. By dividing text into
manageable pieces, tokenization enables further analysis such as counting word frequencies
or generating embeddings. It essentially prepares the text for all subsequent preprocessing
operations.

Normalization of Text
Normalization involves standardizing text into a uniform format. Common practices include
converting all letters to lowercase, removing punctuation, and eliminating special characters.
The aim is to reduce variation so that words with identical meanings but different
appearances are treated the same. This step may also include expanding contractions (e.g.,
“don’t” to “do not”) and handling numbers or abbreviations. By doing so, normalization
reduces complexity and makes the dataset easier to analyze.

Removal of Stopwords
Certain commonly used words such as “the,” “is,” “and,” and “in” occur frequently but add
little meaningful information. These are known as stopwords. Eliminating them helps
concentrate on more informative terms that contribute to the overall meaning. Removing
stopwords reduces unnecessary data and improves processing efficiency. However, in some

1
applications, these words may still be important, so this step should be applied with
consideration.

Stemming and Lemmatization


Both stemming and lemmatization aim to simplify words to their root form, helping to group
similar terms and reduce [Link] works by trimming prefixes or suffixes,
which can sometimes produce non-dictionary words. Lemmatization, on the other hand, relies
on linguistic rules to convert words into their correct base form. For instance, “running”
becomes “run.”While both methods reduce dimensionality and improve processing
efficiency, lemmatization typically produces more accurate results.

Vectorization and Feature Extraction


Once preprocessing is complete, the refined text must be converted into numerical form so
that models can process it. This step is called vectorization or feature extraction. Techniques
such as Bag of Words, TF-IDF, and word embeddings are commonly [Link] approaches
represent text as numerical vectors, capturing the importance and relationships between
words. The quality of preprocessing directly affects how meaningful these representations
are, and ultimately influences model performance.

Automation Through Pipelines


A preprocessing pipeline combines all these steps into a single automated process. This
guarantees that every piece of text is treated consistently, following the same sequence of
[Link] is especially valuable for large datasets, where manual
processing is impractical. Additionally, such pipelines are reusable and can be adapted for
different NLP tasks with minimal effort.

CONCLUSION:
To summarize, constructing a comprehensive text preprocessing pipeline is essential in NLP.
It converts raw, unstructured data into a clean and organized format that can be effectively
analyzed. By incorporating techniques like tokenization, normalization, stopword removal,
stemming, and vectorization, the pipeline improves both the performance and efficiency of
models.A well-structured preprocessing system not only boosts accuracy but also ensures
consistency and scalability, making it a fundamental element of modern NLP applications.

2
3
4
EXPERIMENT 2
AIM: Classify customer feedback as positive or negative using traditional machine learning
models.

THEORY:

Overview of Sentiment Analysis


Sentiment analysis is an essential application within Natural Language Processing (NLP) that
focuses on identifying the emotional intent behind textual content. When applied to customer
feedback, it helps determine whether a given opinion reflects a positive, negative, or
sometimes neutral attitude. This allows organizations to gauge customer satisfaction, uncover
issues, and make informed decisions based on data. Since customer feedback is usually
unstructured and may include informal expressions, spelling inconsistencies, and contextual
subtleties, it cannot be directly used for model training. As a result, machine learning
approaches require proper preparation of the data through preprocessing and feature
extraction.

Problem Statement and Goal


The aim of this task is to develop a model capable of automatically labeling customer
feedback as either positive or negative. This falls under supervised learning, where the
system learns from previously labeled examples consisting of text and their corresponding
sentiment categories. The model’s responsibility is to capture relationships between textual
patterns and sentiment labels so that it can accurately classify new, unseen inputs.

Importance of Preprocessing
Before feeding text into a machine learning model, it must be cleaned and standardized.
Preprocessing steps typically include breaking text into tokens, converting characters to
lowercase, removing punctuation marks, and eliminating commonly used but insignificant
words (stopwords). In certain cases, stemming or lemmatization is applied to reduce words to
their base forms. These steps ensure that unnecessary noise is removed while preserving
meaningful information. Additionally, preprocessing reduces the size and complexity of the
data, making computation more efficient.

Methods for Feature Representation


Since machine learning models operate on numerical data, textual input must be transformed
into a suitable format. Feature extraction techniques serve this purpose. One common
approach is the Bag of Words model, where text is represented based on the frequency of
words. Another widely adopted technique is TF-IDF (Term Frequency–Inverse Document
Frequency), which assigns importance to words depending on how relevant they are within a
document compared to the entire dataset. This reduces the impact of overly common words
and highlights more informative ones. Through these methods, text is converted into
structured numerical vectors that models can process effectively.

Conventional Machine Learning Algorithms


A variety of traditional machine learning algorithms can be applied to sentiment
classification. Popular choices include Naïve Bayes, Logistic Regression, and Support Vector
Machines (SVM). Naïve Bayes is frequently used due to its simplicity and strong
performance on high-dimensional text data, despite assuming feature independence. Logistic

5
Regression works well for binary classification by estimating class probabilities using a linear
boundary. SVM, on the other hand, identifies the best separating boundary between classes
by maximizing the margin, often resulting in robust predictions. These approaches are termed
“traditional” because they rely on statistical principles rather than deep neural networks.

Training and Performance Evaluation


After converting text into features, the dataset is split into training and testing portions. The
model learns from the training data and is then evaluated using the testing data to assess its
effectiveness. Common evaluation metrics include accuracy, precision, recall, and F1-score.
Accuracy reflects overall correctness, while precision and recall provide deeper insight into
class-specific performance. The F1-score combines both precision and recall, making it
especially useful when dealing with uneven class distributions. Proper evaluation ensures that
the model performs reliably and can generalize well to new data.

Benefits of Traditional Approaches


Traditional machine learning techniques offer several practical advantages. They are less
resource-intensive, require smaller datasets compared to deep learning methods, and are
easier to understand and implement. This makes them suitable for scenarios with limited
computational power or when rapid deployment is needed. With well-prepared data and
effective feature engineering, these models can deliver strong performance in many text
classification tasks.

CONCLUSION
To conclude, using traditional machine learning methods to classify customer feedback into
positive and negative sentiments is a practical and effective NLP solution. By integrating
preprocessing steps, feature extraction techniques such as TF-IDF, and algorithms like Naïve
Bayes or SVM, reliable sentiment classification systems can be developed. This work
emphasizes the importance of proper data preparation, thoughtful feature design, and
appropriate model selection, all of which are key to achieving accurate and dependable
results in NLP applications.

6
7
8
EXPERIMENT 3
AIM: Extract entities like company names, dates, and invoice amounts from text.

THEORY:

Introduction to Named Entity Recognition


Named Entity Recognition (NER) is an important task in Natural Language Processing (NLP)
that deals with detecting and categorizing specific elements within unstructured text. These
elements, called entities, may include names of organizations, locations, dates, monetary
figures, and other relevant categories depending on the application. In real-world use cases
such as invoice handling, business reporting, and automated document processing,
identifying key details like company names, billing dates, and payment amounts is crucial.
NER makes it possible to convert raw textual information into an organized and machine-
readable format.

Purpose of Entity Extraction


The main goal of this experiment is to identify and extract essential entities—such as
company names, dates, and invoice values—from textual input. By doing so, unstructured
data is transformed into a structured representation that can be easily stored, searched, and
analyzed. For instance, in an invoice, important information may be distributed across
multiple lines or sentences. NER helps in systematically locating and isolating these details,
reducing manual effort and improving processing efficiency.

Categories of Entities
Entities represent meaningful real-world concepts and are typically grouped into predefined
classes. In this case, the focus is on three categories: organizations (company names), time-
related expressions (dates), and monetary values (invoice amounts). Each category follows
certain identifiable patterns. Company names often appear as proper nouns, dates follow
recognizable formats like “DD/MM/YYYY” or “Month Day, Year,” and financial amounts
are usually accompanied by currency symbols or numeric structures. Detecting these patterns
is essential for accurate extraction.

Methods for Implementing NER


NER systems can be built using rule-based methods, statistical models, or machine learning
techniques. Rule-based approaches rely on predefined patterns, dictionaries, and regular
expressions. While they work well for structured data, they may struggle with variations in
language. Statistical and machine learning methods treat NER as a labeling problem, where
each word is assigned a tag indicating whether it belongs to an entity. Traditional techniques
such as Hidden Markov Models (HMMs) and Conditional Random Fields (CRFs) have been
widely used. More recent approaches utilize deep learning models like recurrent neural
networks and transformer-based architectures, which capture context more effectively and
generally provide higher accuracy. However, for simpler experiments, basic methods or pre-
built libraries are often sufficient.

Preprocessing for NER Tasks


Before extracting entities, the text needs to be prepared through preprocessing steps such as
tokenization, sentence splitting, and normalization. Unlike other NLP tasks, aggressive
preprocessing (like removing stopwords or applying stemming) is usually avoided in NER.

9
This is because entity recognition depends heavily on the original context and sentence
structure. Preserving this context is essential for correctly identifying entities.

Role of Features and Context


In traditional NER systems, feature design is a key component. Useful features include
capitalization patterns, prefixes and suffixes, grammatical tags, and surrounding words. For
example, words that begin with uppercase letters often indicate names, while symbols like
“₹” or “$” suggest monetary values. Contextual terms such as “invoice,” “total,” or “paid”
also provide important clues for identifying entities. These features help models distinguish
between ordinary words and meaningful entities.

Assessing NER Performance


The effectiveness of an NER system is typically measured using precision, recall, and F1-
score. Precision indicates how many identified entities are correct, while recall measures how
many actual entities were successfully detected. The F1-score combines both metrics to give
an overall performance measure. Proper evaluation ensures that the system accurately
extracts information without missing important details or generating incorrect outputs.

Practical Uses of Entity Extraction


Entity extraction is widely applied in multiple domains. In finance, it supports invoice
processing and financial data analysis. In business analytics, it helps derive insights from
textual reports. In healthcare, it assists in identifying medical terms and patient-related
information from clinical [Link] automating the conversion of text into structured
data, NER greatly improves efficiency and reduces manual workload.

CONCLUSION
To conclude, Named Entity Recognition is a powerful NLP technique for identifying and
extracting important information from unstructured text. By detecting entities such as
company names, dates, and monetary values, it enables the transformation of raw data into a
structured format suitable for analysis. This experiment demonstrates the practical application
of NER, highlighting how preprocessing and feature design contribute to effective entity
extraction, making it a vital component of advanced NLP systems.

10
11
12
EXPERIMENT 4
AIM: Classify news articles into predefined categories such as Politics, Sports, and
Technology.

THEORY:

Introduction to Text Classification


Text classification is a core task in Natural Language Processing (NLP) where pieces of text
are assigned to predefined categories based on their content. In the case of news articles, this
process helps sort large amounts of information into categories such as politics, sports, and
technology. Such organization improves content management, search efficiency, and
personalized user experiences. With the continuous expansion of online media, an enormous
volume of news is produced every day. Manually organizing this data is neither efficient nor
scalable, which makes automated classification systems highly valuable in modern
applications.

Aim of News Categorization


The purpose of this experiment is to design a system capable of automatically assigning news
articles to specific categories. This is a supervised learning task, where the model is trained
using labeled data that includes both the text and its corresponding category. The objective is
for the model to learn distinctive patterns and features associated with each category so that it
can correctly classify new, unseen articles. This ultimately improves the accessibility and
structure of large news datasets.

Nature of News Data


News articles are generally composed of structured text, including headlines and detailed
content. Each category tends to use its own vocabulary and style. For example, political news
often contains references to governance, policies, and elections, whereas sports articles
revolve around teams, matches, and results. Similarly, technology-related news includes
terms associated with software, devices, and innovations. Recognizing these unique linguistic
patterns is essential, as the classification model depends on them to differentiate between
categories.

Preprocessing of News Text


Before applying classification algorithms, the text must be cleaned and standardized. This
involves converting all text to lowercase, removing punctuation and special symbols, and
filtering out stopwords that carry little meaning. Tokenization is used to split text into smaller
units, typically words, enabling detailed analysis. In some cases, stemming or lemmatization
is applied to reduce words to their root forms, which helps minimize redundancy and
maintain consistency. These preprocessing steps ensure that the dataset is well-structured and
suitable for further analysis and model training.

Feature Representation Techniques


Machine learning models require numerical input, so textual data must be transformed into
vector form. Common approaches include Bag of Words and TF-IDF (Term Frequency–
Inverse Document Frequency). These techniques represent each document as a vector, either
based on word counts or weighted importance scores. This allows the model to capture

13
relationships between words and categories effectively. The quality of feature extraction has
a significant impact on how well the classification system performs.

Classification Algorithms
Several traditional machine learning models can be applied to news classification, including
Naïve Bayes, Logistic Regression, and Support Vector Machines (SVM). These methods are
particularly effective for text-based tasks due to their ability to handle high-dimensional data.
Naïve Bayes is widely used because of its simplicity and strong performance with word
frequency data. Logistic Regression models class probabilities and works well for
classification tasks, while SVM focuses on finding optimal boundaries between categories,
often leading to strong predictive performance. The selection of a model depends on the
dataset and the desired balance between efficiency and accuracy.

Training and Model Evaluation


The dataset is typically split into training and testing subsets. The model learns from the
training data and is then evaluated on unseen test data to measure its effectiveness.
Performance is assessed using metrics such as accuracy, precision, recall, and F1-score.
While accuracy gives an overall measure, precision and recall provide deeper insights into
classification quality. The F1-score combines these two metrics, making it useful when
dealing with imbalanced datasets. Proper evaluation ensures that the model performs reliably
on new data and avoids overfitting.

Real-World Applications
News classification systems are widely used in practical scenarios. They power news
aggregation platforms by organizing articles into categories, enhance recommendation
systems by tailoring content to user preferences, and improve search engines by delivering
more relevant results. Additionally, they assist in analyzing trends, monitoring public interest,
and managing content across various domains.

CONCLUSION
In summary, classifying news articles is a significant NLP application that helps manage and
retrieve information efficiently. By combining preprocessing steps, feature extraction
techniques such as TF-IDF, and machine learning models, it is possible to create accurate and
scalable classification systems. This experiment demonstrates how unstructured text can be
converted into meaningful numerical representations and used to train models that categorize
news content effectively, forming an essential part of intelligent information processing
systems.

14
15
16
EXPERIMENT 5
AIM: Generate concise summaries of lengthy legal documents using extractive and
abstractive methods.

THEORY

Overview of Text Summarization


Text summarization is a key area in Natural Language Processing (NLP) that aims to produce
a shortened version of a document without losing its core message. This is especially
valuable in fields like law, where documents are often extensive and filled with complex
information. Summarization helps make such content easier to read and understand. Legal
texts are typically detailed, use formal language, and contain tightly packed information.
Reviewing them manually can be slow and demanding. Automated summarization techniques
address this challenge by generating concise versions, enabling quicker comprehension and
more efficient decision-making.

Purpose of Summarizing Legal Documents


The goal of this experiment is to create brief yet informative summaries of long legal
documents using both extractive and abstractive methods. The focus is on reducing the length
of the content while preserving its key ideas. This can involve either selecting important
sentences directly from the document or generating new sentences that capture the main
points. The final summary should be clear, accurate, and reflective of the original material.

Difficulties in Legal Summarization


Summarizing legal text is challenging due to its complicated sentence structures, specialized
vocabulary, and reliance on precise wording. Important details are often spread across
different sections, making it harder to identify what should be included in a summary.
Accuracy is particularly critical in legal contexts, as even minor wording changes can alter
meaning. Therefore, summarization systems must ensure that essential information is retained
and correctly represented.

Extractive Method of Summarization


Extractive summarization works by choosing the most relevant sentences from the original
document and combining them to form a summary. It does not create new content but instead
relies on identifying sentences that best represent the document’s overall meaning. Common
techniques include ranking sentences based on word frequency, TF-IDF scores, or graph-
based approaches that determine sentence importance. Since the original sentences remain
unchanged, this method generally preserves grammatical correctness and factual accuracy.
However, extractive summaries may sometimes lack smooth flow or include repetitive or less
relevant content if sentence selection is not carefully handled.

Abstractive Method of Summarization


Abstractive summarization takes a different approach by generating entirely new sentences
that convey the essence of the original text. This method resembles how humans summarize,
as it involves rephrasing and condensing information. It typically relies on advanced models
such as sequence-to-sequence frameworks, recurrent neural networks, or transformer-based
architectures. These models capture context and meaning, allowing them to produce

17
summaries that are more natural and coherent. Despite its advantages, abstractive
summarization is more complex and may occasionally introduce errors or miss critical points
if not properly trained.

Preprocessing and Text Representation


Before applying summarization techniques, the text must be prepared through preprocessing
steps like sentence splitting, tokenization, and normalization. Unlike other NLP tasks,
maintaining the original structure and context is essential because summarization depends
heavily on relationships between sentences. For extractive approaches, features such as
sentence position, length, and keyword importance are commonly used. In abstractive
methods, the text is converted into embeddings that capture semantic meaning, enabling the
model to generate meaningful summaries.

Evaluation of Summaries
The performance of summarization systems is often measured using metrics like ROUGE,
which evaluates the overlap between generated summaries and reference summaries in terms
of words and phrases. In addition to numerical metrics, human evaluation is important—
especially for legal content—since clarity, correctness, and preservation of intent are crucial.
A good summary should accurately reflect the original document’s key information.

Real-World Applications
Legal document summarization has many practical uses. It assists legal professionals in
quickly reviewing case materials, helps organizations manage contracts more efficiently, and
supports research by providing concise summaries of lengthy judgments. It is also valuable in
compliance and regulatory work, where large volumes of text must be analyzed within
limited time.

CONCLUSION
In summary, text summarization is an effective technique for reducing lengthy legal
documents into concise and meaningful forms. By leveraging both extractive and abstractive
approaches, it is possible to achieve a balance between accuracy and readability. This
experiment demonstrates the importance of preserving context, selecting key information,
and applying suitable NLP methods to build efficient summarization systems, which are
increasingly important for handling complex legal data.

18
19
20
EXPERIMENT 6
AIM: Translate text from one language to another using neural machine translation models.

THEORY

Overview of Neural Machine Translation


Neural Machine Translation (NMT) is an advanced method for translating text between
languages using deep learning techniques. Unlike older rule-based or statistical approaches,
NMT utilizes neural networks to learn linguistic patterns, grammar, and contextual
relationships directly from large bilingual datasets. As a result, it produces translations that
are more natural and fluent, since it considers the meaning of entire sentences rather than
translating individual words in isolation.

How NMT Works


The fundamental structure behind NMT is the encoder-decoder framework. The encoder
takes a sentence in the source language and converts it into a numerical representation, often
referred to as a context vector, which captures its overall meaning. The decoder then uses this
representation to generate the translated sentence in the target language, producing it step by
step. To improve performance, modern systems include attention mechanisms. These allow
the model to selectively focus on different parts of the input sentence while generating each
word, ensuring that important details are preserved, particularly in longer or more complex
sentences.

Importance of Transformer Models


Recent progress in translation systems has been largely driven by transformer architectures.
Unlike earlier models such as recurrent neural networks, transformers do not process text
sequentially. Instead, they rely on self-attention mechanisms to analyze all words in a
sentence simultaneously, resulting in faster computation and better performance. Models like
MarianMT, used in this experiment, are built on transformer technology and are pre-trained
on extensive multilingual datasets. They can be readily applied to various language pairs and
deliver high-quality translations without requiring extensive retraining.

Tokenization and Data Preparation


Before text can be processed by an NMT model, it must be transformed into a suitable
format. This involves tokenization, where sentences are divided into smaller units such as
words or subwords. These units are then mapped to numerical identifiers that the model can
interpret. In this setup, a tokenizer is responsible for both converting input text into tokens
and reconstructing the translated output. Proper tokenization is essential for handling
different languages effectively, especially those with complex structures.

Training and Translation Process


NMT systems are generally trained on large collections of parallel text, where each sentence
in one language is paired with its translation in another. During training, the model adjusts its
internal parameters to minimize the difference between its predicted output and the actual
translation. In practical scenarios, pre-trained models are commonly used instead of training
from scratch. These models already possess knowledge of language patterns and can perform

21
translation directly. The process of generating translations using such a trained model is
known as inference.

Real-World Uses of NMT


Neural machine translation has a wide range of applications. It is used in online translation
services, conversational agents, multilingual search systems, and content localization
platforms. By enabling accurate translation across languages, NMT plays a vital role in
facilitating global communication and information sharing.

CONCLUSION
In summary, neural machine translation marks a major advancement in NLP by delivering
accurate, context-aware translations. Through the use of deep learning and transformer-based
models, NMT systems can understand and generate language in a way that closely resembles
human communication, making them highly effective for modern translation needs.

22
23
EXPERIMENT 7
AIM: Perform sentiment analysis on tweets or social media posts using pretrained BERT
Model.

THEORY:

Overview of Sentiment Analysis


Sentiment analysis is a key application of Natural Language Processing (NLP) that focuses
on identifying the emotional intent behind textual data. It is commonly used to evaluate
opinions in customer reviews, social media content, and other forms of user-generated text.
The primary objective is to categorize the text into sentiments such as positive, negative, or
neutral based on the language and context used. With the expansion of social media and
digital platforms, analyzing public opinion has become increasingly important. Earlier
approaches depended heavily on manual feature design and predefined word lists, whereas
modern techniques rely on deep learning models to achieve better performance and
scalability.

Significance of BERT in Sentiment Analysis


BERT (Bidirectional Encoder Representations from Transformers) is an advanced language
model designed to better understand the context of words in a sentence. Unlike traditional
models that read text in a single direction, BERT processes information in both directions—
left and right—simultaneously. This bidirectional capability allows it to capture subtle
meanings and relationships within text. In sentiment analysis tasks, BERT proves highly
effective because it can interpret complex expressions, contextual dependencies, and even
nuanced language patterns. Pretrained versions of BERT are trained on large datasets and can
be adapted to specific tasks like sentiment classification with minimal additional training.

How the Model Operates


The process starts with raw input text, such as a tweet or review. This text is first broken
down into smaller components called tokens through tokenization. These tokens are then
converted into numerical form so that the model can process them. BERT passes these token
representations through multiple layers of transformer encoders. Each layer uses self-
attention mechanisms to understand how words relate to one another within the sentence.
This results in a context-rich representation of the entire input. For classification purposes, an
additional output layer is attached to the model. This layer assigns a sentiment label—such as
positive or negative and provides a confidence score indicating the reliability of the
prediction.

Transfer Learning and Pretrained Models


A major advantage of BERT is its use of transfer learning. Instead of building a model from
scratch, pretrained BERT models can be reused and fine-tuned for specific applications.
These models already possess a strong understanding of language, gained from training on
massive text corpora. In this experiment, a pretrained BERT-based sentiment analysis
pipeline is utilized. This approach simplifies implementation while maintaining high
accuracy, as the model has already been exposed to similar linguistic patterns.

Practical Applications
Sentiment analysis is widely applied across different industries. Companies use it to track

24
customer opinions and maintain brand reputation by analyzing feedback and social media
content. In politics, it helps measure public sentiment, while in finance, it can assist in
predicting market behavior based on news analysis. It is also valuable in customer service
systems for prioritizing responses based on user emotions.

Strengths and Drawbacks


BERT-based models offer significant advantages, including strong contextual understanding
and high classification accuracy. However, they also come with certain limitations. These
models demand considerable computational resources and may occasionally struggle with
ambiguous or highly sarcastic text. Additionally, biases present in the training data can
influence their predictions.

CONCLUSION
In summary, using pretrained BERT models for sentiment analysis represents a major
advancement in NLP. By leveraging deep contextual understanding and transformer-based
architectures, BERT enables precise and efficient sentiment classification. This makes it an
effective solution for analyzing large-scale textual data and extracting valuable insights from
it.

25
26
EXPERIMENT 8
AIM: Build a system that can answer the questions based on a given context.

THEORY:

Overview of Question Answering Systems


Question Answering (QA) systems are a significant area of Natural Language Processing
(NLP) that aim to respond to user queries expressed in natural language. Unlike conventional
search engines that return a list of documents or links, QA systems deliver direct and precise
answers extracted from a given source of information. This makes them highly valuable in
applications like virtual assistants, helpdesk automation, and educational platforms. In this
experiment, the objective is to design a system that can interpret a passage of text and provide
accurate answers to questions based on that passage. This approach is known as extractive
question answering, where the response is selected directly from the provided content rather
than being generated.

How a QA System Functions


A QA system operates using two primary inputs: a context and a question. The context is a
piece of text containing relevant information, while the question is a query related to that text.
The system processes both inputs together to identify the most suitable answer. Modern QA
models rely on deep learning techniques to examine the relationship between the question
and various parts of the context. They assign probabilities to different segments (spans) of the
text, identifying which portion most likely answers the question. The segment with the
highest probability is then returned as the final answer.

Importance of Transformer Architectures


Transformer-based models are central to the effectiveness of modern QA systems. These
models use self-attention mechanisms to capture relationships between words and understand
context more deeply. Architectures such as BERT are widely used for this purpose. In such
models, the question and context are combined into a single input sequence. The model
processes this sequence through multiple layers to generate context-aware representations. It
then predicts the starting and ending positions of the answer within the context, enabling
precise extraction instead of generating responses from scratch.

Tokenization and Input Preparation


Before processing, both the question and the context must be tokenized. Tokenization breaks
the text into smaller units called tokens, which are then converted into numerical values for
the model. Special tokens are inserted to separate and identify the question and context within
the input. This helps the model distinguish between them and focus on the relevant sections
while determining the answer.

Use of Pretrained Models


Building a QA model from the ground up requires large labeled datasets and significant
computational power. To address this, pretrained models are commonly used. These models
have already been trained on extensive QA datasets and can generalize effectively to new
inputs. In this experiment, a pretrained QA pipeline is employed to perform inference. The
system processes the input question and context and outputs the most probable answer along
with a confidence score, making the solution both efficient and practical.

27
Applications of QA Systems
QA systems are widely used across multiple domains. They form the backbone of chatbots
and virtual assistants, allowing them to answer user queries intelligently. In education, they
assist learners by quickly extracting information from study materials. In customer support,
they automate responses to common queries, improving efficiency and user satisfaction.

Strengths and Limitations


Transformer-based QA systems offer high accuracy and strong contextual understanding,
enabling them to handle complex queries effectively. However, they are restricted to the
information available within the provided context and cannot answer questions beyond it.
Their performance also depends on how clear and well-structured the input text is.

CONCLUSION
In summary, developing a question answering system using pretrained transformer models
highlights the capabilities of modern NLP techniques. By utilizing attention mechanisms and
contextual understanding, these systems can accurately extract relevant information from
text, making them highly useful across a variety of real-world applications.

28
29
EXPERIMENT 9
AIM: Build a chatbot that can handle basic customer queries.

THEORY:

Overview of Chatbots
A chatbot is an AI-driven system built to interact with users in a conversational manner,
either through text or voice. In customer service environments, chatbots are commonly used
to address routine queries such as product details, order tracking, troubleshooting, and
general assistance. By automating these repetitive interactions, they reduce response times
and enhance the overall user experience through instant [Link] experiment involves
creating a basic chatbot that can respond to simple customer queries using Natural Language
Processing (NLP) techniques along with pretrained language models.

How Chatbots Function


The working of a chatbot begins with receiving input from the user. This input is processed
and transformed into a format understandable by the system. The chatbot then analyzes the
intent behind the query and determines an appropriate [Link] chatbots rely on deep
learning rather than fixed rule-based systems. These models are trained on large
conversational datasets, enabling them to learn patterns of human dialogue and generate
responses that feel more natural and coherent.

Importance of Language Models


Language models are at the core of chatbot functionality. Models like DialoGPT are
specifically designed for conversational tasks and are based on transformer architectures.
They are trained on extensive dialogue data, allowing them to generate contextually relevant
responses. These models work by predicting the next sequence of words based on the input
they receive. By considering the context of the conversation, they can produce replies that are
more flexible and meaningful compared to traditional rule-based systems.

Processing Input and Generating Responses


When a user enters a query, the chatbot first breaks the text into smaller components through
tokenization. These tokens are then converted into numerical form and passed to the language
model. The model processes this input and generates a sequence of words as the response. In
conversational systems, context plays an important role. While simple chatbots may treat
each query independently, more advanced systems maintain conversation history to produce
context-aware replies, enabling smoother multi-turn interactions.

Use of Pretrained Models


Building a chatbot from scratch requires significant data and computational resources. To
simplify development, pretrained models are often used. These models already possess an
understanding of conversational patterns and can be applied directly to chatbot [Link] this
experiment, a pretrained conversational model is utilized to generate responses. This
approach reduces complexity while still providing effective handling of general customer
queries.

Applications of Chatbots
Chatbots are widely implemented across various industries, including customer service, e-

30
commerce, banking, and healthcare. They assist users by answering common questions,
guiding them through processes, and offering round-the-clock support. This helps reduce the
workload on human agents and improves operational efficiency.

Benefits and Challenges


Chatbots provide several advantages such as quick response times, scalability, and cost
efficiency. They can handle multiple conversations simultaneously and deliver consistent
outputs. However, they also have limitations. Basic systems may struggle with complex or
ambiguous queries and may fail to maintain context in certain situations. In some cases, they
may produce inaccurate or irrelevant responses if the input is not clearly understood.

CONCLUSION
In summary, developing a chatbot using pretrained language models showcases the practical
use of NLP in automating customer interactions. By utilizing deep learning and transformer-
based models, chatbots can mimic human-like conversations and efficiently manage routine
queries, making them an essential component of modern digital services.

31
EXPERIMENT 10
AIM: Generate human like text for content creation using GPT Models.

THEORY

Overview of Text Generation


Text generation is an important area of Natural Language Processing (NLP) that focuses on
automatically creating meaningful and coherent text from a given input or prompt. It is
widely applied in tasks such as article writing, storytelling, email drafting, and generating
content for social media. The aim is to produce language that appears natural, grammatically
correct, and contextually [Link] in deep learning have greatly enhanced
the quality of generated text, allowing systems to produce outputs that closely resemble
human writing.

Importance of GPT Models


Generative Pre-trained Transformer (GPT) models are among the most advanced tools for
text generation. Built on transformer architecture, these models work by predicting the next
word in a sequence based on previously generated words. By continuously extending the
sequence, they can form complete sentences and [Link] models are trained on large
and diverse text datasets, enabling them to learn linguistic patterns, grammar, factual
knowledge, and different writing styles. This extensive training allows them to generate text
that is both fluent and contextually relevant.

How Text Generation Works


The process starts with an initial prompt provided by the user. This input is broken down into
smaller components through tokenization and then converted into numerical representations.
The model processes these tokens using multiple transformer layers, where self-attention
mechanisms help capture relationships between words. Based on this understanding, the
model predicts the most likely next word. This prediction is added to the sequence, and the
process repeats iteratively to generate longer text. Various parameters, such as maximum
length, temperature, and sampling techniques, can be adjusted to control the output. These
settings influence how creative, diverse, or deterministic the generated text will be.

Pretraining and Transfer Learning


GPT models undergo a pretraining phase using large-scale datasets in an unsupervised
manner. During this stage, the model learns general language patterns by predicting the next
word in sentences. This allows it to develop a strong understanding of language without
requiring labeled data. After pretraining, the model can be directly used for generating text or
further fine-tuned for specific tasks such as summarization, dialogue systems, or domain-
specific writing. This approach reduces the need for large amounts of task-specific training
data.

Applications of Text Generation


Text generation has numerous real-world applications. It is used in automated content
creation, conversational agents, virtual assistants, and even code generation. Businesses
utilize it for marketing materials, product descriptions, and personalized messaging. In

32
education, it assists with writing essays and explanations, making it a versatile tool across
domains.

Benefits and Challenges


GPT-based systems are capable of producing high-quality, fluent, and context-aware text
with minimal input. They can generate creative and diverse outputs, making them highly
useful for content generation [Link], they are not without limitations. These models
may sometimes produce inaccurate or misleading information, particularly when the input is
vague. They can also generate repetitive or generic responses if not properly tuned or guided.

CONCLUSION
In summary, text generation using GPT models represents a significant milestone in NLP. By
leveraging transformer architectures and large-scale pretraining, these models can efficiently
produce human-like text. This makes them powerful tools for a wide range of applications
involving content creation and automation.

33
34

You might also like