# The Building Blocks of AI

“Started from the bottom now we’re here” — Drake

Drake wasn’t lying when he said that, because with all the technological advancements we see today, it’s important to consider how we got here.

I remember listening to a speech about AI in my eighth-grade class, and I recall thinking to myself, “this. topic. is. so. boring”. I didn’t understand how it worked, and the whole time I perceived it as huge robots that were going to take over our planet. My misunderstanding of AI is what inspired me to create this article, a one-stop-shop for understanding AI, “Starting from the bottom” 😉.

(This article is formatted in different “blocks”, and each “block” introduces a new concept. The goal is to have a good understanding of the fundamentals/*blocks* of AI by the end of the article, so you can work on *building *AI.)

*Pro tip: When reading this article, having the **intention to learn** will be key to understanding the concepts *🔑*.*

# 1st block: What is AI

AI is a field of computer science that

works to replicate human intelligence.

The systems can be built to plan, problem-solve, predict, and learn. AI technologies are great at analyzing large parts of data, which allows the AI to complete a task, through a method known as **machine learning **(which we will discuss in block 2). Machine learning isn’t the only form of AI, but it’s what we will be focusing on in this article. **It’s about giving machines the power to problem solve, predict, and analyze vast amounts of data replicating human intelligence.**

How do you imagine AI?

Before I began to learn about it, I perceived AI as something looking this:

Super cool robots…

Or even this:

Maybe you can relate, to my perception of AI, and while that’s partially true, AI actually looks more like this:

Code, and *lots *calculations…

The amazing thing about AI is that anyone can build a model, and the only catch is your mindset. AI is being used all around you, one being social media. The posts you like, share, comment on, watch time, etc. is all data being collected to ensure you engage with the content (this will be further discussed in block 5). Understanding AI is more than all the math and fancy code, it’s also **understanding our future**. Your data is currently being used (possibly against you) and collected for AI, in ways you might not even be aware. AI is being used all around us, and only something to fear, if you don’t understand the fundamentals.

“By far, the greatest danger of Artificial Intelligence is that people conclude too early that they understand it.” — Eliezer Yudkowsky

Watch this video for a better understanding of AI as a concept before we move onto block 2:

## Let’s review:

- Artificial intelligence works to replicate human intelligence by giving machines the power to predict, draw conclusions, and recognize patterns.
- AI is shaping our future, which is why it’s so important to learn about it.
- We need AI to help us analyze large amounts of data (like I mean
**trillions**of data points… I don’t know about you but I would much rather binge a season of Shark Tank). - The more data available for the AI, the more accurate it will be.

**Ready to move on?**

If not… watch this video and this Ted Talk

# Block 2 — Machine Learning (ML):

Machine learning is programming an algorithm to learn by itself.

For a machine learning model to actually “learn”, data is needed to train the model, ensuring the most accurate outcomes, and predictions.

With machine learning, a programmer does not need to write a better algorithm, because the model automatically improves itself! Talk about self improvement 😉.

There are three techniques the model uses to learn:

- Supervised learning
- Unsupervised learning
- Reinforcement learning

## Training and testing data:

*I will refer to these terms when I explain the different learning techniques

Machine learning models improve, the more data available. There are two types of data for an ML model: training data and testing data.

Training data:

- Makes up 80% of the data you collected

- Used to train the model on, so that it can learn using any technique (unsupervised, supervised, reinforcement, etc.)

Testing data:

- Makes up 20% of the data you have collected

- Used to actually test on the model to make sure it gets an accurate output

We can think of training and testing data as the practice vs. test questions at school. Most of the work you do at school is practicing for the test. When you practice, you are able to learn, which is exactly how machine learning works, and how the data is divided.

# Supervised learning:

How it works: Supervised learning models take in previous data to make predictions about the future, by** labeling the data**.

There are two types of supervised learning:

- Classification
- Regression

*note: each type of learning technique has many possible algorithms which can be used.

## Classification (supervised learning method #1)

Using classification for supervised learning** sorts the data with a specific labelled output.**

Classifying data with labels

Algorithm used: Logistic regression (there are many algorithms however logistic regression is the simplest for classification)

Logistic regression:

Logistic regressionuses a set of independent variable to predict a binary outcome

Binary: Either one or the other. Ex, 0 or 1, yes or no

Independent variables: factors that may influence the dependent variable (outcome)Additional resource for further explanation

An example of how classification works:

If you showed the algorithm images of cats and dogs; using this acquired knowledge, the algorithm would tell you if the next image you input is a cat, or dog. **This works based on previous training data which the algorithm learned from; characteristics of cats and dogs, and what to look for in the image you inputted. **Classification in supervised learning gives more accurate outputs, however the process of labeling the original data for the machine to learn from can be tedious.

Picture this:

You input this photo into the algorithm, hoping to get a label of what it is. The options are cat or dog:

It’s now up to the algorithm to decide what this is an image of. It’s going to use a classification learning model and **assign this picture a label based on previous data with the same characteristics.**

Our inputted photo could either be an image of a dog or cat. Drumroll please… 🥁👏

Its a dog! Bet you didn’t guess that ;)

This example of image recognition is used in YOUR cellphone!

Try this:

- Go to your photos app 📷.
- Click on the search option 🔎.
- Search any thing you may have a picture of 🐶.

Bam! You just witnessed some AI hard at work! The algorithm sorting through data, finding correlations in the data, and outputting a label of what the picture is.

## Regression (supervised learning method #2)

When using regression in a supervised learning model, the **output will be a continuous variable; **whereas classification was a label.

Example of a continuous variable: stock prices, salary, house prices, etc.

Algorithm used: Linear regression (many algorithms can be used however linear regression is the simplest)

Linear Regression:

- Linear regression fits the data points on a graph with a line to predict the output.

I recommend watchingthis videoon 1.5x or 2x speed

A regression model can:

- predict age 👴
- predict whether stock price of a company will increase tomorrow 📈
- predict house prices in x amount of years 🏡
- (anything with a numerical output) 🔢

This is what the outcome would look like using linear regression:

As you can see, data points are plotted on the graph and the algorithm will place a line, predicting the future with past data. Unlike classification, the model **isn’t binary**, but rather a **continuous variable**. Because it’s a machine learning model, it uses training data and testing data to get the most accurate output. After the original hypothesis line is placed, the algorithm will calculate how far off it is from the target, also known as finding the *loss function*. Once the loss function is calculated, the algorithm improves itself, and continues to train on the data, until its testing time…

Cost/loss function (this explanation is optional to read through, but loss function will be mentioned later in the article):

MSE= Mean Squared Error (one formula for determining cost function in deep learning- this is just one example)

Explanation of equation:

This equation looks a bit scary, but in summary, it’s what used to calculate the loss function. The goal of the AI is to minimize the loss function, so the prediction is as close to accuracy as possible.

# Unsupervised Learning

Now that we have finished talking about supervised learning and the techniques used, lets move onto unsupervised learning. In this method, **the algorithm finds correlations in unlabeled data**.

For example, lets look at the picture of the blocks below:

If we put the data of these blocks into an unsupervised learning model, it would group together the blocks that share similar characteristics. In this case, it could group the blocks by color and letter.

- TRY THIS: Group together the blocks by color, and letter…

It may seem easy, but now imagine I told you to sort through **millions**, and even **billions** of blocks, would you do it? I know I wouldn’t, I would rather spend my time watching Christmas movies, and baking Pillsbury cookies 🎄.

Thankfully, we don’t need to sort through millions of blocks (data), the unsupervised learning method does it for us!

# Reinforcement Learning

Training the algorithm based off rewards or punishments.

Imagine this:

You’re playing tennis for the very first time 🎾! The opponent serves, and you’re in the returning position. **What are you going to do?**

You could forehand hit the ball, backhand, volley, etc. (some basic tennis moves). But, **what would be the best option?**

You base your decisions with the **goal of winning**, so you need to decide, what move would give you the **least amount of loss**. If you chose a backhand hit, you would have a **greater risk of loss**, so you decide to go with a forehand.

After many hits and decisions later, some good and some bad, the game is done…

Unfortunately, you ended up losing 😥

The good news however is that after collecting this data from what hits to do and what hits not to do, you can practice and train. In an AI model, the algorithm trains (using training data we talked about earlier) and it works by **making decisions that would have the lowest loss function**. If the algorithm chose the right move in the game, it would be rewarded, and closer to winning, but the wrong hit, would result in a punishment.

Punishment=bad, reward=good.

So essentially, a reinforcement model works through **positive or negative reinforcement** to get the desired outcome. Because it’s a type of machine learning, the algorithm gets trained on what’s good vs. bad, the more data inputted.

The reinforcement learning technique enables an agent to learn from trial and error using feedback from it’s own experiences and actions.

## Time for a review of Block 2!

Machine learning:

- Machine learning gives machines the power to replicate human intelligence.

- It’s teaching the machine to learn for itself using three techniques (supervised, unsupervised, and reinforcement learning).

Supervised learning:- Supervised learning > Classification (logistic regression) & Regression (linear regression).

- Classification: The output is a specific label based on previous inputted data with the same characteristics (classification = categorical)

- Regression: The output is a continuous variable (regression = numerical)

Unsupervised learning:- Sorts through unlabeled data and finds patterns to cluster the data

Reinforcement learning:- Training the model with positive or negative reinforcement

Block 2 = Complete! Keep it up! 🏅

# Block 3 - Neural Networks:

The AI algorithm is made up of **neural networks**. Neural networks, are made to simulate the human brain and “neurons” 🧠. Just like a biological neural network, artificial neural networks are constantly updating based on scenarios it encounters. To put it simply, a neural network is a set of mathematical calculations that get you from the input to the output.

This is what a neural network looks like:

**Observing the neural network:**

- “Input”, “hidden layers”, “output”
- Green circles (known as neurons)
- Black lines connecting the “neurons” (known as synapses)

“synapses” — what connects each neuron

Let’s further discuss this…

Imagine you’re in a house and want to get to the second floor 🏡:

Theinputis the bottom floor

Thehidden/computational layersis the stair case (a.k.a, what get’s you upstairs)

Theoutputis the second floor (goal)

## Input:

- The input layer is the very first layer in out neural network
- This is where the programmer will put in data
- Its our starting point and we are
*trying to get to the second floor*

## Hidden layers/computational layers:

- The hidden layers are between the input and output
*(any neural network with two or more hidden layers is known as**deep learning**)*- Within each hidden layer, there are
**neurons**(hence neural network) - The neurons have different
**weights and biases**(will discuss more in the next subtopic)

## Output:

- The result of the hidden layers computing on the input
- With different ML techniques, the output will be different (for example, if you were using a linear regression algorithm for supervised learning, the output will be a continuous variable; whereas if you were to use a logistic regression algorithm, the output would be a label)

In a neural network, there are many neurons, but the image above is what it would look like if we zoom in on **one neuron**.

Observations from the image of one neuron connection 🧠:

- Many inputs
- synapses
- The actual neuron
- The output (determined by calculation happening within the neuron)

## Weights and biases:

Above, we discussed neural networks, and how data (input) gets transferred throughout the network. But what are the calculations happening within each neuron to get the output?

*(ps. this part of the article includes more math, and may be confusing- understanding the other concepts, are key to understanding this, but don’t let it discourage you! You got this!* 💪*)*

Inside each neuron there are many calculations happening (hence the term computing layers). These calculations have something called **weights and biases**. The weights and biases **determine the value each piece of data has in generating the output.**

In a calculation within the neuron, the data gets *multiplied *by the weight value, and the output from this is either **observed or passed through to the next layer. **Within the neural **network **layers, each **individual **neuron computes to move the data through the **network **layers.

**Terms:**

- weights: the strength of connection between each neuron, and the value each neuron has in the output. Ex. Negative weights reduce the value of the output

- biases: kind of like a co-efficient in an equation

- deep learning: A neural network with two or more hidden layers

This image may be a bit confusing at first but we’re going to break it down. Just like the image above of the input, neuron, and output, the only difference is that this one shows the calculations. Here’s a calculation breakdown:

**note: weights and biases can be turned and changed like dials, for a different result and value each input has in the output (the process of changing the dials will be explained below the calculation breakdown).*

Continued calculation breakdown:

What is an activation function, as seen in the calculation? (Optional)

Simply, the activation functiondecides if the neuron should be “activated” in the output or not based on it’s weights and biases.It outputs what gets passed to the next layer in the network.

4 types of activation functions:

- sigmoid function

- hyperbolic tangent functions

- threshold functions

- Rectifier functions, or ReLUs

I’m not going to go in depth of each one (it would take a whole other article) however, if you’re curios to learn more, here’s a greatresource, describing all of them in detail.

💡 Curiosity drives innovation ;)

## Gradient Descent and Back Propagation

*The changing of weights a biases is done through a process known as **back propagation**, and **gradient descent**.*

*Our neural network usually runs forward moving from **input>output.*

*The process of back propagation, moves through the network from the **output>input**.*

*Back propagation** is the process used to go back into the network after getting the predicted output, with the goal of adjusting the calculation to get the accuarte output.*

*Gradient descent** is the process of **tweaking the weights and biases** to get the lowest **cost/loss function** (reminder: loss function - how far off the predicted output is from the actual output)*

**Summary:**

- Back propagation = the process of moving
**backward**through the network - Gradient descent = the process of
**tweaking the weights and biases**(happens during back prorogation)

*WATCH THIS VIDEO (IT’S AMAZING!!):*

## Neural Network- Complete block 3 review :

- A neural network is made up of many layers (input, hidden, and output)

- Within each layer, there are neurons

- The neurons have different weights and biases which determine its value in computing the output

- A Neural

networkhas input, hidden, and output layers, but also eachindividuallayer has input, weights & biases, andoutput> can be observed or passed to the next layer for the same process- Weights are the value the

neuron(which holds data), in determining the output-

Biasesare similar to a co-efficient- Weights and biases can be changed and adjusted, using

back propagationandgradient descent-

Back propagationis the process of moving fromoutput➜input-

Gradient descentis the process oftweaking the weights and biasesto minimize the cost function-

Activation functiondecides if the neuron should be “activated” in determining the output

Block 3 = Complete! Awesome Job! 🏆

# Block 4- The importance of data in AI:

“Data is the new oil”

Lets take a look at Facebook:

Facebooks revenue over a 12 month period ending September 30th 2020, was **$78.976B; a 18.71% increase YoY.**

This graph shows their revenue from advertising and payments displayed for each quarter. In all of these quarters, over** 90%** of all revenue is being generated form **advertisements**, but how do they get you to look at the adds, and ensure they’re advertising things you’d want to see?

This is where **AI **comes in. The amount of time you spend on each post, posts you share, like, comment on, follow, etc. is all **input **into our neural network. Each **hidden layer** looks for a different thing, and the **output **is more posts on your feed that have a relation to the content you interacted with.

The graph is a perfect example of how good the algorithms have gotten, because more content consumed on the app = more adds views = more money.

# Block 5- An example of AI in our daily lives

AI algorithms are all around us and we might not even be aware. Ever get so caught up in social media, that 5 pm suddenly turned into 9 pm when it only felt like 30 minutes?! ⏰

We can blame these AI algorithms for **recommending **us the perfect us content that will keep us engaged. YouTube recommendations is a great example.

## How it works:

This is exactly how it works for Facebooks algorithms: The **input **into our neural network would be the posts you share, comment on, like, watch time, etc.

The **hidden layers** are doing the calculations finding similarities, labeling, and categorizing the content.

The **output **is a decimal telling the algorithm your likeliness of actually enjoying the video. **Back propagation** happens when you interact with the videos YouTube recommends, and it sees how you liked it. It then goes back into the network, changing the weights and biases, varying your output, which will give you even more accurate recommendations; that ensure the lowest loss function (disliked videos, short watch time, etc.)

Essentially, EVERYTHING you do online is being tracked.

The algorithms know you better than you know yourself.

Knowledge is power, and understanding how this works can help you develop your opinion on things; rather than believing everything that’s “fed” to you through social media.

Block 4 & 5 = Complete! SO PROUD! 👑

# Building the blocks:

WOW! YOU JUST DID THAT! Take a deep breath, I know it’s a lot of information at once. It’s going to take more exposure to be fully comfortable with all the terms and concepts but you got it!

Guess what time it is… ⏰

Time to build those blocks and put it all together🎉

Block 1: What is AI

Block 2: Machine Learning

Block 3: Neural Networks

Block 4: The Importance of Data in AI

Block 5: An example of AI in our daily lives

In conclusion, artificial intelligence and machine learning are changing the way we live our lives and they are drastically shaping the way of the future. Whether this is a topic you’re interested in learning more about or not, it’s key to understanding the constantly changing world around us.

Give yourself a pat on the back 👏.

Let’s connect 🤝!

Subscribe to my newsletter for monthly updates, resources, and articles :).