Lets Learn AI Base Module PDF
Lets Learn AI Base Module PDF
Lets Learn AI Base Module PDF
LET’S LEARN
ARTIFICIAL
INTELLIGENCE
FEBRUARY 2020 | BASE MODULE
1
DR. RAJIV
KUMAR
VICE CHAIRMAN,
NITI AAYOG
SHRI
AMITABH
KANT
CEO,
NITI AAYOG
SHRI
RAMANATHAN
RAMANAN
MISSION DIRECTOR
ATAL INNOVATION MISSSION,
NITI AAYOG
DEBJANI GHOSH
President, NASSCOM
It has been estimated that by 2030, the global market in AI is likely to be in the
range of 15 – 15.5 trillion dollars out of which India’s share will be close to a trillion.
The next generation of young Indians will obviously want to challenge the “status
quo” and there’s no gainsaying, they’ll not remain contented with a trillion-dollar
share. Most certainly, they will aim much higher – 2X, 3X or even 5X – to prove ana-
lysts wrong. Frankly, they will be limited only by the magnitude of their aspiration.
Given its impact, we need to introduce AI to students very early so that the right
foundations are built over time and can be leveraged to take the country on a
high-growth path. Responding to the opportunities that lie ahead, it gives me great
happiness that NITI Aayog and NASSCOM have joined hands to roll out training
resources on AI for K12 students.
Under the aegis of Atal Innovation Mission, we have the Tinkering Labs in thou-
sands of schools across the country. The very name suggests a DIY approach to
innovation that provides an ultimate experience to young minds about what it
takes to innovate. In particular, a sandbox approach is much desired so that stu-
dents learn to regroup themselves quickly and move to the next project while
taking the learnings all along.
From cars that can drive themselves to smart toys to smart home appliances to
educational robots, there are already multiple instances of children being
surrounded by AI-enabled products. The pace of change is unprecedented and our
children will be sur-rounded by AI-enabled applications as they grow into adults.
Hence, it is imperative that we equip them with the right tools as early as
possible to start understanding the human-tech ecosystem they will live in as
they gradually transform into Generation AI.
For me, nothing is more exciting than seeing our children leverage technology
to fuel their imagination and spark their creativity. The world of technology is
fun; and a little nudge in the form of this AI module is going to create an
environment of l
earning-by-fun, fueled by curiosity & innovation.
This module was developed after numerous interactions with Atal Tinkering Labs
(ATLs) in schools and reviewing the engagement and performance of students with
current ATL set-up. During the process we spoke with teachers and students across
the country along with the subject matter experts from the industry and leading
pedagogy specialists. The module is an outcome of substantial research
undertaken on various models and content deployed across various contexts, both
at national and international level.
At the Tech Sector Skills Council NASSCOM, we earnestly believe that building a
strong foundation in emerging technologies like AI is critical for embarking
upon a journey towards making India a hub of digital talent. Our FutureSkills®
initiative is a step in that direction and our collaboration with Niti Aayog & Atal
Innovation Mission would accelerate our vision to educate and skill 4 million people
in the new, emerging technologies.
We are super excited to have co-created this learning resource together with the
government and as it is formally being rolled out to K-12 students across the
nation, it’s just a matter of time to witness the unfolding of magic in the making.
Preface
To make India, a 5 trillion USD economy India needs to
harness her creative potential to create an innovation-led
growth model to help transform our nation into a New India.
In keeping with this objective, Atal Innovation Mission, NITI
Aayog at the school level, is setting up state of the art Atal
Tinkering Labs (ATL) at schools in all districts across the
country. These ATLs empowering the students with the
‘skills of the future’, which include computational thinking,
Internet of things (IoT), artificial intelligence, design
thinking, advanced robotics.
Artificial Intelligence (AI) is a key driver of the Fourth Industrial Revolution, more
popularly defined as cognitive science with the right mix of interdisciplinary fields
such as science, mathematics, computing, philosophy, and others. The applications
of artificial intelligence are growing everyday as more people are devising new
techniques.
The ATL AI-Base Module is introduced with the objective that students leverage
the full potential of their Atal Tinkering Lab, the latest technologies introduced in
the labs and the various equipment’s installed there. The students can themselves
ideate, create, and thereby self-learn unleashing the ‘Student-Maker’ in them on
their path to game-changing inventions.
The module, contains activities that enable young innovators to interact with
different forms of artificial intelligence, view videos and engage in experiments.
It follows a simple approach with the sheer objective to introduce young minds
to the ‘magic’ of artificial intelligence. The students work through activities and
learn the various concepts of AI. The hands-on module is formulated to propel the
young minds to contribute to the ecosystem of innovation.
My special acknowledgement for the team at NASSCOM, for their endless support
and commitment towards shaping and designing this module. This would not
have been possible without their hard-work and dedication.
This is an initial step to empower students, teachers and the schools, with the latest
technologies. So lets’ all together celebrate curiosity and imagination as the key
pillars to problem solving and innovation.
Happy Tinkering J
UNIT 2 19-46
Learning
2.1 Human Learning Process
2.2 Computer or Machine Learning
2.3 Learning Human Abilities
2.4 Speech Recognition
2.5 Computer Vision
UNIT 3 49-79
Data
3.1 Introduction to Data
3.2 Datasets
3.3 Types of Data
3.4 Database
3.5 Datascience and Big Data
3.6 Computational Data
UNIT 4 81-105
Data Visualisation
4.1 Algebra and Probability
4.2 Role of Statistics
4.3 Data Visualisation
UNIT 5 107-134
Problem Solving and Decision Making
5.1 Introduction to Problem Solving and Algorithms
5.2 Pseudocode - Writing Basic Algorithms
5.3 Searching and Sorting Algorithms
UNIT 6 139-159
AI Languages
6.1 AI and Computer Programming
6.2 Scratch
6.3 Python
6.4 Top AI Languages in 2020
UNIT 7 161-173
Ethics and AI
7.1 Ethics and AI
Acknowledgement176-177
Disclaimer: The content in this handbook has been curated from various online sources. We do not
intend to infringe on any copyrights.
Note: This document contains several weblinks and associated QR codes. The relevant documents and
video can be accessed either by clicking the weblink or by scanning the QR code using QR code scanner
application, which can be downloaded on any smartphone via the application store. Please note that
there are third party links in this module and Atal Innovation Mission or NITI Aayog or NASSCOM does
not endorse any person(s) or organisations mentioned on or related to these links.
Let's Learn Artificial Intelligence - Base Module
UNIT 1
INTRODUCTION TO AI
Topic Covered
Human Intelligence | Artificial Intelligence | Need for AI
Applications of AI | Key components of AI | Future of AI
1.1 HUMAN INTELLIGENCE
What makes us Humans, intelligent? Humans have brains, is that why we are
intelligent or do we become intelligent if we learn to use our brains well?
Human intelligence is defined in many ways; some common aspects across various
definitions include:
Gathering Analyzing
Information Information
Human
Storing
intelligence Decision Making
Information
involves
Retrieving
Taking Action
Information
Any agent who can perform the above is called an Intelligent Agent.
2
Let's Learn Artificial Intelligence - Base Module
3
WHAT IS ARTIFICIAL INTELLIGENCE?
It is the ability to imitate humans (such as using language/speech, vision/image
recognition, making predictions, learning, problem-solving, ability to move and
manipulate objects on their own)
An Artificial Intelligence Agent is a computer that can perform these activities.
Do you think an AI can produce Art? Can it write and sing songs, write stories, draw
paintings or interact with humans and have a conversation?
4
Let's Learn Artificial Intelligence - Base Module
EXPLORE
To hear more about what artificially intelligent machines can learn and do
listen to this very interesting Talk by Jeremy Howard, who is a data scientist.
“Get caught up on a field that will change the way the computers around
you behave ... sooner than you probably think.”
https://www.ted.com/talks/jeremy_howard_the_wonderful_and_terrifying_implications_
of_computers_that_can_learn
But how do we impart the ability to think and learn like humans on the machines?
We program computers to enable them to identify things, understand the relationship
between them, predict and decide what to do, in various situations. AI, therefore, is the
application of computing to solve problems in an ‘intelligent’ way using computer
programs. The steps to solve these problems are commonly written in the form of
algorithms, we will learn more about these later.
So, what is an intelligent way?
Well, an intelligent way is how humans use their senses, brain, and abilities to make
decisions that help them towards the goal they want to achieve, autonomously (without
being controlled directly by others). Similarly, AI involves computers completing a
task automatically with very little to no human intervention. Here, a computer uses its
capabilities for gathering information, analyzing it to make decisions and act.
Let us look at the video to understand more:
EXPLORE
This video talks about the development of computer systems to perform tasks that
normally require human intelligence.
https://www.youtube.com/watch?v=xR6j9TLZdAw
If a computer is intelligent, does that mean it has a consciousness of its own, i.e. is it
self-aware?
5
AI doesn’t mean that a computer can feel, or that it has a personality of its own. However,
many researchers have been questioning and studying whether ‘a robot should have
rights’? The Ethics and AI Chapter at the end of this module will explore this further.
Several scientists consider Artificial Intelligence to be somewhat of a misnomer,
suggesting that True AI is still years away. Many believe it will be more accurate to call
the current AI systems ‘Augmented Intelligence’, or the use of machines to extend
human capabilities and what they can do.
EXPLORE
https://internetofthingsagenda. https://www.processmaker.com/
techtarget.com/blog/IoT-Agenda/ resources/customer-success/blog/
Augmented-vs-artificial-intelligence- does-augmented-intelligence-
Whats-the-difference enhance-the-customer-experience/
However, there has been a lot of progress made over the years in this field. Now instead
of programming a computer to perform a very narrowly defined specific task, we can
feed it data, let it discover patterns and learn tasks on its own. For example, a computer
may be used to identify pictures of apples or bananas based on color and shape.
Instead of this, we can give the computer lots of pictures of each fruit and program it
to identify apples and bananas based on common features (edges, lines, curves, etc.)
in those images. In other words, we have machines that can make predictions — and
get better at them — based on a library of data. That’s still a far cry from a robot that
can think for itself.
6
Let's Learn Artificial Intelligence - Base Module
List the abilities that the machine should have to perform the task for you?
7
If yes you will be happy to know that we already have AI machines
with these capabilities.
EXPLORE
AI, over the years, has developed many new abilities and is being applied
for several new tasks. These include diagnosing diseases, creating art,
driving our cars, flying our aeroplanes, filtering spam from our emails,
doing our laundry, writing stories and translating them, etc. Let’s look
at some of these.
https://www.weforum.org/agenda/2017/10/robots-used-to-feature-in-horror-stories-
now-they-re-writing-them-for-halloween/
EXPLORE
8
Let's Learn Artificial Intelligence - Base Module
EXPLORE
https://cai.tools.sap/blog/how-artificial-
intelligence-disrupts-the-art-world/ https://newatlas.com/ai-art-film-
writing-review/46891/
EXPLORE
c) Self-driving/driver-less cars
https://www.youtube.com/
watch?v=EtdNHiV9NMc
https://www.youtube.com/
watch?v=OlLFK8oSNEM
https://www.youtube.com/
watch?v=sRxaMDDMWQQ
1.4 APPLICATIONS OF AI
There are many AI applications, which are growing by the day. Some existing
applications of AI are:
Gaming − AI plays an important role for a machine to think of a large number of
possible positions based on deep knowledge in strategic games. For example, chess.
Natural Language Processing − AI helps us interact with the computer that
understands natural language spoken by humans.
Expert Systems − Machine or software that imitates the decision-making ability of
humans and uses it to provide explanations and advice to the users.
9
Vision Systems − Systems understand, explain and describe visual
input on the computer.
Speech Recognition − There are some AI-based speech recognition systems with
the ability to hear and express in sentences, and understand their meanings when a
person talks to it. For example, Siri, Alexa and Google Assistant.
Handwriting Recognition − The handwriting recognition software reads the text
written on paper and recognizes the shape of the letters and converts them into
editable text.
Intelligent Robots − Robots that are able to perform the instructions given by a human
in an interactive manner.
EXPLORE
https://experiments.withgoogle.
com/collection/ai
EXPLORE
10
Let's Learn Artificial Intelligence - Base Module
EXPLORE
Try out the demos in the following link
to see how AI machines can
Describe your pet by just seeing an
image
Paint a beautiful picture as per the
lines drawn by you and much more
https://www.nvidia.com/en-us/research/
ai-playground/
EXPLORE
Want more:
https://lionbridge.ai/articles/10-craziest-ai-
experiments-to-try-online-today/
EXPLORE
https://www.youtube.com/watch?v=5CKhnw2Zfxw
11
1.6 FUTURE OF AI
See an interesting video on what the future of AI is by clicking the link below:
EXPLORE
https://www.youtube.com/watch?v=xH_B5xh42xc
12
Let's Learn Artificial Intelligence - Base Module
Now let’s do an imagination activity. Think of any device, object or facility. If suddenly
this device or object became intelligent, what do you think it would be able to do?
Write your thoughts on these below.
For example:
13
14
Let's Learn Artificial Intelligence - Base Module
15
16
Let's Learn Artificial Intelligence - Base Module
Artificial Intelligence (AI) is teaching the machines to learn, think, decide and act as humans
would.
An Artificial Intelligence Agent is a computer that has the ability to imitate humans (such
as using language/speech, vision/image recognition, making predictions, learning, problem-
solving, ability to move and manipulate objects on their own.
There has been a lot of progress made over the years in this field. Now instead of programming
a computer to perform a very narrowly defined specific task, we can feed it data and let it
discover patterns and learn tasks on its own.
Though currently, AI is able to do all this and more, the real AI is still far away. Many believe it
will be more accurate to call the current AI systems as 'Augmented intelligence' or the use of
machines to extend human capabilities and what they can do.
We still have a long way to go to make a robot that can think for itself.
17
Let's Learn Artificial Intelligence - Base Module
UNIT 2
LEARNING
Topic Covered
Human learning process | Computer or Machine Learning
Learning human abilities | Speech Recognition | Computer Vision
19
2.1 HUMAN LEARNING PROCESS
How do we learn? Think of something you recently learned. How did you learn it?
1. 2. 3.
Next time I see I don’t like the pain I store the memory
something like the and burnt skin and of the flame, its
flame, I evaluate if decide to avoid it features and
it is a flame, that next time. the surrounding
can burn me and information. I also
cause pain. If it is, I store the feeling of
don’t touch it. heat, pain and burnt
skin in my memory.
6. 5. 4.
20
Let's Learn Artificial Intelligence - Base Module
Humans see,
Analyze it to
hear or feel Remember it
recognize it
something
1. 2. 3.
6. 5. 4.
7. 8. 9.
Now think of something you learned to do and break it down into the steps to match
the sequence outlined above.
21
2.2 COMPUTER OR MACHINE LEARNING
A computer learns in a similar way. However, it needs a lot of information, to ensure
that it recognizes things accurately. Machines need to be trained to make decisions
and to act based on goals.
So, how do you train a computer to identify things? Computers need a lot of informa-
tion to ensure accurate recognition of things.
22
Let's Learn Artificial Intelligence - Base Module
A wrongly trained computer may try and extinguish the flame in the painting or touch
a live flame again to get damaged. So, is it possible that they can discern based on
temperature, movement, etc?
So, let’s get back to the task you wanted your personal assistant to do for you (From
Unit 1)
Now let us assume you want your personal assistant to cook for you. What do you
think a robot should be able to know and do in order to cook?
One way of arriving at this list is that instead of thinking of what a robot needs, let us
first think of what a human would need to do this.
What are the things one needs to know and be able to do in order to cook?
Various cooking methods Put and remove utensils from the gas
How to evaluate if food is cooked properly Assess the stage of cooking so as not to
undercook or overheat the food
How to spot spoilage for both raw ingredi- Stir food
ents and food which is being cooked
Wash the ingredients clean
23
Now select some of these tasks and try and see what senses does a robot need to do
this?
TASKS SENSES
As you may have guessed, in cooking we use the senses, such as:
Sight
Sound
Smell
Taste
Touch
24
Let's Learn Artificial Intelligence - Base Module
PROJECT
25
Click the Pen sign (Edit) in front of Class 1
Name Class 1 as Cats
Click the Pen sign (Edit) in front of Class 2
Name Class 2 as Dogs
DOWNLOAD
26
Let's Learn Artificial Intelligence - Base Module
The output is the prediction of machine based on the set of data uploaded as training
images of Cats and Dogs. It tells whether the image uploaded from Table C is more
like those in Folder A (Cats) or Folder B (Dogs). The result is given in the output section
as percentages of the likelihood that the image is similar to Class 1 (Cats) or Class 2
(Dogs).
The larger and more accurate the dataset of images in Class 1 and Class 2, the better
the prediction. Let us see how this will happen.
See the change in output percentages. The closer the result is to 100%, surer the
computer is of the classification. Except for the Cat image, the Cat image is closer to
classification as a Dog than a Cat. This is because the data set is richer on the Dog
side and not on the Cat side. Thus, we got a percentage that indicate the machine is
less sure of the output. Inaccuracies happen when the image data that the computer
receives is not very well defined and distinct.
Now just because more images are uploaded doesn’t automatically translate into
more accuracy. The quality and accuracy of the images is also a factor. In order to
understand this, let us take the following steps:
Note that, the bigger and better the Dataset is, the more accurate is the prediction.
This is very important to understand from a ‘bias’ perspective, you will read about it in
the final Unit of this module.
Now you can practice the same using the Burger and Sandwich images provided as well
in the burgersandwiches folder at the same link given earlier, along the catsanddogs
folder. You can also use the voice and pose projects as given at the same link.
27
To understand how the machines learn, let us first look at three common ways that
humans learn. These are:
Through
Instructions
Can you think of some examples for each of these types of learning?
Here is an example of each.
28
Let's Learn Artificial Intelligence - Base Module
29
Machine Learning takes place in an almost similar manner.
The methods of learning are:
Supervised Learning
Unsupervised Learning
Reinforcement Learning
SUPERVISED LEARNING
In Supervised learning,
the computer is trained
using example inputs
and the correct output.
We feed the features
and their corresponding
labels into the machine in
a process called training.
As you observed in the
exercise involving Cat and
Dog images.
During training, the
rules programmed into
a computer (algorithms)
gradually determine the
relationship between
features and their
corresponding labels without any human intervention. The computer in this case
compared the images we fed into it and their features. It used this comparison to
understood and differentiate features of Dogs and Cats.
This relationship is called the model.
The model, when applied for solving real-world problems can often become very
complex. The number of rules to identify, learn, predict features and outputs can be
many. Complex models with many inter-related rules are called Neural Networks
based on Human Brain Cells known as neurons. But we will learn about these in
later modules.
Once the model provides an output, we determine if more training is required
based on the results it is providing. Every time the machine is trained more as we
did in the activity, the model keeps adjusting itself, to work out the relationship
between the input and output.
The model uses a training data set and a test data set to train and then test the
model, before it is deployed for actual use.
30
Let's Learn Artificial Intelligence - Base Module
UNSUPERVISED LEARNING
Unsupervised learning
only trains using inputs,
and the computer must
figure out how the various
inputs relate to each
other and then it bunches
similar inputs together.
Therefore, the goal is to
identify meaningful and
common patterns in the
data.
To achieve this, the
machine must learn from an unlabelled data set. Unlike supervised data where the
labels on training data provide the machine information on the various input, the
model here has no support on how to categorize each piece of data and makes its
own rules for doing it.
REINFORCEMENT LEARNING
EXPLORE
To learn more about Reinforcement Learning watch the video given below.hh
https://www.youtube.com/watch?v=TnUYcTuZJpM
31
ACTIVITY
Now let’s do an activity for understanding how these three learning methods work.
We will do this activity in stages, so do not jump the steps and peep ahead. Follow
instructions as stated.
EXPLORE
http://www.stoeckl.ai/wp-content/
uploads/2019/12/MLcards_part1.pdf
Ensure you have multiple sets, and if you are printing multiple cards on one sheet, use
a scissor to cut these into individual cards.
Now your task is to mix the cards.
Form groups of 4 persons each and each playing group takes a set of the 16 playing cards.
The task is to divide the cards into 4 groups, which the group thinks belongs together.
Then write down which characteristics or features were used to make the distinction.
Once successfully done, you will know that this is how the machine-learning algorithm
functions, to learn the correct features and characteristics of the features. The
representation of the data as values of the characteristics is crucial. It also shows how
Unsupervised Learning (and a component in it called Clustering) works.
EXPLORE
32
Let's Learn Artificial Intelligence - Base Module
Like in the first case, ensure the cards and cut out into individual cards.
You will notice that in addition to the pattern already noted in the first set of cards,
these cards have 4 different “objects” to see:
“A”, “B”, “C” and “D”
The task of the groups is now to assign which of the 4 groups from task 1 belongs to
which class of objects (A, B, C or D). The additional cards stand for a set of labeled data,
and the task clarifies the principle of Supervised Learning.
Now for reinforcement learning, we must do the third task. The objective of this task is
to find out in a different way which objects belong to a particular class that is “stronger”
than the other objects. There is no data in the form of a set of “labeled data” that shows
the affiliation to this class. This special property of the objects must be derived by the
group purely from the game behavior.
The rules of the game are as follows:
2 of the 4 players in a group fix one of the 4 categories (A, B, C or D) as a special
category (“trump”) without telling the other two.
The goal of the task is that the other two players find out which cards are of the
“trump category” in the further course of the game.
The 16 cards with the markers are played (second set).
The cards are divided by the 4 players, and each player receives 4 cards.
Each of the 4 players places one card on the table in one round.
The player with the card with the highest number of vertical lines wins the round
and receives all 4 cards. Except when one of the cards involved is from the
“trump” category, it wins. (This can be judged by 2 of the players.)
If there are more cards of the trump category in the round, the trump card with
the most lines wins.
If several players with the same number of lines win, the cards are split.
From the results of the rounds of the game, it must be tried to recognize the “trump”
attribute.
The form of learning which cards (objects) are trumps, practiced in this game, is a form
of reinforcement learning. After each round, a theory of the players is given, which
category is a trump by the round result or is discarded.
With these 3 tasks, the different variants of machine learning can be shown with the
help of the cards.
Source: (Stöckl, 2019)
33
As you will see the 3 basic stages of ML across all forms include
Actions may be taken on the output manually or through various connected systems.
In case there is an action based on the output that is taken by an attached device,
then these devices are called actuators, such as the limb of a robot.
EXPLORE
34
Let's Learn Artificial Intelligence - Base Module
So, let us explore some of these and see where we have reached in making the
machines learn these capabilities.
Now, let us look at using language and speech for communicating as humans. Think
about this.
How do we get machines to develop some of these abilities that humans have?
Let us take the example of human interactions. When we talk to someone, not only
does the person understand what we are saying, they remember it and respond.
Form a
Listen Understand Respond
Response
35
Conversational AI agents carry out the following functions in order
to communicate like a human:
Automated Natural
Speech Language
Recognition Processing
Advanced
Dialog
Management
36
Let's Learn Artificial Intelligence - Base Module
To know the working and use of Speech Recognition, read the following
articles:
https://electronics.howstuffworks. https://www.globalme.net/blog/
com/gadgets/high-tech-gadgets/ the-present-future-of-speech-
speech-recognition.htm recognition
https://www.processmaker.com/ https://chatbotsmagazine.com/
resources/customer-success/ conversational-ai-what-to-
blog/how-artificial-intelligence- expect-in-the-next-five-years-
will-disrupt-speech-recognition/ 26518c8cd385
From the time we are born, we hear words and sounds around us. Even before we can
speak, we hear some words that we start responding to words like Mama, Dada, Yes,
No.
Our brain tries to find patterns to differentiate various sounds and words, and categorize
them. It may seem as though humans are pre-programmed to listen and understand,
but it is not so. We have been trained to develop this ability.
Speech recognition technology has been developed on the same lines. Computers are
also trained in the same way.
Like, we may still make mistakes when we hear new words or the words are not said
properly, computers also make mistakes. In fact, more than humans, usually.
Perfecting these speech recognition systems takes a lot of practice.
37
HAVE YOU USED THE SPEECH RECOGNITION
FEATURE IN YOUR COMPUTER?
Let us see how the computer can recognize what you say and reproduce it on a docu-
ment in a basic speech recognition application.
Windows 10 has a Speech Recognition feature that allows you to perform common
tasks hands-free. Speech Recognition is an easy-to-use experience letting you control
your computer on Windows 10 entirely with speech commands.
You can set up and use this feature to navigate, launch applications, dictate text, and
perform a number of other tasks. Speech Recognition though was primarily designed
to help people with disabilities who can't use a mouse or keyboard.
We will now go through the steps to configure and start using Speech Recognition to
control your computer only with voice. Let us do an activity to experience this.
ACTIVITY
38
Let's Learn Artificial Intelligence - Base Module
Before you set up voice recognition, make sure you have a microphone set up.
Set up a microphone
Select the Start button, then select Settings > Time & Language > Speech.
Under Microphone, select the Get Started button.
39
5. In the “Set up Speech Recognition” page, click Next
EXPLORE
Now go to the following link and train your computer to do the task
mentioned below the link.
https://www.windowscentral.com/how-set-speech-recognition-windows-10
40
Let's Learn Artificial Intelligence - Base Module
Task:
Configure Speech Recognition on Windows 10
Train Speech Recognition to improve accuracy
Change Speech Recognition settings
Use Speech Recognition on Windows 10
EXPLORE
To learn more about voice recognition and Virtual Assistants see the video below:
https://www.youtube.com/watch?time_continue=129&v=1e8q_LtH0_o&feature=emb_
logo
41
You are making noise in You register a person approaching,
the corridor of your school, the image passes through your
and you suddenly notice eyes, followed by the visual signal
your Principal approaching hitting your eye’s retina.
42
Let's Learn Artificial Intelligence - Base Module
Cameras today are well advanced to perform the function of the eye with great
precision, capturing the light variations and transferring and storing these as visual
images.
The real challenge is to write algorithms or software programs that can identify what
the image is and extract meaning from these images. Image capture and processing
device hardware cannot identify and differentiate between even a man and a dog.
Our brains use data of past images, exposure and experiences as context to classify
and identify what we see, so how are we expecting machines to do this?
When a computer sees an image, for example, of a cow, it only sees a massive array
(list) of numbers that represent various intensities and colors of the image, but not the
image itself. There is no context to it, and that is why computers need to get algorithms
to comprehend an image the same way a human does.
This is where machine learning is required to come in and use various statistical
techniques to allow algorithms to learn and improve as they come across new data,
so eventually, they are able to decipher the numbers in a particular sequence which
actually brings out the meaning. In the case of Computer Vision, this data is image
data.
Machines interpret images very simply: as a series of pixels, each with their own set of
color values. Consider the simplified image above, and see how grayscale (Grayscale
is a range of gray shades without apparent color. Black is the darkest possible shade
and white is the lightest shade possible) values are converted into a simple array of
numbers:
Source: Openframeworks
43
By feeding a Machine Learning model enough data, we can make it highly accurate
as we have seen in our Dogs and Cats exercise previously. Presently, Computer Vision
accuracy for image recognition that is achieved in some applications is approximately
95% which is similar to human standards.
The discipline that allows us to somewhat recreate our brain’s system of using
knowledge to make sense of objects is called Deep Learning. We will learn about this
is in detail later, for now, think of it as a large and complex neural network that is used
for the most complex AI tasks.
These special types of neural networks break down each picture into pixels and slide
filters (mathematical objects) across them to detect patterns. At the first level, much
like our brain, these determine things like rough curves and edges within an image. A
few runs after, however, they start piecing together surfaces, info about depth, layers,
gaps in the visual spaces, and, finally, begin to make out objects such as faces, cars,
animals, boxes, etc.
EXPLORE
https://video.sas.com/detail/videos/advanced-analytics/video/5410893556001/face-
recognition-using-sas-viya?autoStart=true
44
Let's Learn Artificial Intelligence - Base Module
Automotive: Self-driving cars are the most common example of using computer vision
in the automotive sector, but it is also being used for automatically detecting lanes,
setting speed limits, interpret traffic signage, etc.
EXPLORE
45
What have we learned
The human learning process involves the following cycle:
Humans see,
Analyze it to
hear or feel Remember it
recognise it
something
1. 2. 3.
6. 5. 4.
7. 8. 9.
46
Let's Learn Artificial Intelligence - Base Module
UNIT 3
DATA
Topic Covered
Introduction to Data | Datasets | Types of Data | Database
Data Science and Big Data | Computational Data
49
3.1 INTRODUCTION TO DATA
Artificial intelligence is a set of technologies that allows us to extract knowledge from
the data.
It is a system that learns or understands patterns within that data, and can identify
them, and then reproduce them on new information.
85 100 61 NO NO YES
54 32 97 MAYBE NO NO
As you can see from the above examples it is difficult to extract any information from
this data.
DATA PROCESSING
Data processing refers to organizing and performing various operations on collected
data to produce meaningful information.
50
Let's Learn Artificial Intelligence - Base Module
INFORMATION
DATA
PROCESSING
INPUT OUTPUT
LABELING
CLEANING
STRUCTURING
INTERPRETATION
ANALYSIS
To process the data from our earlier example, let us start by providing labels to them.
The labels indicate what the data is and how it is related to other data.
51
The first set of data was, in fact, the data of The second set of data was the result
the marks obtained by some students of declared by the selection committee of
the 5th standard in a maths test. the same set of students for selection in a
dance competition.
The third set of data was of colored geometrical shapes that had to be identified.
SQUARE
CIRCLE
TRIANGLE
Then next step is to re-arrange the data in an increasing or decreasing order and then
calculating the totals. This will give a better picture of what the data represents and
we should be able to extract some useful information from it now
52
Let's Learn Artificial Intelligence - Base Module
ACTIVITY
Student Name Marks in Maths Test
Aarti YES What is the information you can
extract from this data?
Apu YES
Farah YES
Anik MAYBE
Guna MAYBE
Babu NO
Devin NO
Hira NO
Koel NO
Total YES: 3
Total Number
Total MAYBE: 2
of Students: 9
Total NO: 4
TRIANGLE 4
CIRCLE 3
SQUARE 2
Total 3 2 2 1 1 9
ACTIVITY
53
DATA ANALYSIS
Data analysis is about finding useful patterns in data based on the goals or purpose of
the data analysis activity.
Data analysis is very important for Machine Learning. Machines analyze historical and
available data to make predictions and arrive at conclusions for taking action.
It involves the following processes:
Modelling is the process of finding out the relationships between different parts of
the data and the patterns that can be recognized in it. Models are used to predict
information about new data fed into the system. As we saw in the earlier activity about
Cats and Dogs, the images we fed into the machine was the data. The prediction of
whether the new image was a Dog or a Cat was done by the machine after analyzing
and modeling the earlier data that was fed.
54
Let's Learn Artificial Intelligence - Base Module
Diagnostic Descriptive
TYPES OF DECISION
How can we BASED ON DATA Predictions
make it happen? ANALYTICS
Prescriptions Predictions
3.2 DATASETS
Artificial Intelligence requires a huge amount of data in order to provide an acceptable
output. When people collectively pool their data, we can collect a huge amount of raw
data. Data is usually organized for the purpose of analysis in Datasets.
Dataset is a collection of related sets of information that is composed of separate
elements but can be manipulated by a computer as a unit.
In the previous example of training the computer on images of Dogs and Cats, we had
two sets of data:
1. Training Data
2. Testing Data
55
A Dataset can be in various forms, such as images, numbers, or texts.
The Dataset lists values for each of the variables, such as the height and weight of an
object, for each member of the Dataset. Each value is known as a datum. Datasets can
also consist of a collection of documents or files.
Let us look at a predictive feature of AI that uses a large Dataset of images received
from numerous people through the internet. It is called “QUICKDRAW”.
ACTIVITY
https://quickdraw.withgoogle.com/
56
Let's Learn Artificial Intelligence - Base Module
If you can see the tick marks under all the drawings, it means that QuickDraw
understood your drawing.
Anyway, the point was that QuickDraw is learning from all the sketches drawn
by human beings. As soon as you start drawing your doodle, QuickDraw starts
guessing it one by one. If it does not understand it, it will reject your drawing
and put a wrong mark there.
Since many people have probably tried using 'Quick, Draw!' by now, the game is
becoming very good at figuring out what they are drawing, even if the sketches vary
from person to person. The game literally trains itself to guess people’s drawings based
on previous experiences or previous training.
The previous training is done on a Dataset that includes huge amounts of data for
various types of drawings and the final results.
ACTIVITY
https://www.autodraw.com/
57
Now try to attempt to draw a figure such as a bird.
As you will see there will appear various suggestions on the top, which are predictions
of what you are trying to draw. One can select the correct option for a pre-drawn
image of improved quality.
We are selecting the bird here.
58
Let's Learn Artificial Intelligence - Base Module
The predictions are made through machine learning programs working in the backend
that compare your design to previously made designs. It arrives at the closest image
by extracting the features such as individual and combination of shapes, the distance
between lines, edges and curves, etc. These attributes of the image are called features
and the process of identifying those features is known as feature extraction.
In the AI applications discussed above, the Dataset of images in the background holds
all the suggested images that are compared against a drawn Dataset.
So, where are these Datasets and how are they built?
Datasets are owned by organizations. Some are publicly available. You may wonder
that why can’t we keep all data available to the public? We will discuss this in the last
Unit.
Public Datasets or Open Datasets represent the data compiled by various providers
and made public for use in various Big Data or AI applications. Big enterprises such
as Google, Amazon, Microsoft, and others have provided these datasets to the public.
These organizations usually acquire this data from their regular business activity or
work. Some organizations may also purchase data to fill gaps in their own data to
develop required Datasets. This may also add financial value to Datasets.
Explore the various types of data that your school may have and how it has been
collected? Also, think of what information can be derived from this data and what it
can be used for?
59
EXPLORE
Quantitative Qualitative
Data Data
60
Let's Learn Artificial Intelligence - Base Module
Broadly speaking, when you measure something and get a number value, you create
quantitative data, whereas when you measure something and represent it by name,
symbol, etc, you create qualitative data.
So far, so good. But this is just the highest level of data; there are also different types
of quantitative and qualitative data. These data can be further classified into various
types as discussed in the subsequent sections.
ACTIVITY
61
A form of discrete data is Digital data, this is data transmitted in binary format (zeros
and ones). Examples of digital data includes data used in computers, CDs, DVDs, and
related electronic devices.
Here are some examples of discrete data and continuous data for further clarity.
Discrete Continuous
Shoe size Length of foot
Number of Cars one owns Speed of a Car
ACTIVITY
Going back to the data you collected about your 10 friends earlier, figure out
from the data, which part of the data is Continuous and which is Discrete.
62
Let's Learn Artificial Intelligence - Base Module
Ordinal data is the data that is placed in some kind of an order or scale where the
variables have natural and ordered categories. A simple example can be categorization
on the basis of height i.e. short, medium or tall. Another example is ranking an item
on a scale of 10 where 10 is the highest. This implies 10 is better than 9, which is better
than 8 and this trend continues.
The difference between ordinaland nominal data is that the former is placed in some
defined order based on specific criteria whereas the latter names something without
classifying it based on criteria such as numbered objects or pieces of data.
EXPLORE
Here is a brief video that will summarize what we learned about types
of data.
https://www.youtube.com/watch?v=7bsNWq2A5gI
ACTIVITY
Identify Binary and Nominal data from the data you collected and recorded
in a table about your 10 friends.
3.4 DATABASE
Databases offer a convenient and powerful way to store, organize and efficiently
retrieve information.
When you collected the data for 10 friends, you had to write that data down in a
notebook in order. It must have taken a lot of time and effort. What if you had to collect
and store the data for 500 students?
Since AI involves handling large amounts of data, computer programs such as
spreadsheets are used to store, arrange and process that data.
SPREADSHEET
A spreadsheet can be understood as a computer application that allows the users to
organize, analyze and store data in a tabular format. Spreadsheets are commonly used
for applications such as accounting and recording data using rows and columns. The
primary function of this tool is to organize and categorize data into a logical format.
63
See the diagram given below:
Row
Cell
Column
There are 36 cells in the diagram shown above. What if we had to fill data for hundreds
or thousands of cells?
It would be very difficult to draw such a big table. But computers have a software
called “Spreadsheets” which makes our job pretty easy.
You will also find it very easy to use these computer spreadsheets when you start
playing with data.
Spreadsheets have other benefits too:
We can put words, numbers or even pictures in the cells.
We can easily provide them headings or labels
We can very easily re-arrange them in increasing or decreasing order
We can even do calculations much faster than a calculator
We can make multiple pages
Take print outs on paper
Another strength of spreadsheets is that they can produce diagrams, like graphs and
pie-charts, based on the data the user enters. Sometimes the numbers make more
sense when the computer turns them into a picture.
Following are some of the popular spreadsheet formats:
64
Let's Learn Artificial Intelligence - Base Module
Other databases include MS Access, MYSQL, etc. Databases are controlled by Database
Management Systems (DBMS). The data, the DBMS along with applications that are
associated with them are referred to as a Database System. We will learn about these
in later modules.
EXPLORE
ACTIVITY
Remember the information you collected about your 10 friends in the earlier
segment of this unit, enter that data in the spreadsheet.
65
First, keep the information collected by you in front of you.
Then open Excel in your computer
Now enter the details in a spreadsheet with the 6 items mentioned above as
headings in the first cell of the first 6 Columns.
66
Let's Learn Artificial Intelligence - Base Module
Data sorting is the process of arranging the data into a meaningful order so that it can
be analyzed or processed easily. Data sorting can be done in the following ways:
When we say that the data (numbers or characters) is sorted in ascending order,
it means that the arrangement is from the smallest to the largest number e.g.
5, 18, 26, 48 and 72 or A, B, F, L, O, Y, and Z.
Similarly, when the data (numbers or characters) is sorted into descending
order, the arrangement is from the largest to the smallest number e.g. 98, 77,
53, 29 and 2 or Z, Y, O, L, F, B, and A.
Let’s say you had the spreadsheet above and wanted to sort by age. This process
is fairly simple. One can start by either highlighting the whole column at once
or simply clicking on the first cell in the column. Then you will:
Right-click to open the menu
Go down to the Sort option – when hovering over Sort, sub-menu will appear
Click on Largest to Smallest
Select Expand the selection
Click OK
Data filtering can also be done using spreadsheets. The filter feature applies a drop-
down menu to each column heading, allowing you to select specific choices to narrow
a table. Using the above example, let’s say you wanted to filter your table by gender.
Let us find out how this can be done.
Follow the given steps to filter the table by gender:
Go to the Data tab on the Excel ribbon
Select the Filter tool
Click on the arrow next to Gender to bring down the dropdown menu
Select Female and ensure all other boxes are unticked
ACTIVITY
Use the same data of your 10 friends that you have entered in the spreadsheet
and perform the following task:
Sort the data by Name from A to Z
Filter the data to select the only students whose favorite subject is Hindi
67
Now you have some idea about what data is and it’s processing. You will be using what
you learned here in the next two chapters.
68
Let's Learn Artificial Intelligence - Base Module
There are a number of very common needs for a computer that includes the need to
store and view data.
Computers use electrical signals that are ON or OFF, so they have to see everything
as a series of binary numbers. This data is represented as a sequence of 1s and 0s (ON
and OFF) which we call as bits in the digital terminology. All the data that we want a
computer to process needs to be converted into this binary format.
WHAT IS BINARY?
The binary system is a number system that only uses two digits: 0 and 1. All the
information that is processed by a computer is in the form of a sequence of 0s and 1s.
Therefore, all the data that we want a computer to process needs to be converted into
binary. Text, images and audio, all types of data are recorded as binary on the computer.
Computers can read only 0s and 1s, but it can use them to make text, images as well as
sounds as illustrated in the image below.
69
The binary system is known as a ‘base 2’ system. This is because:
there are only two digits to select from (1 and 0)
when using the binary system, data is converted using the power of two.
ACTIVITY
Can you use these cards to communicate a secret message to your friend? If
the numbers 1 – 26 represented the letters of the alphabet as given below.
1 2 3 4 5 6 7 8 9 10 11 12 13
a b c d e f g h i j k l m
14 15 16 17 18 19 20 21 22 23 24 25 26
n o p q r s t u v w x y z
70
Let's Learn Artificial Intelligence - Base Module
ACTIVITY
Notice that each card has double the diamonds of the card to its right.
We can use these cards to make numbers by turning some of them face down
and adding up the diamonds that are showing in the cards facing up, as seen
below. As you can see, the first card on the right with one diamond and the
first card on the left when added represent 17.
= 17
Similarly, you can make 10 (By counting 8-diamonds and 2-diamonds in the
cards facing up and adding them), as shown below.
= 10
71
ACTIVITY
Going back to the first example, where we represented 17 (By counting 16-dia-
monds and 1-diamond in the cards facing up) by using cards. Now under each
card showing the side with the diamonds, write 1. Under each card flipped
over, write 0. Now when you read the entire sequence i.e. 10001, this is how 17
can be represented in Binary.
1 0 0 0 1 = 17
72
Let's Learn Artificial Intelligence - Base Module
Bit is the smallest unit for measuring a computer’s memory. These bits are commonly
grouped together in groups of eight that represent numbers ranging from 0 to 255
(as we saw numbers 0 to 31 being represented by 5 digits). A byte is a data storage unit
equivalent to 8 bits. 1024 bytes are equivalent to 1KB or 1 Kilobyte of data. Going further,
the following units can also be used for representing the data stored in a computer in
binary:
1024 Kilobyte = 1 Megabyte (MB)
1024 Megabyte = 1 Gigabyte (GB)
1024 Gigabyte = 1 Terabyte (TB)
1024 Terabyte = 1 Petabyte (PB)
A bit is usually represented in a computer’s main memory by a transistor1 that is
switched ON or OFF or a capacitor2 that is charged or discharged.
When data is transmitted over a telephone line or radio link, high and low-pitched
tones are used for the Zeros and Ones. On magnetic disks (floppy disks and hard disks)
and tapes, bits are represented by the direction of the magnetic field on a coated
surface (either North-South or South-North).
N S N S S N N S S N S N N S
The data within CDs and DVDs are stored optically in the form of Zeros and Ones. The
part of the surface corresponding to a bit either does or does not reflect light.
The speed of a computer can be defined as the number of bits that the machine can
process at a single instant. Suppose we take an example that features two computers
A and B wherein one is a 32-bit machine whereas the other one is a 16-bit machine
respectively. Also, let us assume that we have data that is 32-bit number.
1
Transistor is a miniature electronic device that regulates the flow of current and acts as a switch.
2
Capacitor is an electronic device which stores the electric current when current is allowed through it.
73
During the processing cycle, A will process the data in a single operation but B will
break this data into smaller pieces thereby taking more time. Hence, we would say
that machine A is faster than machine B in this operation.
A computer uses bits and bytes for storing data such as number, text and related in-
formation. Let us see how one can represent the information in various formats on a
computer.
To convert a given text into formats that are readable and understandable for the
computer, commonly, we use ASCII codes. ASCII is an acronym for the American
Standard Code for Information Interchange. ASCII codes are used to represent the 128
English characters (includes English alphabets, numbers and special characters) into
a language that can be easily understood by a computer. In ASCII codes each number
represents a character that can be used to convert text into binary. The ASCII code
takes each character on the keyboard and assigns a binary number for it.
74
Let's Learn Artificial Intelligence - Base Module
75
Adding color
The above example was for a black and white image now let us look at how colored
images are represented through binary. Instead of using single digits 0 and 1, using
them in two-digit numbers allows four possible numbers that can be used to represent
four colors in an image. As shown below, in the binary number system this can be
represented using two bits per pixel:
00 – white
01 – blue
10 – green
11 – red
We all know that this will not be sufficient to represent a wide range of colors that are
used in images. Hence, if we add another binary digit, the number of colors available
will be doubled as shown below.
1 bit per pixel (0 or 1): 2 possible colors
2 bits per pixel (00 to 11): 4 possible colors
3 bits per pixel (000 to 111): 8 possible colors
4 bits per pixel (0000 – 1111): 16 possible colors
…and so on
16 bits per pixel (0000 0000 0000 0000 – 1111 1111 1111 1111): over 65 000 possible
colors
The number of bits that are used to store each pixel in an image is known as color
depth. Images with more colors need more pixels to store each available color in that
image. This means that images that use lots of colors need more space and are stored
as larger files.
Image quality
Image quality is affected by the resolution of the image. Image resolution describes
the image’s level of detail – higher resolution means more image detail. In digital
imaging, the resolution is often measured as a pixel count. The resolution of an image
defines the closeness of the pixels with one another. This also decides the number of
pixels required to fill the space.
The images that are in low-resolution will feature larger pixels and require fewer pixels
to fill in space. Such type of images seems to be blocky or pixelated. On the other
hand, the images that have high resolution include far more pixels and look better
when zoomed in or stretched. The disadvantage of having more pixels is that the file
size will be bigger.
76
Let's Learn Artificial Intelligence - Base Module
The samples can then be converted to binary and they will be recorded to the nearest
whole number.
Time 1 2 3 4 5 6 7 8 9 10
sample
Binary 1000 0010 0111 0110 1001 0100 0010 1000 0110 0110
Denary 8 2 7 6 9 4 2 8 6 6
Value
77
If we plot the time samples onto the same graph, we can see that the sound wave
now looks different. This change in the graph is because sampling does not take into
account the change of the sound wave in between each time sample.
This means that the sound loses it’s quality as data has been lost between the time
samples. So, to increase the quality of sound and to store sound which is closer to the
original, we need to have more samples that are closer together. In this way, more de-
tails about the sound can be collected, so now when it is converted to digital and back
to analog again, the sound quality is not lost much.
The frequency at which samples are taken is called the sample rate and is measured
in Hertz (Hz). 1 Hz is one sample per second. Most CD-quality audio is sampled at 44
100 or 48 000 kHz.
78
Let's Learn Artificial Intelligence - Base Module
79
Let's Learn Artificial Intelligence - Base Module
UNIT 4
DATA VISUALIZATION
Topic Covered
Role of Algebra and Probability in AI | Role of statistics in AI |
Data Visualization
4.1 ROLE OF ALGEBRA AND PROBABILITY IN AI
Machines learn differently from us. They use a lot of mathematics and learn by trying
and trying again. To understand how machines learn, let us try to learn like a machine
with the help of this game. In this game, we have to correctly predict what pictures
does a girl called Pari like.
To play this game, we will follow these steps:
You will see You will guess You will You can keep
examples of the features of predict Pari’s trying to predict
pictures that the pictures response to Pari’s response
Pari likes and that Pari likes. some more by trying
dislikes. pictures using out different
the features features that you
you identified. can identify, till
you get it right.
_
^ _
` ^
`
82
Let's Learn Artificial Intelligence - Base Module
Write at least 3 features that you noticed about the pictures that Pari likes. You could
look at features such as color, shape, background, border, texture, sides, angles, length,
height, etc.
To help you notice the features better, we have re-arranged the pictures:
Now see if Pari likes the next 3 pictures based on the features A, B, and C that you have
written down.
Give the picture ‘10 marks’ if that feature is present
Give the picture ’0 marks’ if that feature is not present
Give the picture ’5 marks’ if you are not sure
83
Feature: A Feature: B Feature: C
A+B+C= Total
A+B+C= Total
A+B+C= Total
From the marks given, try to predict if Pari likes this picture or not.
Check Pari’s answers from the end of this Unit.
Were you correct with your guesses?
84
Let's Learn Artificial Intelligence - Base Module
How confident are you that you have understood what Pari likes?
100 – Very confident
50 – Somewhat confident
0 – Not confident at all
Do you want to change anything about the features you have noticed?
You can keep the same features or write a new set of features for the 3 pictures.
Now give 10, 8, 5, 2 or 0 marks to each of the next 3 pictures for each of the features
A, B, and C.
85
Add up the total marks given to each
picture.
From the marks given, try to predict if A+B+C= Total
Pari likes this picture or not.
Check Pari’s answers from the end
of this Unit. A+B+C= Total
Were you correct with your guesses?
How confident are you that you have
understood what Pari likes? A+B+C= Total
100 – Very confident
50 – Somewhat confident
0 – Not confident at all
Do you want to change anything about the features you have noticed?
You can keep the same features or write a new set of features for the 3 pictures.
Now, give marks between 10 and 0 to each of the next 3 pictures. Give marks for each
of the features A, B and C. Assign marks depending on how sure you are that the
feature is present.
(10 marks, if you are fully sure the feature is present. 0 marks, if you are fully sure the
feature is not present)
86
Let's Learn Artificial Intelligence - Base Module
A B C
10 10 10
9 9 9
8 8 8
7 7 7
6 6 6
5 5 5
4 4 4
3 3 3
2 2 2
1 1 1
0 0 0
A B C
10 10 10
9 9 9
8 8 8
7 7 7
6 6 6
5 5 5
4 4 4
3 3 3
2 2 2
1 1 1
0 0 0
A B C
10 10 10
9 9 9
8 8 8
7 7 7
6 6 6
5 5 5
4 4 4
3 3 3
2 2 2
1 1 1
0 0 0
87
Add up the total marks given to each
picture. A+B+C= Total
From the marks given, try to predict if
Pari likes this picture or not.
Check Pari’s answers from the end A+B+C= Total
of this Unit.
Were you correct with your guesses?
How confident are you that you have A+B+C= Total
understood what Pari likes?
100 – Very confident
50 – Somewhat confident
0 – Not confident at all
Do you want to change anything about the features you have noticed?
You can keep the same features or write a new set of features for the 3 pictures.
Now again, give any marks between 10 and 0 to each of the next 3 pictures. Do this
for each of the features A, B and C. Assign marks depending on how sure you are that
the feature is present.
(10 marks, if you are fully sure the feature is present. 0 marks, if you are fully sure the
feature is not present)
88
Let's Learn Artificial Intelligence - Base Module
A B C
10 10 10
9 9 9
8 8 8
7 7 7
6 6 6
5 5 5
4 4 4
3 3 3
2 2 2
1 1 1
0 0 0
A B C
10 10 10
9 9 9
8 8 8
7 7 7
6 6 6
5 5 5
4 4 4
3 3 3
2 2 2
1 1 1
0 0 0
A B C
10 10 10
9 9 9
8 8 8
7 7 7
6 6 6
5 5 5
4 4 4
3 3 3
2 2 2
1 1 1
0 0 0
89
Add up the total marks given to each
picture. A+B+C= Total
From the marks given, try to predict if
Pari Likes this picture or not.
Check Pari’s answers from the end A+B+C= Total
of this Unit.
So, with each new set, have you
become better at guessing?
A+B+C= Total
In this game, you were learning like a machine. You even used some parts of the
mathematical concepts that machines use to learn such as Algebra and Probability.
90
Let's Learn Artificial Intelligence - Base Module
These subjects are covered in greater detail in the maths textbooks of standard
6th to 12th.
Why do you think computers use Algebra and Probability so much? It is because
computers need to figure out a lot of unknown stuff on their own as that is the
objective of AI. If we were always telling them what is what, then it wouldn’t really be
learning. It would just be remembering.
Algebra and Probability are wonderful at helping us and computers in figuring out
the unknown.
91
You cannot look into the Packet, so you cannot count them.
I am not going to tell you the number of marbles in the
Packet.
But I can answer all your other questions about the marbles
in the Packet.
Well, the color of the marbles or who gave me the marbles will not help you find out
the number of marbles in the box.
You need information that is related to the number of marbles. For example, you need
information about something that changes with the number of marbles in the Packet,
such as the total weight of the Packet containing the marbles.
The more the number of marbles, the more will be the weight of the Packet.
What if I told you the weight of 1 marble and then the total weight of all the marbles
in the Packet. Would you be able to tell me the total number of marbles in the Packet
then?
The weight of 1 marble is 2 grams, and the weight of all the marbles is 24 grams.
Let’s see how algebra makes this very easy to predict.
We have to find out the total number of marbles, which is an unknown number.
92
Let's Learn Artificial Intelligence - Base Module
This is how we, as well as computers, use algebra to find out the unknown.
Now, even if we add or remove some marbles from the Packet, and then tell you the
total weight, you can always tell the number of marbles.
All you will do is ‘Number of marbles in the Packet’ = ‘Total weight of the packet’ ÷ 2
We have already given the symbol N to Number of marbles in the Packet.
Let us call the total weight of the Packet W.
Then we can make a relationship N = W ÷ 2.
o So if W=10, N=W ÷ 2 or 10÷ 2 = 5
o So if W=40, N=W ÷ 2 or 40÷ 2 = 20
Here N and W are variables because they can have varying values.
The relationship N = W ÷ 2 is called an equation.
So, if an intelligent computer can find out the relationships related to unknown
information, it makes equations of it. Then it keeps on trying out different values for
the variables till it guesses the correct one, where all the equations comes true.
To learn more, read the chapter on Algebra in your Mathematics books and do
all the exercises given there. If you wish to teach a machine, you must first know
how they learn.
93
MORE ABOUT PROBABILITY
Probability is used when we are not certain of the result.
In the above example, we could be certain of the number of marbles in the Packet
because we knew the weight of 1 marble as well as of the total marbles correctly.
What if we did not have a weighing machine? Then you would hold one marble in
one hand and the Packet of marbles in another and guess. Then you would say “Most
probably this packet contains …… marbles”.
Artificially Intelligent machines use Probability when they do not have all the
information.
Here is a game that will help you understand how Probability helps computers figure
things out.
Cut a page into 4 equal parts and write down ‘RED’ on one, ‘BLUE’ on another, ‘GREEN’
on another and ‘PINK’ on the last one.
RED BLUE
GREEN PINK
Now fold all the four pieces of paper hiding what you wrote on them. Fold them all in
the same manner, so that no-one can make out which piece carries which color. Then
shuffle the pieces and pick 1 out of the 4.
Now, without opening the piece, can you tell me how likely is it that it carries the color
GREEN.
Are you certain it is going to be GREEN?
Are you certain it is not going to be GREEN?
Do you think it most likely will be GREEN?
Do you think it most likely will not be GREEN?
94
Let's Learn Artificial Intelligence - Base Module
Now open it, see and write down the color in the chart given below:
95
Now try the same exercise but with only 3 colors. Destroy the piece of paper containing
PINK.
Now shuffle and pick a piece again and write down the color again in the following table:
96
Let's Learn Artificial Intelligence - Base Module
Thus, in a nutshell:
Probability is a numerical measure of how likely an event is to happen.
Probability is measured in fractions between 0 and 1. (0 is impossible; 1 is certain.)
Sometimes, Probability is represented as a percentage -- from 0 percent to 100 percent.
You will learn more about Probability in Mathematics in higher classes. Hope
you look forward to it.
97
Re-arranging data and taking out the average is part of statistics.
You will learn more about Statistics in higher classes.
Doing Statistical calculations can become very easy if we use spreadsheets, which we
had discussed during the earlier Unit 3 on Data.
PROJECT
Remember the Data you had collected for 10 friends in the earlier unit and
entered it in a spreadsheet. I hope you had saved it. If not enter it again and
this time does not forget to save it.
Name
Age
Gender (Male/Female)
Height (You can measure this using a scale/ruler)
Hobby
Favorite Subject
Now using the tutorial provided earlier, calculate the following, using formulas:
The average age of your 10 friends
The average height of your 10 friends
Sum of the weight of friends put together
98
Let's Learn Artificial Intelligence - Base Module
Devin 100 55
Koel 97 54
Apu 90 55
Sameer 90 55
Babu 85 53
Aarti 70 54
Farah 61 55
Guna 54 45
Hira 35 51
Anik 28 52
PROJECT
After entering all the data of the 10 students in a spreadsheet in Excel, create
a Bar Chart in relation to the 2 variables (Marks and Days) one-by-one.
A bar graph is a two- or three-dimensional representation of data from the
simplest to the most complex.
1 Open Excel. Locate and open the spreadsheet from which you want to
make a bar chart.
2. Select all the data that you want to include in the bar chart.
3. Be sure to include the column and row headers, which will become
the labels in the bar chart. If you want different labels, type them in the
appropriate header cells.
4. Click on the Insert tab and then on Insert Column or BarChart button in
the Charts group. You’ll see many options when you select this button,
such as 2-D columns and 3-D columns, as well as 2-D and 3-D bars. For
these purposes, we’re selecting 2-D columns.
5. The chart will appear. You’ll also see horizontal bars giving the names of
your headers at the bottom of your graph.
99
6. Next, give your chart a name. Click on the Chart Title section at the top
of the graph and the section becomes editable.
7. Decide where to place the bar chart. You can place it on a separate
sheet, or you can embed it in the spreadsheet. Then save it.
8. If you want to delete the chart and start all over again, place your
cursor on the edge of the chart (you’ll get a pop-up that says “chart
area”) and press your Delete key.
Now try a line graph.
A pie chart is a visual representation of data and is used to display the amounts
of several categories relative to the total value of all categories. Pie charts are
used, for example, to show the individual collections by students in a fund raising
activity, and the individual contributions relative to the overall collections. Use a
bar graph, pie chart or line graph to communicate data and information in an
interesting manner. You can plot your data by hand or use a spreadsheet.
Given below are some types of charts that are commonly used to visualize data.
100
Let's Learn Artificial Intelligence - Base Module
There are four basic presentation types and their examples that you can use to
present your data:
Comparison: To show what is more and what is less
Composition: To show the sub-categories
Distribution: To show clusters
Relationship: To show how the value of one thing changes with
the change in another
Unless you are a statistician or a data analyst, you are most likely to use the two,
most common types of data analysis: Comparison or Composition.
Bar charts
101
Line charts
Pie charts
These should be used for simple compositions and not for comparisons or
distributions. For example, what are the benefits participants received from a
training program.
102
Let's Learn Artificial Intelligence - Base Module
Visit the link given below to explore various other types of data
visualization methods. Try and discuss with fellow students’ various uses
of these along with the advantages and disadvantages of each. Try and
use at least a few of them in different projects and assignments.
https://datavizcatalogue.com/
103
What have we learned
Machines learn differently from us. They use a lot of mathematics and learn by trying and
trying again. Two such mathematical concepts are Algebra and Probability. Algebra and
Probability are wonderful at helping us and computers in figuring out the unknown.
Algebra involves the use of letters that stand for various numbers. These are called ‘variables’.
We can create a formula using letters where the numbers can vary. This formula is called an
‘equation’. Machines use complex algebra to make their predictions.
Probability is a numerical measure of how likely an event is to happen. It is measured in
fractions between 0 and 1. (0 is impossible; 1 is certain.) Sometimes, Probability is represented
as a percentage -- from 0 percent to 100 percent. Machines use Probability to decide how
confident they are of their predictions and to what extent they can take chances.
Another tool that humans and computers use to find out interesting information hidden in
lots of data is Statistics. When lots of data is collected and kept in an ordered manner, then we
can find patterns in the data. These patterns can tell us interesting facts.
Doing statistical calculations can become very easy if we use Spreadsheets.
Data visualization is a method to represent information and data graphically using images
like charts, graphs and maps, to describe a story in a way that we can understand. It is very
interesting to see the pattern in the data.
There are four basic presentation types that you can use to present your data:
Comparison, Composition, Distribution, Relationship
Some commonly used types of charts are:
Bar charts Line charts Scatter plot charts Pie charts
As we have discussed the use of data in AI in this unit, now the next unit will focus on how can
we use huge datasets in AI to solve real-life problems.
104
Let's Learn Artificial Intelligence - Base Module
105
Let's Learn Artificial Intelligence - Base Module
UNIT 5
PROBLEM-SOLVING AND
DECISION MAKING
Topic Covered
Introduction of problem solving and algorithms |
Pseudocode – writing basic algorithms | Searching and sorting algorithms
107
5.1 INTRODUCTION TO PROBLEM SOLVING AND
ALGORITHMS
Through Artificial Intelligence, we ultimately want machines to be able to solve our
problems. Machines use logical reasoning to solve problems. Logical reasoning is the
process of applying rules to problem-solving.
Identification of
Understanding Choosing the Implementation
various solutions
the problem best solution of the solution.
to the problem
INPUTS OUTPUT
The various sports teams that are looking for
players.
The various sports you like. The sports team that you should join.
The various sports you play well.
108
Let's Learn Artificial Intelligence - Base Module
The order in which the instructions have to be carried out will be as follows:
1. Find out the available sports teams and their entry criteria
2. Then find out the best team for you
EXPLORE
http://www.aim.gov.in/pdf/Understanding_and_Algorithms.pdf
109
Algorithms are a standard requirement for problem-solving and are used to solve
various problems. Simple algorithms can solve complex problems too based on logic,
sequencing, repetition and writing down the conditions or rules applicable.
The key to any problem-solving task is to guide your process of thinking. We can do
this by asking ‘What if we did it this way?’ Exploring different ways of solving a problem
can help to find the best way to solve it.
When designing an algorithm, consider if there is more than one way of solving the
problem.
When designing an algorithm, there are two main areas to look at:
The big picture - What is the final goal we want to achieve?
The individual stages – What hurdles need to be overcome on the way to the goal?
Going back to our example:
There could be many ways to solve this problem, 3 are suggested below in the form of
algorithms:
If yes If yes
If yes
Recommend Recommend
sport sport Do you If no
play the
sport well?
If yes
Recommend
sport
110
Let's Learn Artificial Intelligence - Base Module
One can choose the best option by comparing the algorithms. Logical reasoning can
compare how effective and efficient, different solutions are. Another way would be to
input some data and see if the output is as desired or not, for each of the solutions.
Then feedback that input to the computer, which will then select the algorithm that
has the most desired feedback. Going back to our example:
Out of the 3 options provided:
OPTIONS
Option 3
This will give a list of sports
Option 1 Option 2
teams that you are eligible
This will give a list of sports This will give a list of sports for and that you play well as
teams that you are eligible for teams that you are eligible well as like, however if there
and that you play well, but you for and that you like, but you is no such sport where you
may not like. may not be good at. are eligible, you like the sport
and you play it well, then
what will you do.
So, you may go for the best solution which is a combination of options 2 and 3.
First run Option 3, if there are sports that it can recommend, choose those. If there are
no recommendations, then run Option 2.
See the algorithm on next page.
111
However, in case you
are not sure you know START
which sport you like;
then this algorithm Find available
sport
would not be the right
one, you could go for
option 1. Do you
If no Find next
meet
Thus you see, at this entry available
sport
stage, the algorithms criteria
can be accepted,
If yes
rejected, modified and
even combined in order
Do you If no
to get the best results like the
as per our goals. sport?
If yes
Do you
If no
play the
sport well?
If yes
Is there If no
a sport to START
recommend?
Find available
sport
Recommend
sport
Do you
If no Find next
meet
available
entry
sport
criteria
If yes
Do you If no
like the
sport?
If yes
Recommend
sport
112
Let's Learn Artificial Intelligence - Base Module
Here you feed in new data and get the solution for your problem. However, the
computer will also be able to tell how sure it with the solution based on the earlier
feedback provided by you.
113
Now see how your recipe compares to that of others.
In a group, try and see the various details that you are missing out for someone else to
follow the recipe and make it exactly as you wanted it to be?
Write a few points of what you would like to include in your perfect Burger.
Do you realize how detailed a recipe you will need, to make it the way you like it?
This is exactly why problem-solving algorithms can often become very detailed and
complex. Now if you compare different recipes of the sandwiches or burgers, can you
find a filling that you really like from within the groupand can you incorporate the
filling steps into your recipe?
114
Let's Learn Artificial Intelligence - Base Module
115
Often one may have different algorithms that work for different parts of the problem.
Like in our burger case, one may have a recipe section for the filling and a separate
section for the bread and even a third one for the assembling, garnishing and plating
presentation.
In a similar manner, as you did in this activity, you can breakdown any activity into
steps and write it as an algorithm and then use more data to modify the algorithm to
get the best results.
116
Let's Learn Artificial Intelligence - Base Module
Pseudocode is also written using some specific words and characters, which are
shown below:
Read / get / input These are used to give input. If it can have variable values,
then it is given a name.
Write / display / print These are used to give the output.
Relational operators: <, ≤, =, These are used to produce the Boolean values (i.e., true and
=, ≥, > false).
Logical operators ‘and’ ‘or’
“if and else” These expressions are used to express a conditional state-
ment.
USING PSEUDOCODE
Let us see how pseudo code is written.
Example 1: Given below is a pseudo code that tells if the number entered is not a 2 or a 4.
Pseudo Code:
Begin
Read enterednumber
If (enterednumber = 2) Write “your number is 2” Else if (enterednumber = 4)
Write “your number is 4”
Else Write “your number is not a 2 or 4”
END
117
Example 2: Given below is a pseudo-code that performs the following:
Ask a user to enter a number.
If the number is between 0 and 10, write the word ‘YES’.
If the number is between 10 and 20, write the word ‘MAYBE’.
If the number is between 20 and 30, write the word ‘NO’.
If it is any other number, write that it is not a correct option.
Pseudo Code:
Begin
Write “Please enter a number”
Read num
If (num >0 and num <= 10) Write YES
else If (num >10 and num <= 20) Write MAYBE
else If (num >20 and num <= 30) Write NO
else Write “not a correct option”
End
ACTIVITY
118
Let's Learn Artificial Intelligence - Base Module
2. Begin
Write “please enter 2 numbers”
Read num1, num2
Compute sumofnum=num1+num2
Write “The sum is”
Write sumofnum
End
ACTIVITY
119
Note: Pseudocode is not an actual programming language.
Program: It is words for instructing and a set of grammatical rules, a computer or
computing device need to perform specific tasks. The machine can’t read a program
directly, because it only understands machine code. But you can write stuff in a
computer language, and then a compiler or interpreter can make it understandable
to the computer.
Have you played the noughts and crosses game?
Let us make an algorithm for this game in Pseudocode.
I am a highly intelligent board. Let’s play noughts and crosses.
I am X, and I go first.
Move 1: Go in a corner.
Move 2: IF the other player did not
go there
THEN go in the opposite corner to
move 1.
ELSE go in a free corner.
Move 3: IF there are 2 Xs and a space
in a line
THEN go in that space.
ELSE IF there are 2 Os and a space
in a line
THEN go in that space.
ELSE go in a free corner.
Move 4: IF there are 2 Xs and a space
in a line
THEN go in that space.
ELSE IF there are 2 Os and a space
in a line
THEN go in that space.
ELSE go in a free corner.
Move 5: Go in the free space.
120
Let's Learn Artificial Intelligence - Base Module
So, Search algorithms prevent you from going through lots of data to find the
information you are searching for.
There are many different types of searching algorithms. Two of them are:
1. Serial or sequential search
2. Binary search
121
SEQUENTIAL SEARCH
A sequential search is when you look at each piece of data, one by one, and don’t stop
until you find what you are looking for.
For example:
We want to find the word “at” from a long list. Due to a lack of space, we shall take a
small list.
The list:
“he”
“you”
“me”
“this”
“that”
“it”
“is”
“which”
“at”
“from”
“us”
The computer would go to the first word “he” and ask is it the same as “at”.
If it is it will stop searching.
If it isn’t, it will go to the next word and repeat this process until it finds the
matching data.
In this case, it takes 9 guesses to find the word because it guesses as per the sequence.
So, if it was finding “me”, it would have taken just 3 guesses.
But imagine, if there were a million items on the list and our word was way down in
the sequence. Then the sequential method may not be the best option.
BINARY SEARCH
A binary search algorithm tells us how to efficiently find a specific value in an ordered
(sorted) list.
It is called ‘binary’ search because each time it searches a value in the list, it divides
the list into 2 parts. Then it checks if the desired value falls in part 1 or part 2. The one
in which the value falls is kept, and the other part is discarded.
122
Let's Learn Artificial Intelligence - Base Module
Now if we want to search the word “that” from this list, we will first sort it in alphabetical
order.
“at”
“from”
“he”
“is”
“it”
“me”
“that “
this”
“us”
“which”
“you”
First, the computer will go straight to the middle word, “me” and see if that matches
- because it doesn’t, the computer doesn’t need to check the 5 words on the top
because “that” will be alphabetically below “me”.
Now the computer finds the middle word of the bottom 5 of the list:
“this”
“that”
“us”
“which”
“you”
It finds the word “us”. It does not match, and the computer can eliminate the words
after “us” as well. That leaves only 2 words:
“this”
“that”
The computer can locate “that” as the second part of the list.
So, it is able to find the word in 3 guesses.
One of the main advantages of a binary search is that it is much quicker than a serial
search because the data that needs to be searched halves with each step. However,
the biggest problem with a binary search is that you can only use this if the data is
sorted into order.
123
WHY DO WE NEED SORTING ALGORITHMS?
A sorting algorithm will put items in a list into an order, such as alphabetical or
numerical order. For example, a list of student names could be sorted in alphabetical
order by surname, or a list of mobile numbers could be put into numerical order.
Sorting a list of items can take a long time, especially if it is a large list. A computer
program can be created to do this, making it much easier.
There are many types of sorting algorithms. Two of them are:
1. Bubble sort
2. Bucket sort
BUBBLE SORT
A bubble sort algorithm goes through a list of data a number of times, comparing two
items that are side by side to see which is out of order.
It will keep going through the list of data until all the data is sorted into order. Each
time the algorithm goes through the list, it is called a ‘pass’.
For example:
Suppose you have a list of marks obtained by students of a class. You want to sort
them from highest to lowest. A bubble sort can do this.
The list of marks is:
32, 97, 89, 63, 30 and 60
First pass
The highlighted numbers are the numbers that are being compared.
32, 97, 89, 63, 30, 60
This is the list before it is sorted.
32, 97, 89, 63, 30, 60
The first two numbers are compared. 97 is larger than 32, so they switch places.
97, 32, 89, 63, 30, 60
The next two numbers are compared. 89 is larger than 32, so they switch places.
97, 89, 32, 63, 30, 60
The next two numbers are compared. 63 is larger than 32, so they switch places.
97, 89, 63, 32, 30, 60
124
Let's Learn Artificial Intelligence - Base Module
The next two numbers are compared. 32 is larger than 30, so they remain as
they are.
97, 89, 63, 32, 30, 60
The next two numbers are compared. 60 is larger than 30, so they switch places.
97, 89, 63, 32, 60, 30
This is what the list looks like after the first pass.
The list is now more ordered than it was originally, but it isn’t yet fully in order of
youngest to oldest. The list needs to go through another pass to compare the
numbers again so that it can be sorted further.
Second pass
97, 89, 63, 32, 60, 30
The first two numbers are compared. 97 is larger than 89, so they remain as
they are.
97, 89, 63, 32, 60, 30
The next two numbers are compared. 89 is larger than 63, so they remain as
they are.
97, 89, 63, 32, 60, 30
The next two numbers are compared. 63 is larger than 32, so they remain as
they are.
97, 89, 63, 32, 60, 30
The next two numbers are compared. 60 is larger than 32, so they switch places.
97, 89, 63, 60, 32, 30
The next two numbers are compared. 32 is larger than 30, so no change occurs.
97, 89, 63, 60, 32, 30
125
This is how the list looks like after the second pass.
The set of data is now in ascending order from youngest to oldest. The algorithm,
though, does not know this yet as it made some changes in the second pass. The
algorithm will only recognize that the list is in order if it makes no changes in a pass.
The algorithm, therefore, needs to run for a third pass to compare the numbers again.
As no changes will be made, the algorithm will then recognize that the data is in order.
If the data being sorted is a large set of data, it may take several passes to get the data
sorted.
Here is another example: Let us take a stack of the cards with the numbers “7 3 6 1 9”,
and sort in ascending order using this algorithm. In each step, the algorithm compares
the elements written in bold. The top of the stack of cards is on the left-hand side.
First pass
( 7 6 3 1 9 ) ( 6 7 3 1 9 ) Here, the algorithm compares the first two elements
and swaps them.
(67319) (63719)
(63719) (63179)
( 6 3 1 7 9 ) ( 6 3 1 7 9 ) These elements are already in order, so the algorithm
does not swap them.
Second pass
(63179) (36179)
(36179) (31679)
(31679) (31679)
(31679) (31679)
Now, the stack of cards is almost sorted
126
Let's Learn Artificial Intelligence - Base Module
Third pass
(31679) (13679)
(13679) (13679)
(13679) (13679)
(13679) (1 3 6 7 9 )
Since there is no change in the runs now, finally, the array is sorted. But our
algorithm does not know this. The algorithm needs one whole pass without
any swap to know it is sorted.
and the algorithm can stop.
Fourth pass
(13679) (13679)
(13679) (13679)
(13679) (13679)
( 1 3 6 7 9 ) (1 3 6 7 9 )
Now the algorithm can stop.
BUCKET SORT
A bucket sort algorithm, separates a list of data into different collections of data, called
‘buckets’. Empty buckets are set up at the start of the sort and are filled with the
relevant data. Data is finally gathered back into a list after sorting each bucket.
For example:
Imagine that you have a list of people who you want to sort by age, from youngest to
oldest. A bucket sort can do this.
The list of ages is:
39, 12, 17, 36, 20, 47, 78 and 55
1. Set up a series of empty buckets.
127
2. Put the data into the correct buckets.
55
12 20 36 47
39 78
17
3. Buckets that have more than one item of data in them will be sorted (e.g. using
bubble sort).
12 17 36 39 47 55 78
20
4. The data will then be gathered from each bucket and put back into a list
The final list will be 12, 17, 20, 36, 39, 47, 55, 78.
COMPARISON OF SORTS
128
Let's Learn Artificial Intelligence - Base Module
CLASSIFICATION ALGORITHMS
We have discussed some basic Searching and Sorting Algorithms. AI uses many
other types of Algorithms as well; some of them can be very complex. Some of these
are called Classification, Regression or Clustering Algorithms. Basic algorithms like
Searching and Sorting could be parts of these AI algorithms.
Classification Algorithms can be somewhat complex, but still are some of the most
used AI Algorithms. The use of Classification Algorithm, for example, is when an AI
machine uses Supervised Learning and defines the rules with a training set and
then when we give it new objects, it classifies them according to the rules defined
previously. These rules could be different for different algorithms.
Let us see an example that will help us understand this better.
Here are is a set of pictures that represent different creatures.
129
What would be the first rule that we create to classify them?
Let us say the first rule is to classify them as having 4 legs or not.
The algorithm will start as follows:
Does it
have 4
legs?
Yes No
Does it
have 4
legs?
Yes No
Does it Does it
have have
scales? wings?
Yes No
Yes No
130
Let's Learn Artificial Intelligence - Base Module
Then we can keep identifying more rules to classify the creatures by,
such as mentioned shown below:
Does it
have 4
legs?
Yes No
Does it Does it
have have
scales? wings?
Yes No Yes No
Is it Does it Is it Does it
long? have tall? have fins?
horns?
Height is Height is
Length is Length is less Yes No more than less or No
more than than or equal Yes
2 cm 2 cm
2 cm equal to
than 2 cm
131
The example above shows a simple use of the classification algorithm. Other examples
are the AI that filters your email into SPAM and INBOX using a Classification AIgorithm
or AI.
Examples of some Classification Algorithms are Naïve Bayes, Logistic Regression,
Support Vector Machine (SVM), etc.
We will learn about these as well as Regression and Clustering Algorithms in the Step-
Up module.
ACTIVITY
132
Let's Learn Artificial Intelligence - Base Module
Rules:
Algorithm:
133
Now here is another set of items. Apply the classification algorithm you have
made to each of these items and see which group they fall into.
134
Let's Learn Artificial Intelligence - Base Module
Identification of
Understanding Choosing the Implementation
various solutions
the problem best solution of the solution.
to the problem
There are a number of basic things to know to really understand the problem:
What are the inputs into the problem?
What will be the output of the problem?
In what order do the instructions need to be carried out?
What decisions need to be made to solve the problem?
Are any areas of the problem repeated?
To identify the various solutions of the problem, it is broken down into logical steps. This is
called an Algorithm that can then be represented in the form of a flowchart. Simple algorithms
can solve complex problems too based on logic, sequencing, repetition and writing down the
conditions or rules applicable.
One can choose the best option by comparing the algorithms. Logical reasoning can be used
to compare how effective and efficient, different solutions are.
During the implementation of the solution, we can feed new data and get the solution to our
problem. However, the computer will also be able to tell how sure it is that with the solution
based on the earlier feedback provided.
Pseudocode is a simpler version of programming code in plain English which uses short
phrases to write code for a program before it is implemented in a specific programming
language.
There are many types of algorithms used in Artificial Intelligence applications for problem-
solving. The most simple and common problem-solving algorithms used by AI are:
Searching Algorithms: That can be used to help find the data we are seeking.
Sorting Algorithms: That can be used to will put items in a list into an order.
Now that we have learned how AI uses algorithms to solve real life problems, we will step
ahead in the world of AI languages. The medium to talk to a machine is by learning their
language. So the next Unit focuses on coding for AI, which will help instruct our machine
135
AI uses much more complex algorithms such as Classification, Regression or Clustering
Algorithms.
In Classification Algorithms, the AI machine uses supervised learning and defines the rules
with a training set and then when we give it new objects, it classifies them according to the
rules defined previously. These rules could be different for different algorithms.
Now that we have learned how AI uses algorithms to solve our real-life problems, we will step
ahead in the world of AI languages. The medium to talk to your machine is by learning their
language. So, the next unit focuses on coding for AI.
136
Let's Learn Artificial Intelligence - Base Module
UNIT 6
AI LANGUAGES
Topic Covered
AI and computer programming | Scratch | Python |
Top AI languages in 2020
139
6.1 AI AND COMPUTER PROGRAMMING
Do you aim to become a software engineer? Do you want to develop your own
mobile application? Do you want to develop AI? The path that will get you there is
Programming; some people also call it Coding.
A program is a set of instructions that are provided to the computer to perform a
certain function.
The execution of the program involves processing the raw data into the desired output
format.
High-level languages are the ones that are used to write these programs. These are
little complex as compared to the machine language or low-level language that the
computer understands.
Various languages help us in communicating with computers such as C, C++, C#,
Java, Python, R, etc. In between the high-level language and low-level language is
the assembly language which is also referred to as the symbolic machine code. An
assembler is used to convert the assembly code into executable machine code that
can be interpreted by the computer.
The most popular programming languages that are used in the current scenario are
C, Python, C++, Java, SCALA, C#, R, Ruby, Go, Swift and JavaScript. Let us study some
points that provide an idea about how AI and programming relate to each other.
Al involves finding insights and patterns inside data which is achieved by writing
and understanding complex algorithms.
It has been predicted that AI would serve as an important tool and assist the
programmers in the future. This will be done by robotically controlling the
repetitive tasks, thereby allowing the programmer to focus on more important
strategies.
140
Let's Learn Artificial Intelligence - Base Module
6.2 SCRATCH
Being a free visual programming language, Scratch was developed to create and
program animations, games, music, interactive stories and much more. The Lifelong
Kindergarten Group had developed Scratch at the MIT Media Lab. Currently, the
software is available in 50 different languages. Scratch can run on Windows, Macintosh
and Linux Operating Systems.
Scratch helps you share the creations with other people who are a part of the online
community. The platform is helpful for understanding the essential skills that are
required in the 21st century. Also, it helps young people learn how to think creatively,
reason systematically and work collaboratively.
With Scratch, the process of creating and programming innovative things has become
simplified.
The main motive behind the introduction of Scratch was to teach computational
thinking using a simple yet powerful building-block approach to software development.
The key feature in Scratch is that it focuses more on problem-solving skills rather than
a specific syntax. (Syntax refers to the rules to be followed that specify the correct
combined sequence of symbols that can be used to form a correctly structured
program using a given programming language.)
DOWNLOAD
141
TUTORIAL
https://scratch.mit.edu/projects/
editor/?tutorial=getStarted
PROJECT
Project Name: Smart Home System using Scratch and IBM Watson API
Project Description: Create AI in Scratch and find out how machine learning really
works!
Learning Outcome:
142
Let's Learn Artificial Intelligence - Base Module
EXPLORE
PROJECT
Learn and practice how to create a Smart Home System using Scratch
and IBM Watson API. Please find below the link where the module file
(pdf) can be downloaded:
https://www.aim.gov.in/smarthomeproject
6.3 PYTHON
Python is an object-oriented programming language created by Guido Rossum in
the year 1989. The language platform aims at simplifying the complex applications.
The Python scripts are stored in files which are named with the extension .py. Python
has interfaces to many operating systems such as Windows, Linux, Unix, etc. Also, it
is extensible to languages such as C and C++. Giants such as NASA, Google, YouTube,
BitTorrent use Python extensively in various projects.
The latest version of Python, i.e. Python 3, is being widely used in artificial intelligence,
natural language generation, neural networks and other advanced fields of computer
science.
143
WHY PYTHON FOR AI?
144
Let's Learn Artificial Intelligence - Base Module
ELEMENTS OF PYTHON
A variable in Python is a reserved memory location that store values as entered by the
user. In simpler terms, a variable provides data to the computer for further processing.
There are various ways by which we can represent variables. These can be declared by
any name or even alphabets like a, aa, abc, etc.
If “x” is the variable to be declared with a value “10” then we can write the following
command:
x=10
A convenient way to divide the code into useful blocks is by using what we call as a
function. A function can be understood as block of instructions that performs a single
and related action. The use of functions in a code makes it more readable and saves
the programmer’s time. Functions can be classified as built-in functions and user-
defined functions. Built-in functions as the name suggests are already a part of the
Python library. These are predefined in the Python programming interface. On the
other hand, user-defined functions are the functions that are invoked or called by
the user to be used in a code. These types of functions are not pre-existing and are
defined as per the user’s imagination.
145
Python has many built-in functions such as:
print( ) : Prints an object specified in the code as an output.
int( ) : Converts a string or a number datatype to an integer datatype.
len( ) : Returns the length of an object.
Syntax:
def functionname( parameters ):
“function_docstring”
function_suite
return [expression]
Let us understand how to use a function in a code.
Example:
Output
My Name is Samuel
I love Python programming
Note that the function “print(str)” is a built-in function whereas “printas( )” is a user-
defined function.
146
Let's Learn Artificial Intelligence - Base Module
TUTORIAL
https://docs.python.org/3/tutorial/introduction.html
Python Numbers
The values stored by Number data types are Numeric values. Number objects are only
valid when they are assigned values. For example:
var1=10
var2=50
In Python, there are four types of numerical types, i.e. int (signed integers), long (long
integers, can be octal or hexadecimal), float (floating point real values) and complex
(complex numbers).
12
147
Python Strings
Strings are sets of characters that are represented in quotation marks. In Python,
strings can be declared in single or double quotes. The subsets of strings can be
declared using the slice operator ( ).
str=’Hello World!’
print(str) # Prints complete string
print(str[0]) # Prints first character of the string
print(str[2:5]) # Prints characters starting from 3rd to 5th
print(str[2:]) # Prints string starting from 3rd character
print(str*2) # Prints string two times
print(str+”TEST”) # Prints concatenated string
Output
This code will generate the following output:
Hello World!
H
llo
llo World!
Hello World!Hello World!
Hello World!TEST
Python Lists
A list in Python contains items that are separated by commas and enclosed within the
square brackets.
list=[‘abcd’,786,2.23,’john’,70.2]
tinylist=[123,’john’]
148
Let's Learn Artificial Intelligence - Base Module
Output
Python Tuples
A tuple is another sequence data type that is quite similar to the list. A Python tuple
consists of a number of values that are separated by commas. Tuples and lists are
different in the sense that the lists are enclosed in brackets ( [ ] ) whereas tuples are
enclosed in parentheses ( ( ) ). Also, the elements and size of a list can be changed,
unlike tuples which cannot be updated. Hence, tuples can be understood as read-only
lists. Let us understand tuples from a Python code as given below:
tuple=(‘abcd’,786,2.23,’john’,70.2 )
tinytuple=(123,’john’)
149
print(tuple) # Prints complete list
print(tuple[0]) # Prints first element of the list
print(tuple[1:3]) # Prints elements starting from 2nd till 3rd
print(tuple[2:)]) # Prints elements starting from 3rd element
print(tinytuple*2) # Prints list two times
print(tuple+tinytuple) # Prints concatenated lists
Output
The code will generate the following output:
Dictionary in Python
Dictionary in Python refers to the unordered collection of data that stores data values
(like a map). The dictionaries in Python are written with curly brackets and consist of
keys and values. Let us see an example how a dictionary is used in Python.
Example:
mydict = {
“subject”: “Maths”,
“topic”: “Algebra”,
“marks”: 86
}
print(mydict)
150
Let's Learn Artificial Intelligence - Base Module
Output
The code will generate the following output::
1. For downloading and installing Python go to the webste and choose the
version to be installed
DOWNLOAD
2. As the download completes, click on the “Install Now” tab. The screen will
display the setup progress at this point.
3. Once the process is complete, the screen shows the message “Setup was
successful”.
151
4. Learn more about AI languages by going to the jetbrain website
DOWNLOAD
5. After the download is complete, click on the Run the exe link. Now, click Next
once the setup wizard starts.
6. You will be given an option to choose the installation path. Click “Next” once the
installation path has been selected.
7. In the subsequent screen, you will be given a choice to create a desktop shortcut.
You will be asked whether the shortcut is 32-bit or a 64-bit. Click on the “Next”
icon after you have selected the required option.
8. Next, select “JetBrains” under the start menu folder. Click on “Install” once selected.
10. Once the installation process is complete, the screen shows a message saying
PyCharm is installed on your computer. To run the program, select “Run
PyCharm Community Edition” box and click on “Finish”.
1. Open the PyCharm Editor installed on your system. An introductory screen will
show up on your system.
2. Click on “Create New Project” for creating your first project and starting to code
in Python.
152
Let's Learn Artificial Intelligence - Base Module
3. Select the location where you wish the project is to be created. You can change
the name to something meaningful such as “MyFirstProject” or “NewProject”.
Click on “Create”.
4. Next, go to the “File” menu and click on “New”. Click on the option “Python File”.
5. A pop-up window will appear where you can enter the filename such as “Hello
World” and hit “OK”.
6. Next, type a simple program, i.e. print(‘Hello World!’).
print(“Hello World!”)
7. Next, go to the “Run” menu and select “Run” for running the program. The
shortcut for this is Alt+Shift+F10.
8. The output of the program will be displayed at the bottom of the screen. `
Output
This code will generate the following output:
I love Python
Example: 2
To print the name of five Indian states, use the print () function as follows:
print(“Rajasthan”)
print(“Assam”)
print(“Uttar Pradesh”)
print(“Odisha”)
gp
print(“Jharkhand”) õK
YL[
ôKK
P
PH
};
DE
i CO
{.
uj
153
Output
Rajasthan
Assam
Uttar Pradesh
Odisha
Jharkhand
Output
I love Python
This is my first Python project
154
Let's Learn Artificial Intelligence - Base Module
Output
Output
155
The following program would return an undefined output:
a= “Python”
b=100
print(“a + b”)
For making this program to return a defined output, it should be written as:
a= “Python”
b=100
print(a+str(b))
Output
This code will generate the following output:
Python100
156
Let's Learn Artificial Intelligence - Base Module
Output
This code will generate the following output:
Python version
3.7.3 (default, Nov 12 2019, 11:53:27
[GCC 5.4.0 20190611]
Version info.
sys.version_info(major=3, minor=5, micro=2, releaselevel=’final’, serial=0)
Exercises:
1. Assume the following list and write a program to print all the given elements that
are less than 10.
2. Provide a command to output all the prime numbers from the given list.
157
6.4 TOP AI LANGUAGES IN 2020
The scientists of Artificial Intelligence are continuously evolving the AI languages
to better suit the needs of developers. Following are some links about lastest AI
language:
EXPLORE
https://www.rankred.com/best-artificial-
intelligence-programming-language/
https://www.techindiatoday.com/programming-
languages-for-artificial-intelligence/
https://www.springboard.com/blog/best-
programming-language-for-ai/
158
Let's Learn Artificial Intelligence - Base Module
159
Let's Learn Artificial Intelligence - Base Module
UNIT 7
ETHICS AND AI
Topic Covered
Ethics and AI
161
7.1 ETHICS AND AI
AI is a comparatively new field and is likely to impact humanity in a big way. There are
many things to be considered to ensure that it does not harm us in any way or lead to
any unfair actions.
Given below are some scenarios that will help you understand the kind of ethical is-
sues that are appearing due to AI.
162
Let's Learn Artificial Intelligence - Base Module
Think of information about yourself that you would not like to share with others. What
would that data or information be?
Think about information about your school or home, that if ended up in the hands of
the wrong type of people can be used to harm students and teachers. What kind of
data might that be?
163
As discussed in Unit 3, Datasets may be public or private. Therefore, people and
organizations have a responsibility to ensure that only safe data finds its way into
public Datasets. Similarly, data in Private Datasets too need some authorization and
permission from those to whom the data belongs for its collection, privacy control,
and use. Laws on Data including its collection, storage, and usage are evolving and
becoming more and more strict, this is another area where there will be a huge need
for experts in the future, including legislators, lawyers, consultants and analysts who
will address controversy, disputes, and risks of data.
Artificial intelligence can cause controversy and put people in danger or at risk of
injustice in many different ways. These risks could be on account of many things apart
from the leakage of data.
EXPLORE
https://www.youtube.com/watch?time_
continue=175&v=vgUWKXVvO9Q&feature=emb_logo
164
Let's Learn Artificial Intelligence - Base Module
When you are browsing the internet, watching movies, making purchases online, etc.
there are algorithms in the background that are connecting the dots and making
recommendations to you for further content and purchases including advertising
based on your profile and activity information.
On the other hand, there are already instances where organizations are accused of
trying to block and filter content for specific audiences based on people’s political
affiliations, religious beliefs, etc.
Every time you access the internet if an AI can make recommendations to you based
on your information available online and can withhold information if it chooses without
you knowing…
How do you think this works?
How can this impact you and others?
What are the potential advantages or risks of this?
165
Ethical Issues – Scenario 3
If the AI algorithm that a robot or car is working on proves to be wrong and
it causes an accident, who will be held responsible?
The owner,
The municipality that allowed these cars on the road
The programmer
The manufacturer
Already there is a debate that if the AI algorithm of self-driving cars or robot had to
choose between two potential accident victims, which one should they choose, or
should they be programmed to choose at all?
AUTONOMOUS
CAR
166
Let's Learn Artificial Intelligence - Base Module
EXPLORE
https://www.theatlantic.com/technology/archive/2013/10/the-ethics-of-
autonomous-cars/280360/
People are witnessing artificial intelligence and automation replace several jobs
already and are worried that more and more AI applications will cause large-scale
loss of jobs and increase unemployment. Widespread use of AI in the workplace may
further cause greater inequality as fewer people may find jobs and those companies
which employ more artificial intelligence agents may likely be profitable, making
more money than others. AI companies being more profitable is likely to concentrate
wealth in the hands of fewer companies and people. Thus, adding to the inequality in
the world.
167
Thus, if an AI makes wrong decisions for people either by mistake or deliberately,
they may have to follow it without question. Those who have the power to change
the algorithms and the AI can thus create conditions to benefit themselves and put
others are at a disadvantage. Therefore, giving rise to discrimination, exploitation
and injustice. AI Explainability is the common term used for how transparent and
understandable an AI is?
There are groups of people who are considering this possibility too. They are trying to
find out how to stay in control of a complex, intelligent system.
Being fooled by machines is a very real possibility. Several people believe that they
have the right to know if they are chatting with a human or a machine. Artificially
intelligent bots are becoming better and better at modelling human conversation
and relationships.
In 2015, a bot named Eugene Goostman won the Turing Challenge for the first time.
In this challenge, human raters used text input to chat with an unknown entity,
then guessed whether they had been chatting with a human or a machine. Eugene
Goostman fooled more than half of the human raters into thinking they had been
talking to a human being. (Bossmann, 2016)
168
Let's Learn Artificial Intelligence - Base Module
(When you watch the video, keep a pen and paper handy. Do not miss out to record the
words you don’t understand and look these up in the dictionary…such as non-sequitur)
EXPLORE
To know more about the Turing Test and its Challenges click on the link
below.
https://www.youtube.com/watch?time_continue=232&v=3wLqsRLvV-
c&feature=emb_logo
Imagine you meet someone in your neighborhood and become friends. After
spending a year together, you suddenly find out the person you thought
of as a friend is, in fact, an AI machine. A 45-year-old man programs and
operates the machine.
How would you feel, what will be your thoughts and concerns?.
Many times, we chat online on websites with chatbots. Who could be an AI programmed
to respond to various types of queries? Some websites declare it transparently that it
is a “Bot” that you are chatting with. However, some organizations may not do so, and
that may make you uncomfortable.
169
While training the machine, developers may feed their own biases into it. i.e. their
personal preferences or aversions. A bias programmed into an AI can cause unfair
decision making on the part of the machine.
EXPLORE
https://www.youtube.com/watch?time_ https://www.ted.com/talks/joy_
continue=1&v=ixDHOAOzjd8&feature= buolamwini_how_i_m_fighting_
emb_logo bias_in_algorithms?referrer=playlist-
what_are_we_really_teaching_
ai&language=en
It is not easy to determine if an algorithm is biased or fair, even for experts who
develop AI. In many cases, the details in an algorithm are often considered proprietary
(owned) and confidential, which is a source of financial value to its owners; therefore,
the owners guard it very closely.
For complex applications, the algorithms are also complex, and even those who have
created these don’t know how they exactly work. On top of that, now we are entering
into an area where AI is further creating AI. With the possibility of no transparency and
real control, this is creating a furore among ethicists. Our inability to see the inside of
an algorithm and understand how it arrives at a decision is often called the AI’s Black
Box problem.
What if a talking machine learns to abuse on its own, can we get offended
and sue it?
170
Let's Learn Artificial Intelligence - Base Module
We are aiming to make machines that can act, think and learn like humans.
We are even making them recognize and respond appropriately to feelings
and emotions. Should at some point in their evolution, they be considered to
have the same rights as humans and be treated accordingly?
ACTIVITY
Take one of the above ten ethical concerns and find examples actual or
potential and research what impact could this have in different contexts?
Some of the contexts could be Healthcare, Banking, Insurance and Finance,
Online Matrimony and Dating, Law and Justice, etc. Also, find out what action
can be taken by society to address these? Make a presentation to others in
your class detailing the above.
171
EXPLORE
https://www.ted.com/talks/kriti_sharma_how_to_keep_human_bias_out_of_
ai?referrer=playlist-what_are_we_really_teaching_ai&language=en
EXPLORE
You can access content on AI and Ethics at the links below to explore
various dimensions of it.
https://montrealethics.ai/blog/
EXPLORE
Here are the ten challenges and risks of AI. Click the link below.
https://www.youtube.com/watch?v=1oeoosMrJz4
172
Let's Learn Artificial Intelligence - Base Module
Congratulations on completing the base module content in AI. We have some more
exciting areas for you to explore in case you are interested on the next page. The next
module, Step-up AI, will help develop further pracitcal skills through a number of projects
and higher level maths and programming abilities. We hope you will engage and enjoy
this journey for becoming an AI enthusiast.
173
Here’s more for the AI Enthusiast !
To further engage with AI, you can visit the following links where you can find current
developments, learning materials AI-enabled and projects to execute.
EXPLORE
https://scratch.mit.edu/search/
projects?q=artificial%20intelligence
https://education.microsoft.
com/en-us/course/9534f9d9/0
https://aischool.microsoft.com/en-us/home
EXPLORE
Explore projects in AI
https://create.arduino.cc/projecthub/electropeak/
speak-to-arduino-and-control-it-with-google-
assistant-3791ee?ref=tag&ref_id=artificial%20
intelligence&offset=3
https://www.microsoft.com/en-
us/ai/ai-lab-projects
174
Let's Learn Artificial Intelligence - Base Module
EXPLORE
Spark is a creative tool powered by AI, free for education and licenses are
generated by Adobe team. Students can create, id and passwords by the
process given on the website
https://helpx.adobe.com/enterprise/using/edu-deployment-guide.html
175
ACKNOWLEDGEMENT
We thank all contributors and facilitators who have supported the development of this
Module. We thank the NASSCOM team for facilitating the Industry-Academia workgroup in
this endeavor.
Companies Represented
176
Workgroup Members
01. Arokiasamy Stephen Raj Head of Data Science and AI Robert Bosch Engineering &
Business Solutions Pvt. Ltd.
02. Ashutosh Raina Doctoral Research Scholar Edu. Tech. - IDP, IIT-Bombay
03. Asna Siddiqui Program Lead - INDIAai NASSCOM
04. Atul Udupi Chief Innovation Officer XcelCorp
05. BC. Jainaressh Account Manager UNITY 3D - Education
06. Ganesh Vaitheeswaran Senior Architect SAP Labs
07. Ganeshan Rajan Senior Data and Information Architect GE Healthcare
08. Garima Babbar Head Education & Skill Development Adobe Systems India Pvt. Ltd.
Programs, India & South Asia
09. Jassi Dimple Director PROGILENCE Capability
Development Pvt. Ltd.
10. Jibu Elias Content & Research Lead, INDIAai NASSCOM
11. Manish Kumar Managing Director IOT School
12. Naba Suroor Young Professional Atal Innovation Mission, Niti
Aayog
13. Narendra Chaudhary Field Engineer UNITY Technologies
14. Prakash Goteti Principal Consultant, AI and Analytics TechMahindra
15. Rahul Lodhe Senior Director Engineering SAP Labs
16. Ramswaroop Mishra Data Analytics & AI Competency Head WIPRO
17. Ronak Jogeshwar Innovation Lead Atal Innovation Mission, Niti
Aayog
18. S Manish Singh Managing Director PROGILENCE Capability
Development Pvt. Ltd.
19. Shruti Verma Head - Marketing and Operations, UNITY Technologies
Indian Sub-Continent
20. Snehasis Bagchi OEM Partner Lead - Future Skills NASSCOM
21. Sridhar Iyer Convener Edu. Tech. - IDP, IIT-Bombay
22. UnniKrishnan AR Head Business- Higher Education NVIDIA
& Research
23. Vinnie Jauhari Director - Education Advocacy Microsoft Corporation India
Pvt. Ltd.
24. Yudhisther Yadav Lead Strategic Initiatives – FutureSkills NASSCOM
177