Comprehensive PCIT404 NLP Laboratory Assignment Manual for students
Detailed guide for PCIT404 NLP lab assignments including text preprocessing, regex-based cleaning, and vectorization techniques like Bag-of-Words and TF-IDF for practical NLP applications.
PCIT404 – NaturalLanguage Processing Laboratory | Assignment Manual
Laboratory Overview
PCIT404 is a 1-credit Natural Language Processing Laboratory. The syllabus
emphasizes NLP preprocessing, classical machine learning and statistical
NLP, transformer-based methods, and end-to-end systems involving LLMs,
prompt engineering, and Retrieval-Augmented Generation (RAG). The
prerequisite background includes Machine Learning, Natural Language
Processing, and Python Programming.
The manual is designed for practical-file preparation, viva preparation, and
laboratory execution. Students should supplement the theory with their own
program code, screenshots, datasets, observations, and results as required
by the instructor.
NLP Laboratory | 2
3.
PCIT404 – NaturalLanguage Processing Laboratory | Assignment Manual
Assignment 1: Text Preprocessing Pipeline
1. Title
Text Preprocessing Pipeline
2. Software Requirements
Python 3.x
Jupyter Notebook/Google Colab or VS Code
NLTK
spaCy
WordNet data
spaCy language model (e.g., en_core_web_sm)
pandas
matplotlib/plotly (optional).
3. Theory
Text preprocessing converts raw, noisy language into a representation suitable for NLP models. A
typical pipeline includes text acquisition, normalization, tokenization, stop-word handling, stemming
or lemmatization, and part-of-speech (POS) tagging.
Tokenization divides text into meaningful units. Whitespace tokenization is simple, rule-based
tokenization handles punctuation and special patterns, and subword tokenization divides words into
smaller units useful for modern transformer models.
Stop-word removal eliminates very common function words when they are not useful for the task.
However, stop words should not be removed blindly because words such as 'not' can be important for
sentiment and other tasks.
Stemming reduces words to approximate roots, while lemmatization maps words to linguistically valid
base forms. PorterStemmer and SnowballStemmer are common stemming approaches; WordNet-
based lemmatization uses lexical information.
POS tagging assigns grammatical categories such as noun, verb, adjective, and adverb. POS
information can support downstream tasks such as information extraction and syntactic analysis.
For multilingual, code-mixed, emoji-rich social-media data, preprocessing must preserve useful
meaning while normalizing noise. The syllabus specifically asks students to compare NLTK and spaCy
outputs and prepare a clean corpus for downstream classification. filecite turn0file0 L38-L47
4. Frequently Asked Questions (Viva)
Q. What is tokenization?
NLP Laboratory | 3
4.
PCIT404 – NaturalLanguage Processing Laboratory | Assignment Manual
Ans. Tokenization is the process of splitting text into smaller units such as words, punctuation
marks, or subword pieces.
Q. Why is preprocessing required?
Ans. Raw text contains punctuation, inconsistent casing, noise, URLs, emojis, spelling variation, and
other patterns that can reduce model quality.
Q. What is the difference between stemming and lemmatization?
Ans. Stemming uses heuristic truncation to obtain a stem, whereas lemmatization uses linguistic
knowledge to obtain a valid base form.
Q. Why should stop-word removal be task dependent?
Ans. Some frequent words carry important meaning. For example, negation words can strongly
affect sentiment.
Q. What is POS tagging?
Ans. POS tagging assigns grammatical labels such as noun, verb, adjective, or preposition to
tokens.
Q. Why compare NLTK and spaCy?
Ans. They provide different APIs, models, tokenization behavior, and linguistic processing
capabilities; comparison helps students understand practical trade-offs.
Q. What is code-mixed text?
Ans. It is text in which two or more languages are mixed within the same sentence or conversation.
Q. Why are emojis important in social-media NLP?
Ans. Emojis can convey sentiment, emotion, or context and therefore may contain useful predictive
information.
5. Conclusion
A well-designed preprocessing pipeline produces cleaner and more consistent text while preserving
task-relevant information. The practical demonstrates the complete preparation of raw text and the
differences between major Python NLP libraries.
6. References
1. Bird, Klein & Loper, Natural Language Processing with Python, O’Reilly.
2. NLTK documentation and online book.
3. spaCy documentation.
NLP Laboratory | 4
5.
PCIT404 – NaturalLanguage Processing Laboratory | Assignment Manual
Assignment 2: Regular Expressions & Text Cleaning
1. Title
Regular Expressions & Text Cleaning
2. Software Requirements
Python 3.x
Jupyter/Colab or VS Code
Python re module
pandas
csv module
PDF-to-text utility if required
optional matplotlib for analysis.
3. Theory
Regular expressions (regex) are pattern-matching expressions used to locate, validate, extract,
replace, or remove structured text patterns.
Common NLP cleaning tasks include email extraction, URL detection, phone-number normalization,
hashtag parsing, and removal of HTML/JSON tags. A reusable TextCleaner class can organize these
operations into a repeatable pipeline.
Regex patterns consist of literals, character classes, quantifiers, groups, anchors, and alternation.
Capturing groups are useful when the required information must be extracted rather than merely
detected.
In resume analytics, raw text can be transformed into structured fields such as candidate name,
email, phone number, years of experience, and skills. This is an information-extraction problem in
which deterministic patterns can provide a strong baseline.
Regex should be used carefully because natural language is variable. A production system may
combine regex with tokenization, NER, dictionaries, and validation rules.
The prescribed assignment explicitly asks for regex-based extraction/cleaning and a reusable
TextCleaner utility, with a resume-processing application producing structured CSV data.
filecite turn0file0 L50-L60
4. Frequently Asked Questions (Viva)
Q. What is a regular expression?
Ans. A regular expression is a formal pattern used to search, match, extract, or replace text.
NLP Laboratory | 5
6.
PCIT404 – NaturalLanguage Processing Laboratory | Assignment Manual
Q. Which Python module provides regex support?
Ans. Python provides regular-expression support through the built-in re module.
Q. What is a character class?
Ans. A character class matches one character from a specified set, such as digits or letters.
Q. What is the purpose of groups in regex?
Ans. Groups allow parts of a matched pattern to be captured for extraction or later processing.
Q. Why normalize phone numbers?
Ans. The same phone number may appear with spaces, hyphens, country codes, or brackets.
Normalization creates a consistent representation.
Q. Can regex understand language meaning?
Ans. No. Regex mainly recognizes surface patterns; it does not provide full semantic
understanding.
Q. Why create a TextCleaner class?
Ans. It makes cleaning operations reusable, testable, and easier to maintain.
Q. What is structured extraction?
Ans. It converts unstructured text into organized fields such as name, email, phone, and skills.
5. Conclusion
Regex provides an efficient first layer for deterministic text cleaning and information extraction.
Combining reusable patterns with validation and NLP methods creates a more robust document-
processing pipeline.
6. References
4. Python Documentation – re: Regular expression operations.
5. Jurafsky & Martin, Speech and Language Processing.
6. Bird, Klein & Loper, Natural Language Processing with Python.
NLP Laboratory | 6
7.
PCIT404 – NaturalLanguage Processing Laboratory | Assignment Manual
Assignment 3: Bag-of-Words & TF-IDF Vectorization
1. Title
Bag-of-Words & TF-IDF Vectorization
2. Software Requirements
Python 3.x
Jupyter/Colab or VS Code
NumPy
pandas
scikit-learn
matplotlib
optional seaborn for local experimentation.
3. Theory
Machine-learning algorithms generally require numerical input. Bag-of-Words (BoW) converts
documents into vectors based on word occurrence, while TF-IDF assigns higher importance to terms
that are frequent in a document but less common across the collection.
In BoW, a vocabulary is built from the corpus and each document is represented by counts of
vocabulary terms. The representation ignores word order and therefore loses some semantic and
syntactic information.
Term Frequency (TF) measures how often a term occurs in a document. Inverse Document Frequency
(IDF) reduces the importance of terms that occur in many documents. A common formulation is
IDF(t)=log(N/df(t)), where N is the number of documents and df(t) is the number of documents
containing term t.
TF-IDF is commonly formed by multiplying TF and IDF. The resulting sparse vectors can be compared
using cosine similarity, which measures the angle between two document vectors.
The syllabus requires students to implement BoW and TF-IDF from scratch, verify the results with
CountVectorizer and TfidfVectorizer, and build a document-similarity system. The specified plagiarism
example uses cosine similarity with a threshold above 0.85. filecite turn0file0 L62-L73
4. Frequently Asked Questions (Viva)
Q. What is Bag-of-Words?
Ans. BoW represents each document using counts of vocabulary terms without considering word
order.
NLP Laboratory | 7
8.
PCIT404 – NaturalLanguage Processing Laboratory | Assignment Manual
Q. What is TF?
Ans. TF represents the frequency of a term within a document, usually using a raw or normalized
count.
Q. What is IDF?
Ans. IDF measures how informative a term is across the corpus by assigning lower weight to terms
appearing in many documents.
Q. Why is TF-IDF better than raw counts in many cases?
Ans. It reduces the influence of very common terms and highlights terms that are more distinctive.
Q. What is cosine similarity?
Ans. It is a similarity measure based on the cosine of the angle between two vectors.
Q. What does sparsity mean in text vectors?
Ans. Most vocabulary positions are zero for a given document, so the vector contains many zeros.
Q. What is a major limitation of BoW?
Ans. It ignores word order and deeper semantic relationships.
Q. Why use a similarity threshold?
Ans. A threshold converts a continuous similarity score into a practical decision such as flagging
potentially similar documents.
5. Conclusion
BoW and TF-IDF provide simple, interpretable numerical representations for classical NLP. They are
especially useful as baselines for classification and document-similarity applications.
6. References
7. Bird, Klein & Loper, Natural Language Processing with Python.
8. Manning, Raghavan & Schütze, Introduction to Information Retrieval.
9. scikit-learn documentation – text feature extraction.
NLP Laboratory | 8
9.
PCIT404 – NaturalLanguage Processing Laboratory | Assignment Manual
Assignment 4: Word Embeddings – Word2Vec & GloVe
1. Title
Word Embeddings – Word2Vec & GloVe
2. Software Requirements
Python 3.x
Jupyter/Colab
Gensim
NumPy
pandas
scikit-learn
matplotlib/plotly
optional pretrained GloVe vectors.
3. Theory
Word embeddings represent words as dense numerical vectors. Unlike one-hot vectors, embeddings
can capture relationships based on distributional context.
Word2Vec learns word vectors using local context. Its common architectures are Continuous Bag-of-
Words (CBOW), which predicts a target word from context, and Skip-gram, which predicts context
words from a target word.
GloVe (Global Vectors) learns word representations from aggregated word co-occurrence statistics.
Both Word2Vec and GloVe can produce vectors in which semantically related words are located near
one another.
Cosine similarity is often used to measure semantic similarity between embeddings. Vector arithmetic
can also demonstrate relationships such as the classic king man + woman queen example,
− ≈
although results depend on training data and model quality.
Dimensionality-reduction methods such as PCA and t-SNE can project high-dimensional embeddings
into two dimensions for visualization. The syllabus requires training Word2Vec, loading pretrained
GloVe vectors, exploring analogies, and visualizing embeddings. filecite turn0file0 L74-L84
4. Frequently Asked Questions (Viva)
Q. What is a word embedding?
Ans. A word embedding is a dense vector representation of a word learned from language data.
Q. Why are embeddings better than one-hot vectors?
NLP Laboratory | 9
10.
PCIT404 – NaturalLanguage Processing Laboratory | Assignment Manual
Ans. They are compact and can encode useful similarity and relational information.
Q. What is CBOW?
Ans. CBOW predicts a target word using surrounding context words.
Q. What is Skip-gram?
Ans. Skip-gram predicts surrounding context words from a target word.
Q. What is GloVe?
Ans. GloVe is an embedding method based on global word co-occurrence statistics.
Q. How is semantic similarity measured?
Ans. Cosine similarity is a common measure for comparing embedding vectors.
Q. Why use PCA or t-SNE?
Ans. They reduce high-dimensional vectors to a small number of dimensions for visualization.
Q. What is a limitation of static embeddings?
Ans. A word generally receives one vector, so the representation may not adapt well to different
meanings in different contexts.
5. Conclusion
Word embeddings move NLP from sparse word-count representations toward dense semantic
representations. The experiment demonstrates how learned vectors support similarity, analogy,
recommendation, and visualization tasks.
6. References
10. Tunstall, Lewis, von Werra & Wolf, Natural Language Processing with Transformers.
11. Mikolov et al., Efficient Estimation of Word Representations in Vector Space.
12. Pennington, Socher & Manning, GloVe.
NLP Laboratory | 10
11.
PCIT404 – NaturalLanguage Processing Laboratory | Assignment Manual
Assignment 5: Topic Modeling using LSA / LDA
1. Title
Topic Modeling using LSA / LDA
2. Software Requirements
Python 3.x
Jupyter/Colab
Gensim
NumPy
pandas
scikit-learn
matplotlib
WordCloud
pyLDAvis (where compatible).
3. Theory
Topic modeling is an unsupervised technique for discovering recurring themes in a collection of
documents. It is useful when documents do not have predefined topic labels.
Latent Semantic Analysis (LSA) applies matrix factorization, commonly Singular Value Decomposition
(SVD), to a document-term matrix. It projects documents and terms into a lower-dimensional latent
space.
Latent Dirichlet Allocation (LDA) is a probabilistic generative model. It assumes that documents
contain mixtures of topics and topics contain probability distributions over words.
The number of topics is a key hyperparameter. Coherence scores can help compare topic
configurations, while word clouds and topic-visualization tools can make discovered themes easier to
interpret.
The prescribed application analyzes telecom customer-support tickets to identify themes such as
billing, network outages, and device issues and requires topic-trend visualization.
filecite turn0file0 L85-L95
4. Frequently Asked Questions (Viva)
Q. What is topic modeling?
Ans. It is an unsupervised approach for discovering latent themes in a document collection.
Q. What is LSA?
NLP Laboratory | 11
12.
PCIT404 – NaturalLanguage Processing Laboratory | Assignment Manual
Ans. LSA uses a matrix-reduction approach, typically SVD, to identify latent semantic dimensions.
Q. What is LDA?
Ans. LDA is a probabilistic model that represents documents as mixtures of topics and topics as
distributions over words.
Q. What does a topic contain?
Ans. A topic is represented by words with high probabilities under that topic.
Q. Why is the number of topics important?
Ans. Too few topics may merge distinct themes, while too many may split coherent themes
unnecessarily.
Q. What is topic coherence?
Ans. It is a measure used to estimate how semantically interpretable the top words of a topic are.
Q. Is topic modeling supervised?
Ans. No. Traditional LSA and LDA are unsupervised and do not require topic labels.
Q. What is a practical use of topic modeling?
Ans. It can reveal recurring themes in customer tickets, news, reviews, research papers, or support
logs.
5. Conclusion
LSA and LDA provide complementary ways to discover latent structure in text. The assignment
demonstrates how unsupervised models can transform large collections of support tickets into
actionable themes.
6. References
13. Manning, Schütze, Foundations of Statistical Natural Language Processing.
14. Gensim documentation.
15. Jurafsky & Martin, Speech and Language Processing.
NLP Laboratory | 12
13.
PCIT404 – NaturalLanguage Processing Laboratory | Assignment Manual
Assignment 6: Named Entity Recognition (NER)
1. Title
Named Entity Recognition (NER)
2. Software Requirements
Python 3.x
Jupyter/Colab or VS Code
spaCy
en_core_web_sm or en_core_web_lg
displaCy
pandas
optional Prodigy/annotation tools
domain-specific labeled data.
3. Theory
Named Entity Recognition identifies spans of text that refer to entities such as people, organizations,
locations, dates, products, drugs, or diagnoses.
NER is commonly treated as a sequence-labeling problem. A model assigns an entity category to
relevant tokens or spans while learning contextual patterns.
spaCy provides pretrained pipelines and tools for visualization through displaCy. EntityRuler can add
rule-based custom entities, which is useful when domain-specific terms are known or the pretrained
model does not recognize them.
Domain adaptation or fine-tuning can improve performance on specialized text such as medical or
legal documents. Evaluation commonly uses precision, recall, and F1-score.
The syllabus specifies spaCy NER, displaCy visualization, fine-tuning on a medical or legal dataset,
evaluation using precision/recall/F1, and custom tagging with EntityRuler. The clinical example
extracts drugs, dosages, symptoms, and diagnoses. filecite turn0file0 L96-L107
4. Frequently Asked Questions (Viva)
Q. What is NER?
Ans. NER is the task of identifying and categorizing named entities in text.
Q. What is an entity span?
Ans. It is the exact portion of text corresponding to an entity.
NLP Laboratory | 13
14.
PCIT404 – NaturalLanguage Processing Laboratory | Assignment Manual
Q. Why use a pretrained NER model?
Ans. It provides a strong starting point without requiring a model to be trained from scratch.
Q. What is EntityRuler?
Ans. It is a rule-based spaCy component for adding custom entity patterns.
Q. Why is domain-specific training needed?
Ans. Specialized documents contain terminology and entity types that general-purpose models
may not recognize reliably.
Q. What is precision?
Ans. Precision is the proportion of predicted entities that are correct.
Q. What is recall?
Ans. Recall is the proportion of true entities that the system successfully identifies.
Q. What is F1-score?
Ans. F1 is the harmonic mean of precision and recall.
5. Conclusion
NER converts unstructured documents into structured entity information. Combining pretrained
models, domain adaptation, and rule-based patterns can improve extraction in specialized
applications such as clinical information systems.
6. References
16. spaCy documentation – Named Entity Recognition.
17. Jurafsky & Martin, Speech and Language Processing.
18. Bird, Klein & Loper, Natural Language Processing with Python.
NLP Laboratory | 14
15.
PCIT404 – NaturalLanguage Processing Laboratory | Assignment Manual
Assignment 7: Sentiment Analysis using Machine Learning
1. Title
Sentiment Analysis using Machine Learning
2. Software Requirements
Python 3.x
Jupyter/Colab
pandas
NumPy
scikit-learn
IMDB dataset
matplotlib
Flask
joblib/pickle for model persistence.
3. Theory
Sentiment analysis classifies text according to expressed opinion or polarity. In this assignment, the
task is binary positive/negative classification using movie reviews.
A typical classical pipeline performs preprocessing, TF-IDF vectorization, model training,
validation/testing, and evaluation. The syllabus requires Logistic Regression, Naive Bayes, and SVM
models.
Logistic Regression estimates class probabilities using a linear decision function. Naive Bayes applies
Bayes' theorem under conditional-independence assumptions and is often effective for sparse text.
SVM learns a decision boundary that maximizes the margin between classes.
Evaluation should include accuracy, confusion matrix, and ROC-AUC. Accuracy gives overall
correctness, the confusion matrix shows error types, and ROC-AUC measures ranking quality across
decision thresholds.
The best-performing model can be exposed through a simple Flask REST API so that external
applications can submit text and receive a prediction. The prescribed real-world example is real-time
brand-sentiment monitoring. filecite turn0file0 L108-L119
4. Frequently Asked Questions (Viva)
Q. What is sentiment analysis?
Ans. It is the task of determining the sentiment or polarity expressed in text.
NLP Laboratory | 15
16.
PCIT404 – NaturalLanguage Processing Laboratory | Assignment Manual
Q. Why use TF-IDF before classical models?
Ans. It converts text into informative numerical features suitable for machine-learning algorithms.
Q. What is Logistic Regression used for here?
Ans. It is a supervised classifier that can predict sentiment from text features.
Q. What is Naive Bayes?
Ans. It is a probabilistic classifier based on Bayes' theorem with simplifying independence
assumptions.
Q. What is SVM?
Ans. Support Vector Machine finds a decision boundary with a large margin between classes.
Q. What does a confusion matrix show?
Ans. It shows counts of true positives, true negatives, false positives, and false negatives.
Q. What is ROC-AUC?
Ans. It summarizes how well a classifier separates classes across decision thresholds.
Q. Why deploy with Flask?
Ans. Flask can expose the trained model as a web API so other applications can call it.
5. Conclusion
Classical machine-learning methods provide strong, interpretable baselines for sentiment
classification. Comparing several models and deploying the best one demonstrates the complete
workflow from text features to an application service.
6. References
19. scikit-learn documentation.
20. Bird, Klein & Loper, Natural Language Processing with Python.
21. Chollet, Deep Learning with Python.
NLP Laboratory | 16
17.
PCIT404 – NaturalLanguage Processing Laboratory | Assignment Manual
Assignment 8: Transformer-based Sentiment Analysis using Hugging Face
1. Title
Transformer-based Sentiment Analysis using Hugging Face
2. Software Requirements
Python 3.x
Jupyter/Colab
Hugging Face Transformers
Datasets
PyTorch or TensorFlow
DistilBERT-compatible model/tokenizer
pandas
scikit-learn
Weights & Biases (wandb) for tracking.
3. Theory
Transformers are neural architectures based on attention mechanisms. They process contextual
relationships between tokens efficiently and have become central to modern NLP.
DistilBERT is a smaller distilled version of BERT designed to retain much of BERT's language
understanding while reducing model size and inference cost.
Fine-tuning adapts a pretrained language model to a downstream task. A tokenizer converts raw text
into model inputs such as token IDs and attention masks, and a classification head produces
sentiment predictions.
Multilingual sentiment classification requires handling multiple languages and potentially different
linguistic patterns. Model choice, training data, class balance, and evaluation methodology strongly
influence performance.
Experiment tracking tools such as Weights & Biases help record hyperparameters, metrics, runs, and
model comparisons. The syllabus requires comparison against machine-learning baselines and
tracking/optimization. filecite turn0file0 L120-L130
4. Frequently Asked Questions (Viva)
Q. What is a transformer?
Ans. A transformer is a neural architecture that uses attention mechanisms to model relationships
between tokens.
NLP Laboratory | 17
18.
PCIT404 – NaturalLanguage Processing Laboratory | Assignment Manual
Q. What is BERT?
Ans. BERT is a pretrained transformer encoder model designed to learn contextual language
representations.
Q. What is DistilBERT?
Ans. DistilBERT is a compressed/distilled BERT-style model intended to be smaller and faster.
Q. What is fine-tuning?
Ans. Fine-tuning continues training of a pretrained model on a task-specific dataset.
Q. Why is tokenization necessary?
Ans. The model operates on numerical token representations rather than raw strings.
Q. What is an attention mask?
Ans. It indicates which token positions should be considered valid inputs by the model.
Q. Why compare against classical baselines?
Ans. The comparison shows whether the transformer provides meaningful gains in accuracy,
robustness, or other metrics.
Q. Why use wandb?
Ans. It helps systematically track experiments, hyperparameters, metrics, and model versions.
5. Conclusion
Transformer fine-tuning demonstrates the transition from feature-engineered NLP to pretrained
contextual language models. The experiment emphasizes multilingual classification, fair comparison,
and reproducible experimentation.
6. References
22. Tunstall et al., Natural Language Processing with Transformers, O’Reilly, 2022.
23. Vaswani et al., Attention Is All You Need, NeurIPS 2017.
24. Hugging Face NLP Course.
NLP Laboratory | 18
19.
PCIT404 – NaturalLanguage Processing Laboratory | Assignment Manual
Assignment 9: Text Classification using Deep Learning (LSTM / BERT)
1. Title
Text Classification using Deep Learning (LSTM / BERT)
2. Software Requirements
Python 3.x
Jupyter/Colab
TensorFlow/Keras
Hugging Face Transformers and Datasets
PyTorch where required
AG-News dataset
scikit-learn
wandb
matplotlib.
3. Theory
Text classification assigns one or more labels to documents. This assignment compares a recurrent
deep-learning approach (LSTM) with a transformer approach (DistilBERT).
LSTM networks are a type of recurrent neural network designed to capture dependencies over
sequences using gates that control information flow. They can process text sequentially and maintain
hidden states.
Transformers use attention rather than recurrence to model token interactions. Fine-tuned DistilBERT
can use contextual representations learned during pretraining to classify documents.
The AG-News dataset contains news articles associated with multiple categories. A complete
experiment should compare training time, predictive accuracy, and inference speed, rather than
considering accuracy alone.
Experiment tracking is important when comparing architectures because training configuration,
hardware, preprocessing, and hyperparameters can affect results. The syllabus specifies AG-News,
LSTM/Keras, DistilBERT/Hugging Face, and wandb. filecite turn0file0 L131-L141
4. Frequently Asked Questions (Viva)
Q. What is text classification?
Ans. It is the task of assigning predefined labels to text documents.
Q. What is an LSTM?
NLP Laboratory | 19
20.
PCIT404 – NaturalLanguage Processing Laboratory | Assignment Manual
Ans. An LSTM is a recurrent neural network architecture with gates that help preserve useful
information over sequences.
Q. Why are LSTMs useful for text?
Ans. They can model sequential dependencies and context across tokens.
Q. How is BERT different from LSTM?
Ans. BERT uses transformer attention and contextual pretraining, whereas LSTM processes
sequences recurrently.
Q. What is AG-News used for?
Ans. It is a benchmark-style news classification dataset used for multi-class text classification.
Q. Why compare training time?
Ans. A model that is slightly more accurate but much more expensive may not be the best practical
choice.
Q. Why measure inference speed?
Ans. Deployment systems often have latency requirements.
Q. What should a fair comparison control?
Ans. Dataset splits, preprocessing, evaluation metrics, and reporting conditions should be kept
consistent as far as practical.
5. Conclusion
The LSTM-versus-transformer experiment highlights the evolution of neural NLP architectures and
encourages evaluation from both accuracy and deployment perspectives.
6. References
25. Chollet, Deep Learning with Python.
26. Tunstall et al., Natural Language Processing with Transformers.
27. Hugging Face NLP Course.
NLP Laboratory | 20
21.
PCIT404 – NaturalLanguage Processing Laboratory | Assignment Manual
Assignment 10: Prompt Engineering Techniques for LLMs
1. Title
Prompt Engineering Techniques for LLMs
2. Software Requirements
Python 3.x
Jupyter/Colab or VS Code
OpenAI API and/or Hugging Face LLM API
requests/httpx or provider SDK
pandas
optional evaluation libraries
secure environment-variable management.
3. Theory
Prompt engineering is the systematic design of instructions and context supplied to a large language
model (LLM) to obtain useful and reliable outputs.
Zero-shot prompting asks the model to perform a task without examples. One-shot prompting
provides one example, while few-shot prompting provides multiple examples that demonstrate the
desired behavior or output format.
Prompt templates should clearly specify the task, context, constraints, expected output format, and
evaluation criteria. Good prompts reduce ambiguity and make outputs more consistent.
Chain-of-thought-style prompting has historically been studied for complex reasoning tasks, but
applications should avoid unnecessarily exposing internal reasoning and should instead request
concise answers, intermediate structured outputs, or verifiable steps where appropriate.
Evaluation can consider correctness, relevance, completeness, consistency, format compliance, and
task-specific metrics. The syllabus requires comparing zero-, one-, and few-shot strategies and
evaluating summarization, QA, and code-generation tasks. filecite turn0file0 L142-L153
4. Frequently Asked Questions (Viva)
Q. What is prompt engineering?
Ans. It is the process of designing instructions and context to guide an LLM toward a desired
output.
Q. What is zero-shot prompting?
NLP Laboratory | 21
22.
PCIT404 – NaturalLanguage Processing Laboratory | Assignment Manual
Ans. It asks the model to perform a task without providing worked examples.
Q. What is one-shot prompting?
Ans. It provides one example of the desired task behavior.
Q. What is few-shot prompting?
Ans. It provides several examples to demonstrate the expected input-output pattern.
Q. Why use prompt templates?
Ans. Templates make prompts reusable and help maintain consistency across experiments.
Q. How can prompt quality be evaluated?
Ans. Use task-specific criteria such as factual correctness, relevance, completeness, format
adherence, and human evaluation.
Q. Why should API keys be protected?
Ans. API keys are credentials and should not be hard-coded into notebooks or shared publicly.
Q. Can a better prompt guarantee correct output?
Ans. No. Prompting can improve behavior but does not eliminate hallucination, bias, or model
limitations.
5. Conclusion
Prompt engineering demonstrates how LLM behavior can be influenced through structured
instructions and examples. Systematic comparison and evaluation are essential because prompt
quality should be measured by output quality rather than intuition alone.
6. References
28. Hugging Face NLP Course.
29. Jurafsky & Martin, Speech and Language Processing.
30. OpenAI API documentation or the documentation of the selected LLM provider.
NLP Laboratory | 22
23.
PCIT404 – NaturalLanguage Processing Laboratory | Assignment Manual
Assignment 11: RAG-based Document Question Answering System
1. Title
RAG-based Document Question Answering System
2. Software Requirements
Python 3.x
Jupyter/Colab
LangChain or equivalent orchestration library (optional)
FAISS and/or ChromaDB
sentence-transformer embedding model
BART/GPT or another selected LLM
PyPDF/document loaders
ROUGE and BLEU evaluation tools.
3. Theory
Retrieval-Augmented Generation (RAG) combines information retrieval with text generation. Instead
of relying only on a language model's parameters, the system retrieves relevant external document
chunks and supplies them as context for answer generation.
A typical RAG pipeline contains document ingestion, text chunking, embedding generation, vector
indexing, semantic retrieval, prompt construction, and answer generation.
Vector databases such as FAISS or ChromaDB store vector representations and support similarity
search. A query is embedded in the same representation space, and the top-k relevant chunks are
retrieved.
The generation model uses retrieved evidence as context. Chunk size, overlap, embedding model,
retrieval k, and prompt design affect answer quality. Evaluation can use ROUGE and BLEU where
reference answers are available, along with qualitative factuality and retrieval checks.
The prescribed application is a university student-support chatbot that answers questions about exam
schedules, admissions, and hostel rules from institutional PDF documents.
filecite turn0file0 L154-L166
4. Frequently Asked Questions (Viva)
Q. What is RAG?
Ans. RAG is a system design that retrieves relevant external information and provides it to a
generative model as context.
NLP Laboratory | 23
24.
PCIT404 – NaturalLanguage Processing Laboratory | Assignment Manual
Q. Why is chunking needed?
Ans. Large documents are divided into manageable passages so that relevant information can be
retrieved efficiently.
Q. What is an embedding?
Ans. An embedding is a numerical vector representing the semantic content of text.
Q. What is a vector database?
Ans. It is a system optimized for storing and searching vector representations.
Q. What does top-k retrieval mean?
Ans. It means retrieving the k most relevant chunks for a query.
Q. Why can RAG reduce hallucination?
Ans. Grounding the response in retrieved evidence can reduce unsupported answers, although it
does not guarantee factuality.
Q. What are ROUGE and BLEU?
Ans. They are automated text-overlap metrics commonly used for evaluating generated text
against reference text.
Q. What is a major RAG failure mode?
Ans. If retrieval returns irrelevant or incomplete evidence, the generator may produce an incorrect
or unsupported answer.
5. Conclusion
RAG provides a practical architecture for document-grounded question answering. The experiment
integrates information retrieval, embeddings, vector search, and generation into a single intelligent
application.
6. References
31. Tunstall et al., Natural Language Processing with Transformers.
32. Lewis et al., Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks.
33. FAISS/ChromaDB and Hugging Face documentation.
NLP Laboratory | 24
25.
PCIT404 – NaturalLanguage Processing Laboratory | Assignment Manual
Assignment 12: Industry Capstone – End-to-End NLP Application
1. Title
Industry Capstone – End-to-End NLP Application
2. Software Requirements
Python 3.x
spaCy and/or Hugging Face Transformers
FastAPI
Streamlit
pandas
scikit-learn
model-serving/deployment environment such as Hugging Face Spaces or AWS/GCP free tier
Git/GitHub recommended.
3. Theory
An end-to-end NLP application connects data ingestion, preprocessing, modeling, evaluation, API
serving, and user interaction into a deployable system.
The architecture should separate responsibilities: the NLP model performs inference, FastAPI exposes
REST endpoints, and Streamlit provides an interactive user interface. This separation makes the
system easier to test and maintain.
Students may implement a resume parser and job-fit scorer, fake-news detector, customer-feedback
analyzer, or legal-document classifier. Each problem requires a suitable dataset, model, evaluation
plan, and user-facing output.
A production-oriented submission should document API endpoints, model assumptions and
limitations, evaluation results, and deployment configuration. A model card communicates what the
model does, what data it was trained/evaluated on, intended use, and known limitations.
The syllabus makes this capstone compulsory and requires an end-to-end application using
spaCy/Transformers, FastAPI, Streamlit, documented APIs, a model card, an evaluation report, and
deployment on an accessible cloud/free-tier platform where feasible. filecite turn0file0 L167-
L182
4. Frequently Asked Questions (Viva)
Q. What is an end-to-end NLP application?
Ans. It is a complete system that takes user/data input, performs NLP processing and inference,
and returns usable results through an interface or API.
NLP Laboratory | 25
26.
PCIT404 – NaturalLanguage Processing Laboratory | Assignment Manual
Q. Why use FastAPI?
Ans. FastAPI provides a modern Python framework for building REST APIs and model-serving
endpoints.
Q. Why use Streamlit?
Ans. Streamlit makes it easy to create interactive data and ML web interfaces in Python.
Q. What is a model card?
Ans. A model card documents a model's purpose, data, evaluation, intended use, and limitations.
Q. Why are API endpoints documented?
Ans. Documentation allows users and developers to understand how to send inputs and interpret
outputs.
Q. What should an evaluation report contain?
Ans. It should describe the dataset, methodology, metrics, results, error analysis, and limitations.
Q. Why separate UI and API?
Ans. Separation improves maintainability, testing, reuse, and deployment flexibility.
Q. What makes a project production-oriented?
Ans. Reproducible setup, validation, error handling, documentation, evaluation, security, and
deployment considerations.
5. Conclusion
The capstone integrates the major skills developed throughout the laboratory into a deployable NLP
product. It demonstrates not only model building but also engineering, evaluation, API design, user
experience, documentation, and deployment.
6. References
34. Tunstall et al., Natural Language Processing with Transformers.
35. spaCy documentation.
36. FastAPI documentation.
37. Streamlit documentation.
38. Hugging Face documentation.
NLP Laboratory | 26
27.
PCIT404 – NaturalLanguage Processing Laboratory | Assignment Manual
Master Reference List
39. Bird, Steven; Klein, Ewan; Loper, Edward. Natural Language Processing with Python. O'Reilly
Media.
40. Rao, Delip; McMahan, Brian. Natural Language Processing with PyTorch. O'Reilly Media.
41. Tunstall, Lewis; von Werra, Leandro; Wolf, Thomas. Natural Language Processing with
Transformers: Building Language Applications with Hugging Face, Revised Edition. O'Reilly Media,
2022.
42. Jurafsky, Daniel; Martin, James H. Speech and Language Processing, 3rd Edition draft, Stanford
University.
43. Manning, Christopher D.; Schütze, Hinrich. Foundations of Statistical Natural Language
Processing. MIT Press.
44. Vaswani, Ashish et al. Attention Is All You Need. NeurIPS, 2017.
45. Chollet, François. Deep Learning with Python, 2nd Edition. Manning Publications.
46. NLTK documentation and online book.
47. spaCy documentation.
48. scikit-learn documentation.
49. Hugging Face NLP Course.
50. Stanford CS224N – NLP with Deep Learning.
51. Fast.ai NLP resources.
NLP Laboratory | 27