Machine Learning for Social Causes (Part I)
Introduction
Wei Pin
Charlton
About DSC
We aim to make a difference in society, pushing our mission of #TechforGood through developing software solutions for Non-Profit Organizations and running events and workshops to promote the learning of technology skills among the student population
At the end of this workshop, you will learn:
Win $10 GrabFood Voucher
Kahoot Quiz at the end!
**Not sponsored by Grab although we wish it was.
What is Machine Learning To You?
Give us your answer in the URL provided in the zoom chat!
Machine Learning
/məˈʃiːn ˈləːnɪŋ/
[noun]
Development of computer systems that are able to learn for themselves without explicit instructions
Applications of Machine Learning
Security and Surveillance
Medical Industry
Digital Media & Intelligence
Self-Driving Vehicles
Robotics and AI
Computer
Machine
Data
Rules
Answers
Walking
Cycling
Running
Traditional Programming
Machine Learning
Computer Machine
(+ML)
Rules
Will identify the distinct patterns/features in a cat image
Data & Answers
CAT
CAT
CAT
CAT
CAT
CAT
CAT
CAT
Machine
(Trained with Images of Cat)
CAT
CAT
CAT
Uh oh..
NOT CAT
Machine Learning is an ongoing process
Which is why the more we train it, the better our machine gets
(More Diverse Data -> Greater Accuracy)
Let’s Try It Out!
Machine Learning
Categories of Machine Learning
Supervised Learning
Learning through the use of labelled data
Example 1: Classification (Computer Vision)
Cat
Cat
Cat
Cat/Dog?
Dog
Dog
Dog
Supervised Learning
Learning through the use of labelled data
Example 2: Regression
X-Values | Y-Values |
x1 | y1 |
x2 | y2 |
x3 | y3 |
. . . | . . . |
What if we do not have enough data
to train the machine?
Unsupervised Learning
Discovering hidden patterns without human intervention
Example: Clustering
cluster attached to it at the start
each point should belong to on its
own
Advantages of Unsupervised Learning
Disadvantages of Unsupervised Learning
What are the tools used in Machine Learning?
Machine Learning Framework
Programming Language
So how does Machine Learning works?
3 Learning Objectives
2. How Neural Network learn
3. What is backpropagation and how does it work?
Credits: GumGum
Analogy
Consensus:
9
Consensus: Not 9
+Bias
Jack
Jordan
Jane
Weight of opinion = How much this person’s the opinion matter
+Bias
Alice
Tim
Ken
IT IS NOT 9!
IT IS 9
How is the analogy applicable?
Consensus:
9
Consensus: Not 9
+Bias
+Bias
0.32
0.98
0.40
0.30
0.50
0.65
A Neuron/Node
0.00
This number is called
“Activation”
0.00
1.00
1.00
0.45
The number represents the greyscale value of a particular pixel
How it will turn out..
And what is a neural layer?
0.32
0.98
0.40
0.32
.
.
.
Neural Layer: A collection of 'neurons'/nodes operating together at the same column in a neural network
Neural Networks
A computer system modelled on the human brain. Made up of multiple neural layers
/ˈnjʊər(ə)l ˈnɛtwəːk/
[noun]
Human Brain Neuron Network
ML Neural Network
A neural network
0.32
0.98
0.40
0.32
.
.
Input
Layer
.
8
Output
Layer
1
2
9
.
.
9 Neurons
Basically Many Layers
Here
Hidden
Layer
Visualising Neural Network (Simplified)
Note: This Neural Network has already been trained
What is in the hidden layer?
0.32
0.98
0.40
0.32
8
1
2
9
9 Neurons
.
.
.
.
.
.
.
.
.
.
.
.
How different layers interact with each other
0.35
0.09
x
0.80
0.20
Finding/Optimising the correct weight value for each of the channel (Those lines that you see) is our aim in ML
Weights
Control the signal/strength of a connection
between 2 neurons
0.3
0.57
0.8
0.70
x = F((A1W1 + A2W2 + … + AxWx) + Bias)
x = F((0.2*0.7 + 0.8*0.8 + 0.35*0.3 + 0.09*0.57) + Bias)
x is the result we get after passing in the sum of the product of each respective neuron activation and its weight into an activation function
Bias is when an algorithm produces results that are systemically prejudiced due to erroneous assumptions in the machine learning process
Activation Function
Linear
Non-Linear
Assume that the red and blue circles as items we are trying to classify
Common Types of Activation Functions
Which Activation Functions do we choose?
Problem Type
Classification
Regression
Binary
Classification
Multiclass
Classification
Multilabel
Classification
Sigmoid
Activation
Softmax
Activation
Sigmoid
Activation
Linear
Activation
x = F((A1*W1 + A2*W2 + A3*W3 + A4*W4) + Bias)
You probably wonder..
Why 2 hidden layers and why the number of neurons in each layer?
Let’s Visualize it!
Multilayer Perceptron Visualisation on handwritten numbers:
How Neural Network learn?
0.32
0.98
0.40
0.32
.
.
.
8
1
2
9
.
.
Hidden
Layer
0.12
0.32
0.20
0.75
.
.
.
TRAINED Neural Network
0.32
0.98
0.40
0.32
.
.
.
8
1
2
9
.
.
Hidden
Layer
0.81
0.55
0.62
0.72
.
.
.
UNTRAINED Neural Network
Wrong!
Here, the network is running for the first time, so it is making a random guess
UNTRAINED Neural Network (Animated)
.
8
1
2
9
.
.
Hidden
Layer
0.81
0.55
0.62
0.72
.
.
.
.
8
1
2
9
.
.
0.00
0.00
0.00
1.00
.
.
.
Actual
Expected
Probability
How does it “improve” itself?
Cost/Loss Function
A technique we use to measure the performance/correctness of our algorithm/machine learning model
(Actual - Expected)2
Cost/Loss Function
Quantifying the differences in expected vs actual result
Purpose of Training a neural network
To minimise the cost/loss value to as close to zero
How it is achieved
Through repeated training over the neural network with different data
a.k.a telling the computer its mistakes and what should it do to re-adjust for a better outcome
Backpropagation
A way of propagating the total loss back into the neural network to know how much of the loss every node is responsible for,
We cannot change the activation of the neurons directly, the only variables here are the weights and bias (The Lines/Channel)
Why is it called Backpropagation
Addendum: For the curious mind (Optional)
Due to time constraint and the depth required, if you are
interested to find out the maths behind how the neural network learn please feel free to visit this after the end of this workshop:
bit.ly/DSCGradientDescent
How it works?
To summarize:
Coding a Neural Network
Coding a Neural Network
Coding a Neural Network
Predicting y=x Graph
Coding a Neural Network
Loss and Optimizers
Loss - A mathematical way of measuring how "wrong" our predictions are
Optimizers - An algorithm to help us minimise loss
Common Problems of Machine Learning
Overfitting and Underfitting
Coding a Neural Network
How are images processed by computers?
Think about it this way:
Training Data:
Past Year Exam Papers
Validation Data:
Mock Exam Papers
Test Data:
The Actual Exam
Coding a Neural Network
How are images processed by computers?
Images are made of pixels of different colours.
Pixels contain Red, Green, Blue (RGB) values to indicate what colour it should be
Red: 255, Green: 0, Blue: 0
Red: 0, Green: 255, Blue: 0
Red: 0, Green: 0, Blue: 255
Red: 120, Green: 120, Blue: 120
Red: 0, Green: 0, Blue: 0
Red: 255, Green: 255, Blue: 255
Coding a Neural Network
Simpler way to process some images
Grayscale (if colour is not important to the model)
Value: 0
Value: 255
Coding a Neural Network
Normalization
Let's look at an analogy to see why this is useful!
Coding a Neural Network
Normalization
A
B
10 marks
20 marks
Max score: 20
Max score: 100
50%
100%
20%
10%
50%
Difference:
10%
Convolutional Neural Networks
A type of neural network used in image recognition and processing, specifically designed to process pixel data
/ˌkɒnvəˈluːʃ(ə)n(ə)l ˈnjʊər(ə)l ˈnɛtwəːk/
[noun]
Convolutional Neural Network
Adding Layers Together
Convolutional Neural Network Visualisation
Convolutional Neural Networks
Why convolution?
The problem with conventional neural networks and image processing
???
Algorithm is skewed to detect cats in the centre, but isn't always the case
Convolutional Neural Networks
Why convolution?
Demo with the Number 1:
Convolutional Neural Networks
The Convolutional Layer
Use of filters for feature extraction
parts of the image
the filter
165
1
170
1
2
1
240
238
1
151
160
0
Convolutional Neural Network
Filters
Each filter is often used to identify specific features such as edges or corners.
Try it yourself!
https://bit.ly/DSCFiltersHandsOn
But what if we want to identify something more? For example, eyes, noses, faces?
Convolutional Neural Network
Hierarchical Nature of Filters
Lower level filters identify lower level features
Passed on to higher level filters which identify higher level features comprising these lower level features
EYES
EYES
MOUTH
FACE
EYES FILTER
MOUTH FILTER
FACE FILTER
Max Pooling Layer
Don't images have a lot of pixels? Won't it take very long to run an algorithm on so many pixels?
Other Pooling Layers
Are there other types of pooling?
Convolutional Neural Network
Adding Layers Together (Recap)
Hands-on Demo
Use the following Link and copy the Notebook onto your own Google drive:
Quiz!
Stand a chance to get a $10 GrabFood Voucher!
Thank you for joining us in this workshop!
Workshop will be recorded and uploaded to
DSC Youtube Channel