0% found this document useful (0 votes)
10 views63 pages

AI Fundamentals: Project Cycle & Ethics

The document provides a comprehensive overview of Artificial Intelligence (AI) fundamentals, covering the AI project cycle, ethical frameworks, machine learning, computer vision, and natural language processing. It details the stages of the AI project cycle, ethical considerations in AI design, and various modeling concepts including supervised, unsupervised, and reinforcement learning. Additionally, it discusses neural networks and their applications in AI, emphasizing the importance of data in training models.

Uploaded by

achintyatekade1
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)
10 views63 pages

AI Fundamentals: Project Cycle & Ethics

The document provides a comprehensive overview of Artificial Intelligence (AI) fundamentals, covering the AI project cycle, ethical frameworks, machine learning, computer vision, and natural language processing. It details the stages of the AI project cycle, ethical considerations in AI design, and various modeling concepts including supervised, unsupervised, and reinforcement learning. Additionally, it discusses neural networks and their applications in AI, emphasizing the importance of data in training models.

Uploaded by

achintyatekade1
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

📚 🧠 Artificial Intelligence Fundamentals

Overview
Brief Overview
This note covering Artificial Intelligence Fundamentals was created from a PDF
document, 181 pages. It provides a comprehensive journey from the AI project cycle and
ethical frameworks to advanced modeling concepts, machine learning fundamentals,
computer vision basics, and NLP fundamentals, all structured for easy study and review.

Key Points
Understanding the AI project lifecycle and its six stages.
Exploring ethical frameworks that guide responsible AI design.
Grasping core machine learning concepts and evaluation metrics.
Delving into computer vision techniques and no‑code tools.
Learning NLP fundamentals, from tokenisation to sentiment analysis.

Unit 1 – AI Project Cycle & Ethical Frameworks 🤖


AI Project Cycle – A systematic, six‑stage process that guides the development of an
artificial‑intelligence solution from problem identification to real‑world deployment.

1.1 Revisiting the AI Project Cycle 🔄


Stage Core Activity Key Purpose
Problem Scoping Define the problem and Clarifies the goal and sets
identify influencing boundaries.
parameters.
Data Acquisition Collect data from reliable, Provides the raw material
authentic sources. for modelling.
Data Exploration Visualise data (graphs, Helps understand
flow‑charts, maps) to spot relationships and quality.
patterns.
Modelling Select, test, and refine Determines the most
algorithms/models. efficient predictive
approach.
Evaluation Assess model performance Ensures accuracy and
on new data and improve. reliability before
deployment.
Deployment Integrate the model into Delivers tangible value to
the target environment. users and stakeholders.
Metaphor: Designing a birthday greeting card follows the same steps – ideation, material
gathering, crafting, testing, and finally gifting.

1.2 AI Domains 🌐
Statistical Data – Systems that collect large datasets, maintain them, and extract
meaningful insights for decision‑making.

Computer Vision – Enables machines to acquire, analyse, and interpret visual


information (photos, video, infrared, etc.) to make decisions.

Natural Language Processing (NLP) – Handles spoken and written human language,
extracting meaning and enabling interaction between computers and people.

Domain Typical Input Example Applications


Statistical Data Structured tables, CSV files Price‑comparison websites
(PriceGrabber, Shopzilla)
Computer Vision Images, video streams Crop‑health monitoring
with drones; surveillance
systems
NLP Text, speech Spam filters; machine
translation (Google
Translate)

1.3 Frameworks & Ethical Frameworks 📋


Framework – A step‑by‑step guide that structures problem‑solving, ensuring all
relevant factors are considered.

Ethical Framework – A systematic approach that helps ensure AI choices do not cause
unintended harm, aligning decisions with moral principles.

1.3.1 Why Ethical Frameworks Matter


The scales illustration below visualises the balance between right (✓) and wrong (✗)
outcomes in AI design.

The image highlights the need to weigh ethical considerations before releasing an AI
system.
1.4 Types of Ethical Frameworks
1.4.1 Sector‑Based Frameworks
Tailored to specific industries; they embed domain‑specific concerns (e.g., privacy in
finance, patient safety in healthcare).
Bioethics – Focuses on health‑care and life‑science applications.
1.4.2 Value‑Based Frameworks
Category Core Concern Typical Question
Rights‑Based Protection of human rights Does the system respect
and dignity individual autonomy?
Utility‑Based Maximising overall benefit, Do the benefits outweigh
minimising harm the societal risks?
Virtue‑Based Alignment with moral Are developers acting with
virtues (honesty, integrity throughout the
compassion) lifecycle?

1.5 Bioethics Principles 🩺


The circular flowchart visualises the four foundational principles.

Each principle informs ethical decision‑making in health‑related AI.


Respect for Autonomy – Users must understand and control how AI influences
them.
Non‑maleficence – Avoid causing harm; minimise negative impacts.
Beneficence – Actively promote well‑being and maximise positive outcomes.
Justice – Distribute benefits and burdens fairly across all groups.

1.6 Case Study: AI for Patient‑Risk Prediction


Issue Description
Goal Identify high‑risk patients to allocate care
resources.
Unintended Consequence Model trained on expense data
mis‑classifies patients, reinforcing regional
bias.
Root Cause Training data reflected U.S. spending
patterns, not actual health outcomes.
Bioethical Application Respect for Autonomy:
disclose algorithm logic and
data sources.
Non‑maleficence: retrain on
clinical metrics to avoid harm.
Beneficence: ensure
recommendations improve care
for all regions.
Justice: use equitable datasets
so no group is disadvantaged.

1.7 Activity Snapshot – “My Goodness”


Students explored personal biases by making charitable‑donation decisions in an online
game, revealing influences such as identity, location, and intuition. The exercise
underscored the need for explicit ethical frameworks to surface hidden biases.

1.8 Self‑Check Questions


1. Problem‑scoping purpose: Understand the project’s aim and objectives.
2. AI model domains: Statistical Data, Computer Vision, NLP (three domains).
3. Primary function of Computer Vision: Translate visual data into
machine‑readable descriptions.
4. Core focus of virtue‑based frameworks: Align actions with moral virtues.
5. Primary bioethics application domain: Healthcare and life sciences.

Unit 2 – Advanced Modeling Concepts in AI 🧠


Modeling in AI – The process of creating mathematical or rule‑based representations
that enable machines to perform tasks such as prediction, classification, or control.

2.1 Categories of AI Models


Category Description
Rule‑Based Explicitly programmed logic; no learning
from data.
Learning‑Based Algorithms improve performance by
ingesting data. Sub‑categories:
• Supervised Learning Trains on labelled examples (e.g., image
classification).
• Unsupervised Learning Discovers patterns in unlabelled data (e.g.,
clustering).
• Reinforcement Learning Learns via rewards/penalties from
interaction with an environment.

2.2 Neural Networks

Neural Network – A layered structure of interconnected nodes (neurons) that


automatically extracts features from complex datasets (e.g., images) and mimics
brain‑like processing.

Key traits:
Interconnected nodes enable hierarchical feature learning.
Efficient for large, unstructured data such as visual or audio streams.

2.3 Distinguishing AI, ML, and DL


Term Scope Typical Technique
Artificial Intelligence (AI) Umbrella concept; any Rule‑based systems, expert
system that mimics human systems.
intelligence.
Machine Learning (ML) Subset of AI; algorithms Decision trees,
that improve with support‑vector machines.
experience.
Deep Learning (DL) Subset of ML; deep neural Convolutional neural
networks with many layers. networks for image tasks.

AI provides the overarching goal, ML supplies the learning mechanism, and DL offers
the deep‑layered architecture for handling massive data volumes.

2.4 Key Takeaways


