NLP Lab Tasks
NLP Lab Tasks
Lab Activity
Lab Task: Communicating with ChatGPT and Exploring NLP Applications
This lab focuses on interacting with ChatGPT to understand its capabilities in processing natural
language, especially when dealing with ambiguous sentences. Additionally, students will explore
different practical applications of Natural Language Processing (NLP) to gain insights into the
field's breadth and depth.
1. Interact with ChatGPT:
Begin by crafting a series of sentences that you will use to communicate with ChatGPT. Aim for
a mix of straightforward and ambiguous sentences to test the model's understanding and
contextual interpretation capabilities.
- Examples of ambiguous sentences might include:
- "Can you tell me the time the clock stopped?"
- "I saw the man with a telescope."
- "They are cooking apples."
- Record ChatGPT's responses to each sentence, noting particularly how it handles the
ambiguous ones.
2. Analyze ChatGPT's Performance:
For each interaction, analyze whether ChatGPT correctly understood the context of your
sentences, especially the ambiguous ones. Identify any patterns in responses where the model
may misinterpret the intended meaning.
3. Explore NLP Practical Applications
For each application, consider the following:
- The specific NLP techniques and models used.
- The benefits and limitations of applying NLP in this context.
- Any potential future developments or improvements in NLP that could enhance it
FACULTY OF COMPUTER SCIENCE AND ENGINEERING
Ghulam Ishaq Khan Institute of Engineering Sciences and Technology, Topi
Task Statement:
In this NLP lab task, you will work with a text file containing a collection of recipes. Your
objective is to extract four different types of information from each recipe: the amount, measure
type, ingredient, and instructions.
Instructions:
1. Read Text File:
- Begin by reading the text file containing the collection of recipes. You can use Python's file
handling capabilities or any suitable library for text file processing.
2. Extract Information:
- For each recipe in the text file, extract the following four types of information:
- Amount: The quantity of the ingredient (e.g., "1", "2.5").
- Measure Type: The unit of measurement for the ingredient (e.g., "cup", "teaspoon").
- Ingredient: The name of the ingredient (e.g., "flour", "sugar").
- Instructions: The cooking instructions or steps for preparing the recipe.
3. Data Processing:
- Utilize natural language processing (NLP) techniques, such as tokenization and part-of-
speech tagging, to extract the required information accurately.
- Consider using regular expressions to identify patterns related to amounts, measure types, and
ingredients within the recipe text.
4. Output:
- Organize the extracted information for each recipe into a structured format, such as a list of
dictionaries or a pandas DataFrame.
FACULTY OF COMPUTER SCIENCE AND ENGINEERING
Ghulam Ishaq Khan Institute of Engineering Sciences and Technology, Topi
Implementing perplexity calculation in Python or other programming languages involves the following
steps:
1. Preprocess the Text Data: As discussed in Section 2, preprocess the text data by tokenizing it,
removing stopwords and punctuation, and creating n-grams.
2. Build the Language Model: Depending on the chosen language model (e.g., n-gram model or neural
language model), build the model and estimate the probabilities of n-grams or train the neural model on
the preprocessed data.
3. Prepare the Test Dataset: Create a test dataset containing sequences of words that the language model
has not seen during training. This dataset will be used to evaluate the perplexity of the model.
4. Calculate Perplexity: For each sequence in the test dataset, calculate the probability of the sequence
using the language model. Then, compute the inverse probability and take the geometric mean across
all sequences to get the perplexity score
FACULTY OF COMPUTER SCIENCE AND ENGINEERING
Ghulam Ishaq Khan Institute of Engineering Sciences and Technology, Topi
Q. Implement Naiive byes model from scratch and solve any use case of NLP
FACULTY OF COMPUTER SCIENCE AND ENGINEERING
Ghulam Ishaq Khan Institute of Engineering Sciences and Technology, Topi