AI 101 | Introduction to Artificial Intelligence
Tags: beginners, github, machinelearning, deeplearning
Published: 2021-01-08 06:00:25

## Introduction

If you are someone who is intrigued by self-driving cars, androids that can converse fluently or software that can diagnose tens of thousands of patients in a matter of minutes then artificial intelligence is the field for you!

![1](https://dev-to-uploads.s3.amazonaws.com/i/nhw6zortbuijmyxplet6.png) 

This post covers basic components of the field, goes over the optimal learning path to take and includes a number of resources to help get you started. So no need to worry about all those complicated terms, super lengthy videos and numerous courses available online. Just follow this post and observe as we simplify AI for you!

![2](https://dev-to-uploads.s3.amazonaws.com/i/zq7xjby52zckea63bhjl.png)

## Table of Contents

* [About this Post](#chapter-1)
* [Learning Objectives](#chapter-2)
* [What is Artificial Intelligence?](#chapter-3)
* [The Power & Uses of AI](#chapter-4)
* [Components of AI](#chapter-5)
* [Python Learning Resources](#chapter-6)
* [Logic & Rules-Based Approach](#chapter-7)
* [Intro to Machine Learning](#chapter-8)
* [First AI Classifier (hands-on)](#chapter-9)
* [Classic Machine Learning](#chapter-10)
* [Intro to Deep Learning](#chapter-11)
* [Machine Learning vs. Deep Learning](#chapter-12)
* [More on Deep Learning](#chapter-13)
* [Theoretical & Hands-on Notebooks](#chapter-14)
* [Problems with ML & DL](#chapter-15)
* [Cloud Services: Microsoft Azure](#chapter-16)
* [Conclusion](#chapter-17)

## About this Post <a name="chapter-1"></a>

This post covers content discussed in the [AI 101 | Introduction to Artificial Intelligence](https://www.facebook.com/events/429419051422702) hands-on online workshop conducted by [Microsoft Learn Student Ambassadors - Islamabad] (https://www.facebook.com/mlsaislamabad), [Student Ambassadors Club - Karachi](https://www.facebook.com/mlsa.community) and [NUST ACM Student Chapter] (https://www.facebook.com/NUST.ACM).

![3](https://dev-to-uploads.s3.amazonaws.com/i/cjr77r8en21p1yw0dmdj.png) 
 
If you prefer watching the recording for the session, it is available [here](https://youtu.be/3K6bz7KCdFc). 

__Note: You do not need to watch the recording to understand this post, the link has only been provided for learning purposes.__

## Learning Objectives <a name="chapter-2"></a>

* Understanding the applications of AI
* Understanding & differentiating AI components 
* Implementing a Basic AI classifier (Hands-on)
* Discussing Learning Paths & Resources
* Understanding Cloud Technologies in AI  
* Discussing Opportunities in AI

## What is Artificial Intelligence? <a name="chapter-3"></a>

We are living in the modern age of problem solving where we have based entire fields on ideas of science and mathematics to identify and solve problems. Artificial Intelligence, although an extremely broad term, can be thought of as a means of _using Computers to solve problems or make automated decisions for tasks that, when done by humans, typically require intelligence_. 

![1](https://dev-to-uploads.s3.amazonaws.com/i/bwentaouvnb05z4rfbsl.jpg) 

A classic example would be shape identification. The following picture contains a few shapes that can easily be identified by a toddler.

![2](https://dev-to-uploads.s3.amazonaws.com/i/zugxgboboge2z4ulcba4.png)

So this task requires some degree of intelligence and hence if a computer program were able to do it, we could say it does so using artificial intelligence!

## The Power & Uses of AI <a name="chapter-4"></a>

Shape identification was pretty impressive back in the 1990s, but the applications of AI have grown ever since that time. Decades of research and technology have allowed us to do things that were once considered impossible! Let us dive into the vast capabilities of this field.

The following is a short video of a [humanoid robot](https://en.wikipedia.org/wiki/Humanoid_robot) called [Sophia](https://en.wikipedia.org/wiki/Sophia_(robot)) being interviewed by the [Stylist Magazine](https://www.stylist.co.uk/).

{% youtube ZQrKFAAlxO4 %}

Now a lot of people have this confusion that AI refers to such robots (like Sophia) that can, to an extent, mimic human brain functionality to produce abstract thought. When this is entirely false. Robots, like Sophia, make use of an AI backend that allow them to _indulge in conversation_, this is regardless of a humanoid exterior.

So what exactly are the applications of AI other than robotics? Well, here are a few to help you get started:

#### Data Processing & Cleaning

Corporate giants maintain tens of thousands of customers' data on a daily basis. Now this task can be both tedious and prone to error if assigned to employees, instead they opt for an AI solution to learn certain patterns and trends overtime to clean or process incorrect, incomplete, irrelevant, duplicated, or improperly formatted customer data. 

#### Speech Recognition

![3](https://dev-to-uploads.s3.amazonaws.com/i/y1aavfhnd8h3j12w4rfe.jpg)

Ever used [Siri](https://www.apple.com/siri/), [Alexa](https://www.alexa.com/), [Google Assistant](https://assistant.google.com/) or any voice-activated piece of technology? Ever wondered _how_ a machine that communicates in binary (1's and 0's) is able to understand you? Well, the answer is the vast field of speech recognition. Here, an AI is trained to understand commands, phrases and even words! Speech recognition is used immensely and almost everywhere, from virtual assistants in our phones, to biometric verification for security purposes and even online banking!

#### Natural Language Processing

This powerful field of AI involves analyzing human language and deriving understanding based on language structure and context.

For example in the fill-in-the-blank: **Man** is to **Woman** what **King** is to **____**, We as humans know that the most suitable replacement to the blank would be **Queen**, as it gives us a good analogy statement. This is what we are trying to teach our AI as well and can be done by training it on huge amounts of linguistic data. 

Applications of this field include the predictive keyboard.

![4](https://dev-to-uploads.s3.amazonaws.com/i/rz2lfiyopokz6tyg0p8y.png) 

#### Image Processing & Transformation

Many amazing artworks have effortlessly been created with the help of AI in this field. Below is an example of convolving a picture of a dog with [Vincent van Gogh](https://en.wikipedia.org/wiki/Vincent_van_Gogh)'s famous [Starry Night](https://en.wikipedia.org/wiki/The_Starry_Night).

![6](https://dev-to-uploads.s3.amazonaws.com/i/7fuh8dzq6vgtw3w01hlr.jpeg) 
 
For further clarity, an AI is needed to extract the essence of both pictures and put them together.

#### Computer Vision

This field makes use of the ideas behind object detection and identification in images to make applications like self-driving cars a reality. 

![7](https://dev-to-uploads.s3.amazonaws.com/i/umy7dtbndljff0b4422p.png)

As seen in the image above, an AI has successfully identified each object and can now make decisions based on this. Incase of a self driving car, it will either go or stop depending on the number and position of people on the street.

## Components of AI <a name="chapter-5"></a>

Artificial Intelligence has been around for a while now and modern breakthroughs in technology have allowed for greater advancements in this field. Using ideas of __Machine Learning__ and __Deep Learning__, we are now able to achieve the extraordinary. As you can observe in the diagram below, Machine Learning, or ML, and Deep Learning, or DL, are simply the subfields of AI, which will be discussed to some extend in this post.

![10](https://dev-to-uploads.s3.amazonaws.com/i/8ht6yrjdwan8g2csiumk.png)

So how should one go about studying this field? Maybe you are someone who wants to start with AI, maybe you are stuck on ML or perhaps confused as to where to go when done with DL? Should you start with DL, then go to ML and only then learn about the broader field of AI? With so much content out there, one can get quite confused about which learning path to take. So to make things easier, I'll be sharing my learning path here. It may not be the best path to take but it will give you a structure while studying for AI.

#### Recommended Learning Path

* Learn Python
* Study Classic Machine Learning Examples 
* Make use of Deep Learning Libraries
* Implement Cloud Technology Practices

Note: Key-elements of this learning path will be discussed throughout this post.

### Python Learning Resources <a name="chapter-6"></a>

Python is a powerful [programming language](https://en.wikipedia.org/wiki/Programming_language) that will allow us to create our AI [models](https://en.wikipedia.org/wiki/Programming_model). We choose python because it allows us to make use of many Deep Learning libraries that can make programming much more easier. More on that when we talk about Deep Learning.

Follow these resources to get command on this language in no time! Also, if you are someone that is proficient in another language like C, C++, Java etc. then the learning process will be easier for you.

#### Resource 1: Watch Python in Action

The following is a video by [howCode](https://www.youtube.com/channel/UCovR8D97-8qmQ8hWQW0d3ew) and goes over all the basics of Python in just 5 minutes!

{% youtube I2wURDqiXdM %}

#### Resource 2: Signup for HackerRank

Programming requires practice and this website has a ton of python-related problems for you to solve and help improve your skills for free.

![11](https://dev-to-uploads.s3.amazonaws.com/i/eu1dlzf9vj2zkdreitka.PNG)

You can signup [here](https://www.hackerrank.com/auth/signup).

#### Resource 3: Python Repository

The following [GitHub](https://github.com/) repository contains python problems taken from HackerRank along with solutions. You can make use of the code here for learning and evaluation purposes.

{% github MuizAlvi/Python_Programs %}

## Logic & Rules-Based Approach <a name="chapter-7"></a>

Remember this diagram?

![11](https://dev-to-uploads.s3.amazonaws.com/i/8ht6yrjdwan8g2csiumk.png)

You've already been made familiar with the Machine Learning and Deep Learning subsets of this field, but what about the portion of AI that is not enclosed by either subset? Well, that is the part of AI that makes use of a logical and rules-based approach, and by that we simply mean [if-else statements](https://www.geeksforgeeks.org/python-if-else/)! 

There was this [meme](https://en.wikipedia.org/wiki/Internet_meme) that circulated back in 2014:

![Meme](https://dev-to-uploads.s3.amazonaws.com/i/1moognwaegl3uyaxjh7v.jpg)

So how accurate is this statement anyways? can we create AI using simple if-else statements? Well the answer is yes, we can do that but this comes with a lot of limitations.

First of all, to program an AI like [Sophia](https://en.wikipedia.org/wiki/Sophia_(robot)) one would have to write about 50,000 such statements, which is quite laborious. Secondly, it would take a processor quite a lot of time to execute such a code, making it quite inefficient as well. 

So is there a way to make use of this approach? Yes! Some Deep Learning models make use of this method by combining if-else statements with [Object Oriented Programming](https://www.geeksforgeeks.org/object-oriented-programming-in-python-set-1-class-and-its-members/). Here is a sample code to help your understanding:

```python
if (road.people == None):
   car.move()
else:
   car.stop()
```

In this program, the car only moves when people are not seen on the road.

So in conclusion, _If-else Statements are a very limited approach to solving AI problems_.

## Intro to Machine Learning <a name="chapter-8"></a>

Now let us move towards a more refined version of AI, known as Machine Learning. In this subfield, we make use of [algorithms](https://en.wikipedia.org/wiki/Algorithm#:~:text=In%20mathematics%20and%20computer%20science,or%20to%20perform%20a%20computation.) that find patterns in data and infer rules on their own. So what do we mean by learning through data? Well let's first look at the way us humans learn. Consider the picture below:

![6](https://dev-to-uploads.s3.amazonaws.com/i/l8p6g0pjq4hi8qhip4h4.jpg)

In this image, we are able to identify the animal on the left as a 'dog' and on the right as a 'cat'. Ever wondered how we were able to do this? Well chances are that you have seen multiple cats and dogs in real life, books or on television etc. and are now able to identify them with ease. Machine Learning works in a similar way, we give a program some data and tell it to learn features (like whiskers, ear size etc.) it then adjusts its learnable parameter(s) according to this data and only then is made able to produce a desired output. More on learnable parameters in the following example. 

## First AI Classifier (hands-on) <a name="chapter-9"></a>

Now let us try to build our first AI classifier. Read the problem statement below to understand what we are trying to build:

#### Problem Statement:  

A computer is given a dataset of 'labeled' animal heights to help train its learnable parameter 'x'. Once trained, the computer will be given a height value and will have to determine whether this height belongs to a 'cat' or 'dog'

Algorithm: When the computer receives a height value greater than x, it outputs 'dog' and if less than or equal to x then it outputs 'cat'

Dataset:

![7](https://dev-to-uploads.s3.amazonaws.com/i/c8r54qo0ubivfopc3qjs.PNG)

Now before moving towards the code, you should first try to figure out the unknown label for the 50 cm height on your own. (Hint: It will help to write down all heights and labels in ascending order). Once done, follow the steps below to create your first AI classifier:

####  Step 1: Create Data Variables & Lists:

```python
data = [20, 60, 25, 18, 40] 
label = ['cat', 'dog', 'cat', 'cat', 'dog']
```
The code above is our training data taken from the table in the problem statement. Each data and label has been placed in a list in respective order. Our program will learn from this data.

```python
x = 0 # learning parameter
H = 50 
```
We have now initialize our learnable parameter 'x'. The program will set the value of x according to our data. The variable 'H' is the height of the animal we need to classify.

#### Step 2: Train the Program

The code snippet below simply sets a value for 'x' on the basis of our data and labels being used.

```python
for i in range(0, len(data)): 
    if (data[i] > x) & (label[i] == 'cat'): x = data[i]
```
When you are done running this code, the optimum value of 'x' will have been set.

#### Step 3: Test the Program

This is a simple if-else statement that compares 'H' with 'x' and determines whether the animal is a 'cat' or 'dog' based on its height.

```python
if x <= H: print('dog') 
else: print ('cat')
```
Based on the data the output should be **dog**.

Ands that's it! you have successfully built, trained and tested your first AI classifier! Now the learning outcome here is that a model extracts features from data and sets its learnable parameter according to these features. It then uses its learnable parameter to predict outcomes on test data.

#### Full Code

This is what the final form of your code should look like after completing all the steps. I have added comments as well for better understanding.

```python

# Training

data = [20, 60, 25, 18, 40] # Training dataset 
label = ['cat', 'dog', 'cat', 'cat', 'dog'] # Training dataset labels

x = 0 # initial value for x
H = 50 # Test data

for i in range(0, len(data)): 
    if (data[i] > x) & (label[i] == 'cat'): x = data[i]

# Testing

if x <= H: print('dog') 
else: print ('cat')
```

## Classic Machine Learning <a name="chapter-10"></a>

Machine Learning has been around for quite sometime now. We know that Deep Learning is a subset of ML, so let us discuss the part of ML that does not fall in the DL category. Namely the 'Classic' version of ML. 

![10](https://dev-to-uploads.s3.amazonaws.com/i/m9r44wf4cex9awxl1yw1.png)  

I would now like to ask you a question. **Was the above AI classifier an example of Classic Machine Learning?** 

The answer is **no**. This is because of [Tom Mitchell](https://en.wikipedia.org/wiki/Tom_M._Mitchell)'s modern definition of ML: _"A computer program is said to learn from experience E with respect to some class of tasks T and performance measure P, if its performance at tasks in T, as measured by P, improves with experience E."_ In our classifier, the program lacks a performance measure and so is **not** an example of Machine Learning. It was only presented to give you an idea about how computers learn.

Classic Machine Learning follows the same principles: it extracts features from data, adjusts its learnable parameters (i.e. weight and bias) but also accounts for performance. In layman's terms this means that our program is learning through its mistakes. We will not go into how this works or, the math behind this learning, as it is beyond the scope of this post, this is an introductory post after all, but I hope the example gave you some basic intuition about _how_ ML works.

#### Applications

There are many applications of Classic Machine Learning. Cooperate giants make use of spam filters that train on spam emails, learn words like 'Nigerian prince' or 'free survey' overtime and filter out such emails. Allowing for a cleaner workspace. 

![11](https://dev-to-uploads.s3.amazonaws.com/i/7u90ywodztpc7fra6h9i.png)

Another application is image classification, which will be discussed in detail later in this post.

#### Resources

The best way to start with ML would be with a course by [Andrew NG](https://en.wikipedia.org/wiki/Andrew_Ng) available on [Coursera](www.coursera.org). This is a free course and covers topics related to ML extensively. You can check it out [here](https://www.coursera.org/learn/machine-learning).

For people already done with ML courses and wish to strengthen their ML concepts with some intro to DL, there's this [DeepLizard](https://deeplizard.com/) playlist covering fundamentals for both ML and DL. You can find this playlist [here](https://www.youtube.com/playlist?list=PLZbbT5o_s2xq7LwI2y8_QtvuXZedL6tQU).

## Intro to Deep Learning <a name="chapter-11"></a>

Deep Learning is a sub-field of Machine Learning that allows for us to overcome limitations of Classic Machine Learning and train powerful models with revolutionary applications. This field makes use of [Neural Networks](https://en.wikipedia.org/wiki/Artificial_neural_network) (shown below) for calculations and is quite [GPU](https://en.wikipedia.org/wiki/Graphics_processing_unit) intensive. 

![12](https://dev-to-uploads.s3.amazonaws.com/i/nj4upc7nvefcpxjrfpm6.png) 

In the diagram above, each circle represents a node and each column of nodes represent a layer. Check out the [Build your first Neural Network with the Keras API](https://dev.to/muizalvi/build-your-first-neural-network-with-the-keras-api-35b4) tutorial to learn all about Neural Networks and their implementation.

## Machine Learning vs. Deep Learning <a name="chapter-12"></a>

If you are someone who understands the concepts of ML and DL but aren't exactly aware of the technical differences between both. Then this section is just for you! Let us look at the differences between the approach taken by both subfields by the help of an image classification example. The following is a picture of me taken a few weeks ago. Our models will try to train themself on this image. 

![1](https://dev-to-uploads.s3.amazonaws.com/i/bjbafffh3spqnasrnjlr.png) 

#### Machine Learning Approach

An ML model will first extract features, for instance face shape and distance between pupils _relative_ to distance between forehead and chin.

![2](https://dev-to-uploads.s3.amazonaws.com/i/m2a2ga7md6dc1tuy6kmc.png)

The model will then adjust its learnable parameter according to these features.

#### Deep Learning Approach

A DL model, on the other hand, takes the image as a whole and passes it through a Neural Network. The Neural Net for our problem looks like this:

![8](https://dev-to-uploads.s3.amazonaws.com/i/g1khbvrp6p01x5aw9at9.jpeg)
 
This Network has been programmed to _slice up_ an image and take each slice as an input for each input node (nodes on the left most side). The image will be split as follows:

![3](https://dev-to-uploads.s3.amazonaws.com/i/zyjt7omq5rjjwtnrnsmx.png)

Now each input node will extract some feature from each slice on its own and pass it to the next node to find out another feature and so on. The nodes are learning the features on their own. These features could be anything, like _hair color_, _eye shape_, _lip shape_ and so on. This is exactly why DL is GPU intensive, as each node is carrying out complex calculations to extract and learn features. This is also why DL models are far more accurate as compared to ML models.

## More on Deep Learning <a name="chapter-13"></a>

The applications of DL include self-driving cars, object detection algorithms (like the one discussed above) and [Deepfakes](https://en.wikipedia.org/wiki/Deepfake).

The most efficient way for you to create DL models is simply by implementing certain Python libraries in your code. These libraries make it super easy to build, train, validate and test your Deep Learning models. Examples of such libraries are [tensorflow](https://www.tensorflow.org/), [keras](https://keras.io/), [pytorch](https://pytorch.org/) and [fast.ai](https://www.fast.ai/). 

#### Resources

You can access these libraries and many more using [Anaconda](https://www.anaconda.com/). You can learn all about acquiring Anaconda and installing DL libraries in the [Setting up Python environments using Anaconda](https://dev.to/muizalvi/setting-up-python-environments-using-anaconda-1a2m) tutorial.

![13](https://dev-to-uploads.s3.amazonaws.com/i/n67jc48dadonxfqnv2ti.PNG) 

You can also check out the Deep Learning Specialization course by [Andrew NG](https://en.wikipedia.org/wiki/Andrew_Ng) available on [Coursera](https://en.wikipedia.org/wiki/Andrew_Ng). This is a powerful five-course specialization that covers DL in great detail. However it is **not** free but you can apply for financial aid if necessary. Check out the course [here](https://www.coursera.org/specializations/deep-learning).

Another recommended course would be a video series by [fast.ai](fast.ai) that covers the use of the fast.ai python library. This series has eight videos and you can check them out [here](https://course.fast.ai/videos/)

#### Deep Learning Models

The following GitHub repository contains a number of DL Models that you can make use of according to your liking. I have created this repo for people studying math intensive DL courses to be able to see the programs in action. It contains actual image classifiers made with python libraries.

{% github MuizAlvi/Machine_Learning_and_Deep_Learning_models %}

## Theoretical & Hands-on Notebooks <a name="chapter-14"></a>

Although videos, books and courses are a great source of learning, fields like AI require a more hands-on approach. The following repository contains a number of [jupyter notebooks](https://jupyter.org/) to help further your understanding of ML and DL. It also includes the code to the AI classifier example along with a number of resources to guide you on the path of Artificial Intelligence.

{% github MuizAlvi/AI101 %}

Note: Please do make use of these notebooks as they will improve your understanding and learning.

## Problems with ML & DL <a name="chapter-15"></a>

Classic Machine Learning comes with a number of limitations. These limitations are highlighted in the image classification problem discussed above as well. 

The problem with Deep Learning is that it is GPU intensive (as mentioned several times above), requires huge amounts of training data and has a very complicated code.

## Cloud Services: Microsoft Azure <a name="chapter-16"></a>

[Microsoft Azure](https://azure.microsoft.com/en-us/) is your one-stop-shop solution to all the above mentioned problems.

![microsoft-azure-500x500](https://dev-to-uploads.s3.amazonaws.com/i/ohe7vbfba2f0b713pxoh.png)

Azure provides:

* [Virtual Machines](https://en.wikipedia.org/wiki/Virtual_machine) that do complex computations for you!
* Cloud storage space to store your models and datasets
* Open datasets that you can use to train your models
* Automated ML (drag and drop), so you don't event have to code anything!

Now a lot of individuals hesitate to use this platform because it's a paid service, but there is a way around this! 

#### Azure Free Credits

I will be listing down two ways to obtain free Azure credits to help you get started on the platform:

1. You can get $200 worth of free Azure credits simply by signing up for an Azure account [here](https://azure.microsoft.com/en-us/free/). 
2. You can obtain $100 worth of free Azure credits and much more by applying for the GitHub Student Developer Pack [here](https://education.github.com/pack).

#### Budgeting

Now the question you're probably asking yourself is _how much can be done with this amount of free credits?_ Well to answer your question, I built, trained, tested and deployed an ML and a DL model on Azure and that only cost me $0.64! You can see the details below:

![9](https://dev-to-uploads.s3.amazonaws.com/i/dsknct1frc033i5gg2gb.PNG)

So either package is more than enough to for learning purposes.

## Conclusion <a name="chapter-17"></a>

AI is a powerful field with immense research and implementation opportunity. You should now have a good idea about this field, its subfields and the possible path to take when it comes to learning. If you are someone starting out with AI then please feel free to make use of the provided resources as they will help you on your journey immensely. I would also urge you to share this post in your circle as well, as it addresses a lot of issues faced by people in the AI learning process. It's all here, we just need to get the word out.

![DL is a superpower](https://dev-to-uploads.s3.amazonaws.com/i/x749s8bckfq0rfvy33sy.jpeg)

The picture above is reference to [Andrew NG](https://en.wikipedia.org/wiki/Andrew_Ng)'s [Deep Learning Specialization](https://www.coursera.org/specializations/deep-learning) course where he tells us that DL is no less than a super power and it is our job to make the best use of it.

I hope the post was clear and covered everything. Please use the discussion/comment section to let me know if you faced any difficulty or have any questions. 

Thank you for taking the time to read this article!