Rule‑based vs Learning‑based: Choose rule‑based for deterministic,
well‑understood processes; adopt learning‑based when patterns are complex
or data‑driven.
Supervised requires labelled data; unsupervised discovers hidden structure;
reinforcement optimises sequential decisions.
Neural networks excel in perception tasks (vision, speech) due to automatic
feature extraction.

Supporting Visuals
The image symbolises the integration of human cognition (brain) with AI‑driven city‑scale
innovations, reinforcing the curriculum’s focus on societal impact.
The three coloured plus signs represent the collaborative, multi‑stakeholder approach
encouraged throughout the AI curriculum.

Machine Learning Foundations 🧩


Machine Learning (ML) – A set of techniques that enable computers to improve their
performance on a task through experience, i.e., by learning from data rather than
following fixed instructions.

Core Idea: Input data → ML model learns patterns → Output predictions or


decisions.
The simple flowchart below visualises this pipeline:
The diagram shows how historical data enters the model, which then produces an output
after learning.
Key ML Tasks
Object Classification – Assign a label (e.g., apple or strawberry) to each
image.
Anomaly Detection – Identify data points that deviate markedly from normal
patterns (e.g., sudden heart‑rate spikes).

Deep Learning Overview 🤖


Deep Learning (DL) – A sub‑field of ML that uses multi‑layered neural networks to
automatically extract high‑level features from massive datasets.

DL models are considered the most advanced form of AI because they can
self‑train on huge amounts of data and even devise their own internal
algorithms.
Two primary DL architectures mentioned:
Architecture Typical Use
Artificial Neural Network (ANN) General‑purpose pattern learning; e.g.,
recognizing a bird from pixel data.
Convolutional Neural Network (CNN) Image‑centric tasks; learns spatial
hierarchies such as edges → shapes →
objects.

Data Fundamentals 📊
Data – Information in any form that can be processed by a computer (tables, images,
sensor readings, etc.).

Features – Columns of a dataset; each column represents an attribute (e.g.,


color, size).
Labels – The target variable attached to each example; determines what the
model should predict (e.g., fruit name).
Labeled vs Unlabeled Data
Type Description Example
Labeled Each record carries a Fruit table with Color →
tag/label. Apple/Orange labels.
Unlabeled Raw records with no A collection of bird photos
attached meaning. without species names.

Training & Testing Sets

Training set – The collection of (usually labeled) examples the model learns from.

Testing set – A separate collection used to evaluate model performance; predictions


are compared against true labels to compute accuracy.

Modeling Approaches: Rule‑Based vs Learning‑Based ⚙️


Approach How It Works Typical Example
Rule‑Based Developer encodes explicit FAQ chatbot that replies
IF‑THEN rules. only to pre‑defined
keywords.
Learning‑Based Model discovers patterns Spam filter that adapts to
from data; updates itself as evolving email content.
new data arrive.

Rule‑Based Example (Chatbot)


1. Detect keywords like “track order”.
2. Prompt for order number.
3. Retrieve status from database.
Limitation: Once deployed, the bot does not modify its behaviour when the underlying
data change.

Learning‑Based Example (Spam Filter)


1. Train on a large corpus of labeled emails (spam vs. not‑spam).
2. Model extracts discriminative features (e.g., presence of attachments, certain
words).
3. Continually refines its decision boundary as new emails are processed.

Learning Paradigms 🌱
Paradigm Data Requirement Goal
Supervised Learning Labeled data Map inputs → known
outputs (classification,
regression).
Unsupervised Learning Unlabeled data Discover hidden structure
(clustering, association).
Reinforcement Learning Interaction feedback Learn a policy that
(rewards/penalties) maximises cumulative
reward.

Visual Summary

The flowchart separates the three learning families and highlights their typical model
types.

Supervised Learning Details 📚


Supervised Learning – Models are trained on input–output pairs; the algorithm learns
a mapping from features to labels.

Sub‑Categories
Subtype Output Type Example
Classification Discrete categories Spam vs. not‑spam, animal
species.
Regression Continuous value House price, temperature
forecast.

Classification Example – Coin Recognition


Features: Weight of a coin.
Labels: Currency type (Euro, Dollar, etc.).
After training, the model predicts the correct currency from a new weight
measurement.

Shows the split between classification and regression under supervised learning.
Regression Example – House‑Price Prediction
Features: # bedrooms, carpet size, garage area.
Label: Sale price (continuous).

Unsupervised Learning Details 🔍


Unsupervised Learning – Models find patterns in data without any explicit labels.
Main Types
Type Purpose Typical Use
Clustering Group similar records Customer segmentation,
together. image grouping.
Association Discover frequent item‑set Market‑basket analysis
relationships. (e.g., “bread → butter”).

Clustering Example – Music Preference


Songs are described by tempo and intensity.
The algorithm creates two clusters: “slow‑soft” (liked) vs. “fast‑loud” (disliked).
Association Example – Grocery Recommendations
Mining purchase logs reveals that customers who buy bread often buy butter
next, enabling cross‑sell suggestions.

Reinforcement Learning 🚦
Reinforcement Learning (RL) – An agent interacts with an environment, receives a
reward signal, and learns a policy that maximises long‑term reward.

Typical Scenario: A robot learns to navigate a maze by receiving positive


feedback for reaching the goal and negative feedback for hitting walls.
Key Feature: No explicit labeled data; learning is driven solely by
trial‑and‑error and the reward structure.

Neural Networks Basics 🧠


Artificial Neural Network (ANN) – A computational model inspired by the human
brain, consisting of layers of interconnected nodes (neurons).

Structure:
1. Input Layer – Receives raw features; no processing occurs here.
2. Hidden Layers – Perform weighted summations and non‑linear
transformations; these layers are “hidden” from the user.
3. Output Layer – Produces the final prediction (class label, numeric
value, etc.).
Key Advantage: Ability to automatically extract features from raw data,
especially useful for high‑dimensional inputs like images.

Example Flow (Object Identification)


1. Pixels of an image → ANN processes through hidden layers.
2. Network learns to recognise edges, shapes, then whole objects.
3. Output: Correct label (e.g., “bird”).

Practical Checklist
Identify the learning paradigm before selecting a model (supervised ↔
unsupervised ↔ reinforcement).
Confirm data labeling: if labels exist, supervised methods are appropriate;
otherwise explore clustering or association.
Choose architecture based on task complexity:
Simple rule‑based logic for deterministic, low‑variability problems.
Deep neural networks (ANN/CNN) for image, speech, or large‑scale
pattern recognition.
Split data into training and testing sets to avoid overfitting and to gauge
real‑world performance.

3 – Neural‑Network Structure & Computation 🧩


Neural network – A computational model composed of an input layer, one or more
hidden layers, and an output layer. Each layer contains nodes (neurons) that receive
signals, apply weights and biases, pass the result through an activation function, and
forward the transformed value to the next layer.

The hidden layers perform the bulk of the computation; the number of hidden layers and
the number of nodes per layer depend on the complexity of the function the network
must learn.
The diagram visualises how information flows from the left‑most input neurons, through
two intermediate hidden layers, to the right‑most output neuron. Each connection carries
a weight that is tuned during training.
3.1 Perceptron Decision‑Making Example 🌦️
A perceptron is the simplest neural unit: it sums weighted inputs, adds a bias, and
compares the total to a threshold (often zero).
Input (X) Question Binary encoding
X1 ​
“Do you have a jacket?” 1 = yes, 0 = no
X2 ​
“Do you have an umbrella?” 1 = yes, 0 = no
X3 ​
“Is it sunny now?” 1 = yes, 0 = no
X4 “Will it rain later 1 = yes, 0 = no
(forecast)?”

Assume the following weights (based on personal experience or preference) and a bias b:
w1 = 1.5

(jacket)
w2 ​ = 1.0 (umbrella)

w3 ​ = 0.3 (sunny now)

w4 ​ = −0.5 (rain forecast)

b = −0.3

The perceptron output y is computed as


y = sgn(w1 X1 + w2 X2 + w3 X3 + w4 X4 + b)
​ ​ ​ ​ ​ ​ ​ ​
where the sign function returns 1 (go to the park) if the sum ≥ 0, otherwise 0 (stay home).
Scenario 1 – All positives
, ,
X1 = 1 X2 = 0 X3 = 1 X4 = 0 , (jacket present, no umbrella, sunny, no rain
forecast)
​ ​ ​ ​

Sum = 1.5(1) + 1.0(0) + 0.3(1) − 0.5(0) − 0.3 = 1.5 + 0 + 0.3 − 0.3 = 1.5 > 0

Output = 1 → Go to the park.


Scenario 2 – No jacket, umbrella present, not sunny, rain forecast
​ , ​ ,
X1 = 0 X2 = 1 X3 = 0 X4 = 1
​ , ​

Sum = 1.5(0) + 1.0(1) + 0.3(0) − 0.5(1) − 0.3 = 1.0 − 0.5 − 0.3 = 0.2 > 0

Output = 1 → Go to the park (the bias is low enough that the umbrella outweighs the rain
forecast).
Changing the weights or bias directly changes the decision boundary, illustrating why
different people can reach opposite conclusions from the same factual inputs.

3.2 Human‑Neural‑Network Game 🎭


A classroom activity mimics a neural network by assigning each student to a node in a
specific layer.
Layer Role Key Action
Input Observe an image (e.g., a Pass the chit to a random
fruit basket) and write one hidden‑layer node.
descriptive word on a chit.
Hidden Layer 1 Receive several chits, Reinforces or expands the
possibly add new relevant original description.
words, then forward a
single chit onward.
Hidden Layer 2 Perform the same Further abstracts the
“refinement” step as information.
Layer 1.
Output Collect all incoming chits, Comparison with the real
synthesize a short image determines success.
summary, and announce
the guessed image.
Materials required
Item Quantity
Post‑it notes enough for each student (≈ 1 per chit)
Sketch pens 1 per 5 students
Sample image (printed) 1 (shown only to the input layer)
The game enforces no verbal communication until the final reveal, forcing each “neuron”
to rely solely on the information passed via the chits—mirroring how artificial neurons
exchange weighted signals.

Students can visualise the same structure they are physically embodying.

3.3 Test‑Yourself: Multiple‑Choice Review ✅


# Question (summarised) Correct Answer
1 Data labelled with the a) Supervised Learning
desired output belongs to
which ML type?
2 Email spam filter that a) Supervised Learning
learns from labelled
examples is an example of:
3 Algorithm that groups b) Unsupervised Learning
similar customers into
clusters is used in:
4 Agent playing a game and c) Reinforcement
learning from Learning
rewards/penalties
exemplifies:
5 Statement NOT true about c) Can be less efficient
supervised learning: for large datasets
6 Unsupervised learning goal b) Identify patterns and
is to: relationships within
unlabeled data
7 Clustering algorithms are d) Grouping similar data
commonly used for: points
8 Reinforcement learning is b) Desired outcome is
useful when: clear but the path to
achieve it is unknown
9 AI playing a game and c) Reinforcement
improving by Learning
trial‑and‑error illustrates:
10 Artificial neural networks a) The human brain
are inspired by:
11 Adjusting weights to d) Training
improve performance is
called:
12 A network with multiple b) Deep Neural Network
layers of interconnected
neurons is a:
13 Neural networks excel at: b) Recognising patterns
in complex data such as
images and text
14 Training a neural network b) A significant amount
generally requires: of data and computation

3.4 Why Model Evaluation Matters 📈


Model evaluation – The systematic use of metrics to quantify how well a trained
model performs on unseen data.

Evaluation provides a report‑card for an AI system, revealing strengths, weaknesses, and


suitability for deployment.

3.4.1 Train‑Test Split


1. Split the full dataset into a training set (e.g., 80 %) and a testing set (e.g.,
20 %).
2. Train the model only on the training data.
3. Test the model on the hold‑out set; compare predictions with true labels.

The diagram shows the four steps from data division to evaluation, highlighting that the
test set must remain unseen during training to avoid over‑fitting.
3.4.2 Accuracy & Error
Accuracy

Accuracy =
Number of correct predictions

Total predictions
Error rate

Error = 1 − Accuracy

Example – Bob estimates a concert ticket price at ₹300 (actual ₹500).


Error = ∣300 − 500∣/500 = 0.4 (40 % error).
Accuracy = 1 − 0.4 = 0.6 (60 % accurate).
Accuracy alone can be misleading in imbalanced domains (e.g., medical diagnosis),
prompting the use of more nuanced metrics.

3.5 Classification Metrics & Confusion Matrix 🎯


3.5.1 Confusion Matrix Basics
A confusion matrix tabulates the counts of True Positives (TP), False Positives (FP),
True Negatives (TN), and False Negatives (FN) for binary classification.
​ Predicted = 1 Predicted = 0
Actual = 1 TP FN
Actual = 0 FP TN

The figure visualises a 2 × 2 matrix with numbers 12, 06, 04, 21 representing TP, FN, FP, TN
respectively.
From the matrix we derive:
Precision = – proportion of positive predictions that are correct.
TP

TP + FP

Recall (Sensitivity) = – proportion of actual positives that are


TP

TP + FN
captured.
F1‑Score = 2 × – harmonic mean of precision and recall.
Precision × Recall

Precision + Recall

These metrics are crucial when false negatives (e.g., missed disease) are more costly
than false positives.

3.5.2 Activity: Build a Confusion Matrix


1. List the actual and predicted labels for a small test set.
2. Count TP, FP, FN, TN.
3. Populate the matrix and compute precision, recall, and F1‑score.

3.6 Practical Accuracy Calculation – House‑Price Model


🏠
Given five sample predictions (predicted vs. actual prices), compute absolute error, error
rate, and accuracy for each, then the overall mean accuracy.

| Predicted (USD) | Actual (USD) | ∣Error∣ = ∣Pred − Act∣ | Error Rate = | Accuracy =
Error

Actual
1 − Error Rate | |----------------|--------------|----------------|--------------------------|-----------

--------| | 40 000 | 41 000 | 1 000 | = 0.0244 | 0.9756 | | 93 500 | 95 000 | 1 500 |


1 000

41 000

= 0.0158 | 0.9842 | | 110 000 | 112 000 | 2 000 | = 0.0179 | 0.9821 | | … | … |


1 500 2 000
​ ​

95 000 112 000

…|…|…|
Overall mean accuracy = average of the row‑wise accuracies (e.g., (0.9756 + 0.9842 +

0.9821 + … )/5 ).

3.7 Classification vs. Regression Recap 📊


Model Type Output Typical Metric
Classification Discrete class label Accuracy, Precision, Recall,
F1
Regression Continuous numeric value Mean Absolute Error
(MAE), Mean Squared
Error (MSE), R 2

Understanding which evaluation metric aligns with the business objective is essential for
model selection and tuning.

Confusion Matrix & Classification Metrics 📊


Confusion Matrix – A 2 × 2 table that compares the actual class of each observation
with the predicted class, allowing us to count True Positives (TP), False Positives (FP),
True Negatives (TN) and False Negatives (FN).

The matrix visualises how many “Yes” and “No” predictions were correct (green) and
incorrect (red).
Building the Confusion Matrix
1. Count rows where both Actual = Yes and Predicted = Yes → TP (top‑left cell).
2. Count rows where Actual = Yes but Predicted = No → FN (bottom‑left cell).
3. Count rows where Actual = No but Predicted = Yes → FP (top‑right cell).
4. Count rows where both Actual = No and Predicted = No → TN (bottom‑right
cell).

Cell Definitions
Cell Meaning Example from activity
TP Correctly predicted the Predicted “Yes” for a
positive class disease that was present.
TN Correctly predicted the Predicted “No” for a
negative class disease that was not
present.
FP Incorrectly predicted the Predicted “Yes” for a
positive class disease that was not
present.
FN Incorrectly predicted the Predicted “No” for a
negative class disease that was present.

Accuracy

Classification Accuracy – The proportion of all predictions that are correct.


TP +TN
Accuracy = ​

TP +TN +FP +FN

Using the matrix above:


2+5 7
Accuracy = ​ = ​ = 0.70; (70
2+5+2+1 10

Precision, Recall & F1‑Score


Metric Formula When it matters
Precision (\displaystyle \frac{TP} Reducing false positives
{TP+FP}) (e.g.,
fraudulent‑transaction
alerts).
Recall (Sensitivity) (\displaystyle \frac{TP} Reducing false negatives
{TP+FN}) (e.g., medical disease
detection).
F1‑Score (\displaystyle 2 \times Balancing precision and
\frac{\text{Precision}\times\text{Recall}}
recall when both error
{\text{Precision}+\text{Recall}}) types are costly.

Example Calculation (from the earlier matrix)


Precision = ( \frac{2}{2+2}=0.50) (50 %).
Recall = ( \frac{2}{2+1}=0.67) (67 %).
F1‑Score = (2 \times \frac{0.50 \times 0.67}{0.50+0.67}=0.57).

Choosing the Right Metric


Scenario Preferred Metric Reason
Highly imbalanced data Recall or Precision Accuracy can be
(many “No” cases) misleading; focus on the
minority class.
Spam detection – false Recall Want to catch as many
negatives allow spam spam messages as
through possible.
Legal judgments – false Precision Minimise wrongful
positives penalise innocent accusations.
General balanced tasks Accuracy (with caution) Gives a quick overall
performance snapshot.

Ethical Concerns in Model Evaluation

Evaluation Ethics – Ensuring that chosen metrics, data splits, and reporting practices
do not introduce bias or hide harms.

Accountability – Metrics must reflect the real‑world impact; e.g., high accuracy
on a balanced test set may hide poor performance for a protected group.
Transparency – Clearly disclose which metrics are used and why; avoid hiding
low‑performing sub‑groups.
Fairness – Check that metric choices do not systematically disadvantage any
demographic.
Practice Activities & Self‑Check ✅
Activity Goal Key Takeaway
Activity 3 – Compute Demonstrates why The model attains 90 %
accuracy of a “always‑Yes” accuracy can be deceptive. accuracy despite never
classifier on an unbalanced predicting the negative
test set (900 Yes, 100 No) class.
Activity 4 – Select the Apply metric‑selection Recall is crucial because
most suitable metric for a reasoning. missing a fraudulent
fraud‑detection scenario transaction (FN) is far
costlier than flagging a
legitimate one (FP).
Test‑Yourself Questions – Reinforce formula Practice solidifies
Identify TP, FP, TN, FN application. understanding of each
from given matrices; cell’s meaning.
compute precision, recall,
F1‑score.

Case Studies: Metric Computations 📈


For each case, fill the confusion matrix, then compute Accuracy, Precision, Recall, and
F1‑Score.

Case TP FP TN FN
Spam 150 50 750 50
detection
(1 000 emails)
Credit‑scoring 90 40 820 50
defaults (1 000
applicants)
Fraud 80 30 850 40
detection
(1 000
transactions)
Medical 120 20 800 60
diagnosis
(1 000
patients)
Inventory 100 50 800 0
out‑of‑stock
prediction
(1 000
products)
Metrics are computed using the formulas above; students should practice filling the table.

No‑Code AI for Statistical Data 🤖


No‑Code AI – Platforms that let users build, train and deploy AI models through visual
interfaces (drag‑and‑drop) without writing code.

What Is No‑Code AI?


Term Description
No‑Code Entire workflow is created with
point‑and‑click components; no
programming required.
Low‑Code Minimal coding is needed; users can
extend visual components with small
scripts.
High‑Code (Custom Coding) Full‑stack development; every step is
programmed manually.

Benefits
1. Accessibility – Enables non‑technical users (e.g., doctors, marketers) to create
models.
2. Speed – Drag‑and‑drop pipelines can be assembled in minutes.
3. Cost‑Effective – Reduces the need for dedicated AI engineers.
Drawbacks
Issue Impact
Lack of Flexibility Custom algorithms or fine‑tuned
hyper‑parameters may be unavailable.
Automation Bias Users may over‑trust model suggestions
without critical review.
Security Concerns Platforms may offer limited control over
data protection; unsuitable for highly
sensitive datasets.

Popular No‑Code Platforms


Platform Key Features
Azure Machine Learning (Microsoft) Cloud‑based, visual model builder,
one‑click deployment.
Google Cloud AutoML Automated model selection, REST API
export, suitable for vision, language, and
tables.
Orange Data Mining Open‑source, visual workflow editor,
extensive data‑visualisation widgets.
Lobe Desktop app, intuitive drag‑and‑drop for
image classification.
Teachable Machine (Web) Quick prototyping of image, audio, and
pose models directly in the browser.

Example Flow: Cloud AutoML Vision


The diagram shows how a user uploads a photo dataset, trains a model, and accesses
predictions via a REST API.
Scenario: Predicting Food‑Price Inflation for a Wildlife Dietitian
Problem: Forecast future prices of meat and vegetables for a zoo’s 200‑animal
diet.
No‑Code Solution: Use a platform such as Orange Data Mining or Google
Cloud AutoML to upload historical price data, select a regression model, and
obtain price forecasts without writing code.
Key Insight – The user only needs to understand the project cycle (data acquisition →
modeling → evaluation → deployment) – the platform handles algorithm selection and
training automatically.

Comparing Development Approaches


Approach Coding Required Customisation Typical Use‑Case
High‑Code Full programming Unlimited Research‑grade
(e.g., Python, Java) models, novel
architectures.
Low‑Code Minimal scripting Moderate Business analysts
for extensions who need some
bespoke logic.
No‑Code None Limited to built‑in Rapid prototypes,
components internal
dashboards,
non‑technical
teams.

Ethical Reflections on No‑Code AI


Bias Transparency – Even visual tools can embed biased datasets; users must
inspect training data.
Responsibility – Deployers remain accountable for model outcomes, regardless
of how the model was built.
Explainability – Many no‑code platforms offer limited model interpretability;
supplement with post‑hoc analysis when required.

All formulas are presented in LaTeX syntax for clear mathematical representation. The
images are integrated to illustrate key concepts such as the confusion matrix, DNA as a
data‑science metaphor, code‑free interfaces, and AutoML pipelines.

5 – Computer Vision 📸
Computer Vision – The AI sub‑domain that enables machines to interpret, analyse,
and act upon visual information (images, video, infrared, etc.) in a way that mimics
human perception.

5.1 Core Concepts

Feature Extraction – The process of turning raw pixels into meaningful descriptors
(edges, corners, textures) that a model can use.

Object Detection – Locating and classifying objects within an image, often producing
bounding boxes.

Image Segmentation – Partitioning an image into regions (semantic or instance) so that


each pixel is assigned a class label.

5.2 Computer Vision vs. Image Processing


Aspect Computer Vision Image Processing
Goal Derive high‑level Enhance or transform pixel
understanding (what is in data (e.g., resizing,
the image). filtering).
Typical Output Class labels, bounding Sharper image, corrected
boxes, masks. colour, compressed file.
Typical Tasks Face recognition, Noise reduction, contrast
autonomous driving, adjustment.
medical imaging.

5.3 Real‑World Applications


🛂 Facial Recognition – Security checkpoints, attendance systems.
🎭 Face Filters – Instagram, Snapchat augmentations.
🔍 Google Image Search – Query‑by‑image retrieval.
🚜 Precision Agriculture – Drone‑based crop health monitoring.
🏥 Medical Imaging – Tumour detection in X‑rays or MRIs.
5.4 No‑Code Platforms for Vision
Platform Main Strength Typical Use‑Case
Orange Data Mining Drag‑and‑drop widgets; Rapid prototyping of
visual workflow; supports classification/regression
both tabular and image pipelines.
data.
Lobe Automatic model training; Custom image classifiers
export to mobile/web for apps without coding.
apps.
Teachable Machine Browser‑based; instant Quick demos, educational
model generation from projects, simple gesture
webcam or uploads. recognition.

Ethical note – Even visual models can inherit bias from training images; always audit
datasets for representation and privacy concerns.
5.5 Orange Data Mining – Step‑by‑Step Vision Workflow
The following workflow builds a price‑prediction model for a zoo’s animal‑feed budget.
The same sequence applies to any supervised vision task (e.g., classifying penguin
species).
1. Download the dataset (FAO Food Price Index).
2. Open Orange → double‑click the Orange icon.

The initial view shows a blank canvas where widgets will be placed.
3. Upload the dataset – drag the File widget (Data → File) onto the canvas and
browse to the CSV file.
The green arrows illustrate moving a widget from the left panel to the central
canvas.
4. Inspect the data – connect File → Data Table and open the table to verify that
the target variable is Food Price Index.

The table view confirms correct column selection; the diagram hints at the
upcoming pipeline.
5. Select the model – add the Linear Regression widget (Model → Linear
Regression) and connect it to File.
The red‑circled “Linear Regression” node indicates the algorithm chosen for
regression.
6. Evaluate performance – place Test & Score (Evaluate → Test & Score) and link
both File and Linear Regression to it.

The diagram visualises the split into training and hold‑out test sets, followed by
metric calculation.
7. Generate predictions – add the Prediction widget, connect it to Test & Score,
and inspect the output table for the forecasted price index.
The final prediction can be exported or used to inform the zoo’s budgeting
plan.

5.6 Statistical Foundations for Vision Projects


Concept Why It Matters for Vision
Statistical Sampling Large image collections are often
impractical to label entirely; a
representative subset (the sample)
enables model training while preserving
population characteristics.
Descriptive Statistics Summaries such as mean pixel intensity,
median colour channel, or mode of class
labels help spot data quality issues before
training.
Distributions Histograms of feature values (e.g., edge
lengths) reveal skewness that may affect
model assumptions.
Variance & Standard Deviation Measure how spread out pixel‑level
features are; high variance may indicate
noisy images needing preprocessing.
Outliers Images with extreme illumination or
occlusion can act as outliers; identifying
them prevents distortion of learned
patterns.

Mind‑Map Activity – Students created a digital mind map (see image below) to
organise where mean, median, and mode appear in real‑life contexts (e.g., average
temperature, most common shoe size).
The visual shows how statistical ideas interlink, reinforcing their relevance to data‑driven
AI.

5.7 Excel Linear Regression Mini‑Project


1. Enable the Analysis ToolPak – File → Options → Add‑ins → Analysis ToolPak →
Go → check.
2. Load the Speed‑vs‑Distance sheet; create a Scatter Plot to visualise the
relationship.
3. Add a Trendline → Linear → display equation and R on the chart.
2

4. Run the Regression via Data → Data Analysis → Regression; set Distance as
the dependent variable and Speed as the independent variable.
5. Interpret the output – the coefficient for Speed gives the slope; the intercept
is the constant term. Use the equation Distance = β + β × Speed to predict
0 1

distances for new speeds.


​ ​

5.8 Case Study – Palmer Penguins Species Classification


Stage Action
Problem Scoping Predict the species of a penguin from
measurable traits (flipper length, bill
dimensions, body mass, etc.).
Data Acquisition Download the Palmer Penguins dataset
(CSV) from the provided URL.
Data Exploration Clean missing entries, select the target
label Species, and sample the data for
faster iteration.
Modelling Use Orange – drag File → Data Table →
Linear Regression (or Logistic Regression
for classification) → Test & Score.
Evaluation Examine accuracy, precision, and the
confusion matrix (see example below).
Prediction Apply the Prediction widget to new,
unlabeled penguin measurements.

Feature Overview

Feature Description
Culmen Length Length of the penguin’s bill (mm).
Culmen Depth Depth of the bill (mm).
Flipper Length Length of the wing‑like flipper (mm).
Body Mass Weight of the bird (g).
Sex Male / Female (categorical).
Confusion matrix example (from a previous classification task)

The matrix visualises true/false positives and negatives, from which precision, recall, and
F1 ​ can be derived.
TP
Precision = ​

TP + FP
TP
Recall = ​

TP + FN
TP + TN
Accuracy = ​

TP + TN + FP + FN

5.9 Evaluation Recap for Vision Models


Accuracy is useful when classes are balanced.
Precision matters for tasks where false positives are costly (e.g., medical
anomaly detection).
Recall is critical when missing a positive case is dangerous (e.g., wildlife
poaching detection).
F1‑Score balances precision and recall for uneven class distributions.

Ethical reminder – Report all relevant metrics; a high overall accuracy can mask poor
performance on minority species in the penguin dataset.

5.10 Test‑Yourself
# Question Answer
1 Define feature extraction in Transforming raw pixel
a single sentence. data into informative
descriptors such as edges
or colour histograms.
2 Which metric is most Recall
appropriate when false
negatives are far more
harmful than false
positives?
3 In Orange, which widget Scatter Plot
visualises the relationship
between two numeric
variables?
4 List two advantages of Rapid prototyping and
no‑code tools for accessibility for
computer‑vision projects. non‑technical users.
5 Name three statistical Mean pixel intensity,
concepts that help assess variance (or standard
the quality of an image deviation), and outlier
dataset. detection.
6 True or false: The Linear False
Regression widget can be
used for classification
tasks.
7 What does the Data It creates a random subset
Sampler widget do? of the loaded data for
quicker experimentation.
8 Provide the formula for F 1 ​
F1 = 2 ×

‑score using LaTeX. Precision × Recall


Precision + Recall

9 Which platform allows Lobe


export of a trained model
directly to a mobile app
without writing code?
10 In the Palmer Penguins Sex (categorical).
case, which feature is not a
numeric measurement?

5.11 Ethical Reflections on No‑Code AI


Transparency – Drag‑and‑drop interfaces often hide algorithmic details;
documentation of the selected widget (e.g., Logistic Regression) is essential.
Bias Amplification – Using pre‑packaged datasets (e.g., FAO price index)
without demographic checks can propagate regional inequities.
Responsibility – Even though coding is minimal, the developer (or project lead)
remains accountable for model outcomes and must conduct thorough
evaluation.
Unit 6 – Natural Language Processing 🌐
6.1 What Is a Natural Language?

Natural language – a human‑made system of communication (e.g., English, Spanish,


Japanese) that follows linguistic rules such as syntax, lexicon, and semantics.

Key Features of Natural Languages


Feature Description
Rule‑based Governed by syntax (sentence structure),
lexicon (vocabulary) and semantics
(meaning).
Redundancy The same idea can be expressed in many
different ways.
Evolving New words, usages, and meanings appear
over time.

6.2 Why NLP Matters – Real‑World Applications


Chatbots & Virtual Assistants – interpret user queries and generate
responses.
Sentiment Analysis – gauge public opinion from reviews, tweets, or surveys.
Machine Translation – convert text from one language to another (e.g., Google
Translate).
Information Retrieval – power search engines and document classification.
Speech‑to‑Text & Text‑to‑Speech – enable accessibility and voice‑controlled
devices.

6.3 Typical NLP Pipeline (Stages)


1. Data Collection – gather raw text (documents, tweets, transcripts).
2. Pre‑processing – clean and standardise the text (see § 6.4).
3. Feature Extraction – convert text into numeric representations (Bag‑of‑Words,
TF‑IDF, embeddings).
4. Modeling – apply supervised, unsupervised or deep‑learning algorithms.
5. Evaluation – use metrics such as accuracy, F1‑score, or BLEU (for translation).
6. Deployment – integrate the model into an application or API.
6.4 Text‑Processing Techniques
Technique Purpose Typical Operation
Tokenisation Split text into words, The quick brown fox →
sub‑words, or characters. [The, quick, brown, fox]
Lowercasing Reduce case variance. Apple → apple
Stop‑word Removal Discard high‑frequency, Improves model focus on
low‑information words content words.
(e.g., “the”, “and”).
Stemming / Reduce words to their base running → run, better →
Lemmatization form. good
Punctuation & Noise Strip symbols, numbers, Cleans data for
Removal HTML tags, etc. downstream modeling.
N‑grams Capture local word order ["quick brown", "brown
(bigrams, trigrams). fox"]

Pre‑processing importance – Consistent cleaning ensures that the same semantic


content is represented identically across the dataset, which is crucial for reliable
feature extraction and model training.

6.5 No‑Code NLP Tools


Tool Core Capability Typical Use‑Case
Orange Data Mining (NLP Drag‑and‑drop Rapid prototyping of
add‑on) text‑pre‑processing, sentiment or topic models.
Bag‑of‑Words, TF‑IDF,
classification widgets.
Lobe Auto‑ML for text Building a custom intent
classification (supports recogniser without code.
labelled examples).
Teachable Machine Browser‑based model Classroom demos of simple
builder for text (and spam vs. ham classifiers.
image/audio) classification
using [Link].
Google Cloud AutoML Managed service for entity Scalable production‑grade
Natural Language extraction, sentiment pipelines.
analysis, and content
classification.
Ethical reminder: Even with no‑code interfaces, developers remain responsible for data
bias, privacy, and model interpretability.

6.6 Bag‑of‑Words (BoW) Model

Bag‑of‑Words – a representation that treats a document as an unordered multiset of


its words, ignoring grammar and word order.

Construction Steps
1. Build a vocabulary of all unique tokens across the corpus.
2. For each document, count the occurrences of each vocabulary term →
frequency vector.
Strengths – simple, fast, works well for many classic text‑classification tasks.
Limitations – loses contextual information; high‑dimensional for large
vocabularies.

6.7 Term Frequency‑Inverse Document Frequency (TF‑IDF)

TF‑IDF – a weighting scheme that reflects how important a word is to a document


relative to the entire corpus.

Formula
$ \text{TF‑IDF}(t,d) = \underbrace{\frac{\text{count}(t,d)}{\text{total words in }d}}
{\text{Term Frequency (TF)}} \times \underbrace{\log!\left(\frac{N}{\text{df}(t)}\right)}
{\text{Inverse Document Frequency (IDF)}} $
where
t= term, d = document,
N = total number of documents,
df(t)= number of documents containing term t .
Interpretation – Frequently occurring words in a specific document get high
weight, while ubiquitous words across many documents (e.g., “the”) receive low
weight.

6.8 Sentiment Analysis

Sentiment analysis – the process of classifying textual opinion into categories such as
positive, negative, or neutral.

Typical workflow
1. Pre‑process text (tokenise, remove stop‑words).
2. Convert to BoW or TF‑IDF vectors.
3. Train a supervised classifier (e.g., logistic regression, SVM).
4. Evaluate using accuracy, precision, recall, or F1‑score.
Applications – brand monitoring, customer support triage, market research.

6.9 Learning Objectives Recap


Explain why preprocessing is essential for NLP.
Identify each stage of an NLP pipeline.
List at least three no‑code NLP platforms and their primary strengths.
Describe how the Bag‑of‑Words model is built and its limitations.
Compute TF‑IDF values using the provided formula.
Outline the steps of a sentiment‑analysis project from raw data to deployment.

6.10 Test‑Yourself (Selected Items)


# Question Correct Choice / Answer
1 Choose the correctly break
spelled word for “break”.
2 In the sentence “His face ​
turned red after he…”, the
phrase most likely means
he felt ashamed
(emotional response)
rather than a physical
reaction.
3 Which NLP task involves Image classification
assigning one label from a analogue → Text
fixed set to an entire classification
document? (Bag‑of‑Words)
4 What does the pixel value Brightness (0 = black,
represent in a grayscale 255 = white)
image?
5 The core purpose of the ​
ReLU activation in a CNN
(mentioned earlier) is to
remove negative values
while keeping positives.
(Relevant because many
NLP models now use ReLU
in deep architectures.)
6 Object detection vs. image ​
classification: Object
detection is more complex
because it must both
classify and locate
objects.
7 Grayscale images consist ​
of a single byte per pixel;
their size is determined by
height × width.
8 In an RGB image, a pixel ​
with R = 255, G = 0, B = 0
represents pure red (full
intensity of the red
channel, none of green or
blue).
9 Which no‑code tool lets Orange Data Mining
you build a
text‑classification model by
simply uploading labelled
CSV files?
10 TF‑IDF down‑weights ​
words that appear in many
documents across the
corpus.

6.11 Reflection Prompt (No‑Code NLP in Practice)


Identify the technology used when a smartphone app recognises a dog from a
photo. → Computer vision (image classification) combined with a pre‑trained
CNN; the app’s back‑end often uses a REST API that returns the predicted
label.
Two smartphone apps that employ NLP
1. Google Assistant – parses spoken commands into intents via
speech‑to‑text + intent classification.
2. Grammarly – analyses written text for grammar, style, and sentiment
using deep‑learning language models.
How does an RGB image differ from a grayscale image?
RGB stores three separate channels (R, G, B) → three bytes per pixel
→ colour information.
Grayscale stores a single channel → one byte per pixel → only
intensity.
6.12 Connecting Vision & Language (Cross‑Domain Insight)
Image captioning combines computer vision (extract visual features via CNN)
with NLP (generate descriptive text using sequence‑to‑sequence models).
The Bag‑of‑Words concept parallels the feature maps produced by early CNN
layers: both treat raw inputs as unordered collections of elementary elements
(words vs. pixels) before higher‑level abstraction.

All formulas are presented in LaTeX syntax for clarity. The notes maintain the same visual
style (bold keywords, blockquote definitions, tables) as earlier sections, enabling seamless
integration into the overall study guide.

6.1 Natural Language Ambiguity 🌈


Natural language – the everyday spoken or written language humans use, where a
single word can carry several meanings that are resolved by context.
Example: the word red can refer to a colour, a political affiliation, or a warning sign
depending on the surrounding sentence.

6.2 Computer Languages & Why NLP Matters 💻


Computer language – a formal language (e.g., Python, Java, HTML) that a machine
can interpret directly.

Natural‑Language Processing (NLP) – a set of techniques that translate human


language into a format computers can manipulate (binary/electrical signals).

Computers only understand binary; NLP bridges the gap between human intent
and machine‑readable data.
The goal is to enable seamless human‑computer communication.

6.3 Key Reasons for Using NLP 🔧


NLP converts unstructured linguistic input into structured digital representations,
making it possible to:

Capture intent and context.


Build tools such as voice assistants, auto‑generated captions, and real‑time
translation.

6.4 Demystifying NLP 📚


NLP is the AI sub‑field that analyses, understands, and derives meaning from human
language, turning raw text or speech into actionable information.

6.5 Everyday Applications of NLP 🌐


Application Real‑world example
Auto‑generated captions YouTube and Google Meet transcribe
spoken content into subtitles.
Voice assistants “Hey Google, set an alarm for 7 am.”
Language translation Google Translate converts text between
languages.
Sentiment analysis Brands monitor customer emotions
(positive, negative, neutral).
Chatbots Customer‑service bots answer queries and
collect leads.

6.6 Activity 1 – Keyword Extraction 🗝️


The diagram below shows how news articles are routed into topical categories.

The flowchart visualises the automatic identification of the most frequent and meaningful
words that define each article’s topic.
Purpose: Highlight the most informative terms in a text corpus, useful for
summarisation, content recommendation, and market‑trend analysis.

6.7 Stages of Natural Language Processing 🧩


Stage Core task
Lexical analysis Split raw text into sentences, paragraphs,
and words (the lexicon).
Syntactic analysis / parsing Verify grammatical structure and
relationships among words.
Semantic analysis Ensure each word and phrase conveys a
plausible meaning (e.g., reject “hot
ice‑cream”).
Discourse integration Link sentences to form a coherent story;
resolve pronouns such as “it”.
Pragmatic analysis Infer the speaker’s intent beyond literal
meaning (e.g., “I’m just pulling your leg” →
joking).
The flowchart below maps these stages and additional checks (grammar, sarcasm).

Each red box represents a processing stage; arrows indicate the sequential flow from raw
text to nuanced understanding.

6.8 Quick Check


Question Options
Syntax refers to the grammatical YES / NO
structure of a sentence.
Which analysis assesses the Pragmatic Analysis / Lexical Analysis /
meaningfulness of input text? Semantic Analysis / Discourse Integration
6.9 Chatbots 🤖
6.9.1 What is a chatbot?

Chatbot – a software program that simulates conversation with users via text or voice,
handling queries, troubleshooting, lead generation, and sales support.

6.9.2 Types of Chatbots


Type Characteristics Typical effort
Script bot Follows a predefined Minimal coding; quick
decision tree; easy to integration.
build; limited flexibility.
Smart bot Leverages large knowledge Requires coding and larger
bases and datasets.
machine‑learning; learns
from data; more functional.

6.9.3 Exploration Activity


Interact with any of the listed bots (e.g., ELIZA, Cleverbot, Mitsuki). Reflect on:
Bot purpose.
Naturalness of the conversation.
Presence of a distinct personality.

6.10 Quiz 📋
Statement Answer
NLP primarily deals with numeric, textual, ✔︎
image, and visual data.
Sentiment analysis expresses an opinion ✔︎
as positive, negative, or neutral.
First NLP stage is Lexical Analysis. ✔︎
“Stop words” are high‑frequency terms ✔︎
with little semantic value.
Discourse integration identifies ✘ (it links sentences).
individual words.

6.11 Text Processing Overview 📄


Human language is rich and ambiguous; computers require a numerical representation.
The first step toward that is Text Normalisation, which reduces linguistic complexity to a
form that algorithms can handle.

6.12 Text Normalisation Steps


1. Sentence segmentation – split the whole corpus into individual sentences.
2. Tokenisation – break each sentence into tokens (words, numbers,
punctuation).
3. Removal of stop words, special characters, and numbers – discard
high‑frequency, low‑value tokens; optionally keep symbols if they carry
meaning (e.g., email addresses).
4. Case normalisation – convert all tokens to a common case (usually lowercase)
to avoid treating “Hello” and “hello” as distinct.
5. Stemming – strip affixes to obtain a crude root form.
Word Stem
healed heal
healing heal
studying studi
6. Lemmatization – like stemming but returns a meaningful lemma (dictionary
form).
Word Lemma
healed heal
studying study
caring care

6.13 Bag of Words Model 📚


Bag‑of‑Words (BoW) – a feature‑extraction technique that records the frequency of
each unique word in a document, ignoring order.

Implementation outline
Step Action
1. Collect & preprocess documents. e.g., three short sentences about “Aman”,
“Avni”, and “chatbot”.
2. Build a dictionary of unique tokens. {aman, avni, stressed, went, download,
health, chatbot, therapist}
3. Create document vectors – count ​
occurrences of each dictionary term per
document.
4. Assemble the vocabulary‑frequency ​
matrix.
The resulting matrix supplies the raw numerical input for downstream ML algorithms.

6.14 Term Frequency –


Inverse Document Frequency (TF‑IDF)
TF‑IDF quantifies how important a word is to a particular document relative to the
entire corpus.

Term Frequency (TF)


count(w in d)
TF(w, d) = ​

total words in d
Inverse Document Frequency (IDF)
N
IDF(w) = log! ( ​ )
df(w)

where N is the total number of documents and df(w) is the number of


documents containing w .
TF‑IDF

TF IDF(w, d) = TF(w, d) × IDF(w)

Interpretation
High TF + low DF → high TF‑IDF → word is specific and informative for that
document (e.g., “pollution” in a pollution‑focused article).
High DF across all documents → low IDF → the term behaves like a stop word
(e.g., “and”).

6.15 Typical TF‑IDF Applications


Use‑case How TF‑IDF helps
Topic modelling Highlights discriminative terms that define
each topic.
Stop‑word filtering Low TF‑IDF scores identify words to drop.
Document classification Feature vectors derived from TF‑IDF feed
supervised classifiers.
Information retrieval Ranks documents by relevance to a query
based on TF‑IDF similarity.

6.16 Sentiment Analysis Walkthrough 🗣️


The illustration below captures the idea of detecting sentiment from speech bubbles.
The image shows how textual expressions are examined to decide whether the underlying
opinion is positive, negative, or neutral.
Workflow (using Orange Data Mining)
1. Import a corpus of customer comments.
2. Apply Text Normalisation (steps from 6.12).
3. Convert to TF‑IDF vectors.
4. Train a sentiment classifier (e.g., logistic regression).
5. Evaluate with accuracy, precision, recall, and F1‑score.

6.17 NLP Toolbox


Category Tools Typical capabilities
Code‑based NLTK (Python) – Full‑programmatic control;
tokenisation, stemming, custom pipelines.
POS tagging.
spaCy – fast tokenisation,
dependency parsing,
named‑entity recognition.
No‑code Orange Data Mining – Rapid prototyping; minimal
drag‑and‑drop text widgets coding.
(preprocess, BoW, TF‑IDF,
classification).
MonkeyLearn – web UI for
building custom classifiers
and sentiment models.

6.18 Test‑Yourself
# Question Correct Answer
1 Primary challenge for Complexity of human
computers in languages
understanding human
language?
2 How do voice assistants To understand natural
use NLP? language
3 Which step is not part of Document summarisation
Text Normalisation?
4 Purpose of tokenisation? To segment sentences
into smaller units
5 What distinguishes Lemmatization produces
lemmatization from meaningful words after
stemming? affix removal, while
stemming does not
6 Main goal of the To extract features from
Bag‑of‑Words model? text for machine‑learning
algorithms
7 In TF‑IDF, stop words are … Words with frequent
occurrence in the corpus
that are often removed
during preprocessing
8 Rare, valuable words … Occur the least but add
the most value to the
corpus

Document‑Term Matrix Overview 📊


Document‑Term Matrix – a tabular representation where rows correspond to
documents and columns correspond to distinct terms (words). Each cell contains the
frequency of that term in the specific document.

The matrix does not aggregate frequencies across the whole corpus, count
total words, or compute average word length.
Correct answer: frequency of each word in a single document (option B).

TF‑IDF Purpose and Interpretation 🎯


TF‑IDF (Term Frequency‑Inverse Document Frequency) assigns a weight to each
term in each document that reflects how important the term is for that document
relative to the entire corpus.

Term Frequency (TF) captures how often a word appears in a document.


Inverse Document Frequency (IDF) down‑weights terms that appear in many
documents (common words) and up‑weights rare, discriminative words.
The primary purpose is to identify the value (importance) of each word in a
document (option C).

Pragmatic Analysis in NLP 🧩


Pragmatic analysis – the stage of natural‑language processing that evaluates a
sentence for its real‑world applicability and the speaker’s intended effect, beyond
literal meaning.

Assertion / Reasoning
Assertion: Pragmatic analysis involves assessing sentences for practical
applicability.
Reasoning: It requires understanding nuanced meaning and logical
implications, not just literal semantics.
Both statements are true, and the reasoning correctly explains the assertion (option A).

Importance of Lowercasing & Stop‑Word Removal 🔤


Converting all text to lowercase after removing stop words is a crucial preprocessing
step because it ensures uniform word representation; the model will not treat “Apple”
and “apple” as distinct tokens.

Both the assertion and the reasoning are true, and the reasoning explains the assertion
(option A).

Reflection Prompts – Core NLP Concepts ❓


Prompt Key Point
What is the significance of NLP? Enables machines to interpret, analyse,
and act upon human language, bridging
the gap between unstructured text and
structured data.
What do we mean by lexical analysis? > Lexical analysis – the process of
segmenting raw text into basic units
(sentences, words, tokens) that form the
foundation for downstream NLP tasks.
What is a chatbot? > Chatbot – a software agent that
simulates conversation with users via
text or voice, handling queries, providing
information, or performing actions.
What does the “Bag of Words” model > Bag of Words – a representation that
refer to? records term frequencies for each
document while ignoring word order and
syntax.
Describe two practical NLP use‑cases. 1. Sentiment analysis for brand
monitoring. 2. Automatic email routing
(spam detection, priority classification).
Explain stemming vs. lemmatization See the Stemming vs. Lemmatization
(with example). section below.
List any four applications of TF‑IDF. 1. Document classification. 2. Information
retrieval (search ranking). 3. Topic
modelling. 4. Feature weighting for
clustering.
Stemming vs. Lemmatization 🔧
Stemming – crude reduction of words to a root form by chopping affixes; the result
may not be a valid word.
Lemmatization – morphological analysis that returns the dictionary (lemma) form,
preserving meaning.

Word (original) Stemmed form Lemmatized form


healed heal heal
healing heal heal
studying studi study
caring care care
Stemming is faster but can produce non‑words.
Lemmatization is more accurate for downstream tasks that depend on proper
lexical semantics.

TF‑IDF Applications 📈
Application How TF‑IDF Helps
Document Classification Provides discriminative term weights for
classifiers (e.g., Naïve Bayes, SVM).
Search Engine Ranking Scores query‑document similarity based
on weighted term overlap.
Topic Modelling Highlights terms that uniquely define each
topic.
Spam Detection Emphasises rare words that are
characteristic of spam messages.

Text Normalisation Walkthrough ✂️


Original Documents
1. Document 1: “Akash and Ajay are best friends.”
2. Document 2: “Akash likes to play football but Ajay prefers: play online games.”
Step‑by‑step normalisation
1. Sentence segmentation – each document is already a single sentence.
2. Tokenisation – split on whitespace and punctuation.
3. Lowercasing – convert every token to lowercase.
4. Stop‑word removal – discard common function words (e.g., and, are, to, but,
the).
5. Punctuation & special‑character removal – strip commas, colons, periods.
Normalized output
Document 1: akash ajay best friends
Document 2: akash likes play football ajay prefers play online games
These tokens can now be fed into a Bag‑of‑Words or TF‑IDF pipeline.

TF‑IDF Calculation Example 🧮


Corpus (4 documents)
Doc ID Text
D1 “Johny Johny Yes Papa”
D2 “Eating ug?r? No Papa”
D3 “Telling lies? No Papa”
D4 “Open Mot mouth; Hal Hal Hal”

1. Pre‑process
Lowercase, remove punctuation, tokenise.
Doc Tokens
D1 johnny johnny yes papa
D2 eating ug?r? no papa
D3 telling lies no papa
D4 open mot mouth hal hal hal

2. Build Vocabulary
{johnny, yes, papa, eating, ug?r?, no, telling, lies, open, mot, mouth, hal}
(12 unique terms)

3. Term Frequency (TF) – raw counts per document


Term D1 D2 D3 D4
johnny 2 0 0 0
yes 1 0 0 0
papa 1 1 1 0
eating 0 1 0 0
ug?r? 0 1 0 0
no 0 1 1 0
telling 0 0 1 0
lies 0 0 1 0
open 0 0 0 1
mot 0 0 0 1
mouth 0 0 0 1
hal 0 0 0 3

4. Document Frequency (DF)


Number of documents containing each term:
Term DF
johnny 1
yes 1
papa 3
eating 1
ug?r? 1
no 2
telling 1
lies 1
open 1
mot 1
mouth 1
hal 1

5. Inverse Document Frequency (IDF)


Using IDF(t) = log! ( N

DF(t)

) with N = 4 :

Term IDF
johnny log! (
4

1
​ ) = log 4

yes log 4

papa log! (
4

3
​ ) = log
4

3

eating log 4

ug?r? log 4

no log! (
4

2
​ ) = log 2

telling log 4

lies log 4

open log 4

mot log 4
mouth log 4

hal log 4

(Values can be left symbolic or approximated; e.g., ,


log 4 ≈ 1.386 log 2 ≈ 0.693 log , 4

3

0.288 .)
6. TF‑IDF weights (TF × IDF)
Term D1 D2 D3 D4
johnny 2!×! log 4 0 0 0
yes 1!×! log 4 0 0 0
papa 1!×! log
4

3

1!×! log
4

3

1!×! log
4

3

0
eating 0 1!×! log 4 0 0
ug?r? 0 1!×! log 4 0 0
no 0 1!×! log 2 1!×! log 2 0
telling 0 0 1!×! log 4 0
lies 0 0 1!×! log 4 0
open 0 0 0 1!×! log 4

mot 0 0 0 1!×! log 4

mouth 0 0 0 1!×! log 4

hal 0 0 0 3!×! log 4

These weighted vectors can now be used for similarity scoring, classification, or
clustering.

Answer Keys for “Test‑Yourself” Sections ✅


Unit / Section Question # Correct Option
Ethical Frameworks 7 B
Advanced Modelling 9 4
Evaluating Models 3 A
Statistical Data (UNL_4i) 1 4.4
Statistical Data (UNL_42i) 1 B
Statistical Data (UNL_42i) 2 B
Statistical Data (UNL_42i) 3 4
Statistical Data (UNL_42i) 4 C
Computer Vision 1 B
Computer Vision 5 €
Computer Vision 6 4
Computer Vision 11 4
Computer Vision 12 €
Natural Language 1 4
Processing
Natural Language 2 C
Processing
Natural Language 3 D
Processing
Natural Language 4 B
Processing
Natural Language 5 4
Processing
Natural Language 6 B
Processing
Natural Language 7 B
Processing
Natural Language 8 C
Processing
Natural Language 9 4
Processing
Natural Language 10 €
Processing
Natural Language 11 4
Processing
Natural Language 12 4
Processing

You might also like