1 of 80

Machine Learning for Social Causes (Part I)

2 of 80

Introduction

Wei Pin

Charlton

3 of 80

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

4 of 80

5 of 80

At the end of this workshop, you will learn:

  • Machine Learning and its applications
  • Types of Machine Learning
  • The brain behind ML: Neural Networks
  • Convolutional Network

6 of 80

Win $10 GrabFood Voucher

Kahoot Quiz at the end!

**Not sponsored by Grab although we wish it was.

7 of 80

What is Machine Learning To You?

Give us your answer in the URL provided in the zoom chat!

8 of 80

Machine Learning

/məˈʃiːn ˈləːnɪŋ/

[noun]

Development of computer systems that are able to learn for themselves without explicit instructions

9 of 80

Applications of Machine Learning

Security and Surveillance

Medical Industry

Digital Media & Intelligence

Self-Driving Vehicles

Robotics and AI

10 of 80

Computer

Machine

Data

Rules

Answers

Walking

Cycling

Running

Traditional Programming

11 of 80

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

12 of 80

Machine

(Trained with Images of Cat)

CAT

CAT

CAT

Uh oh..

NOT CAT

13 of 80

Machine Learning is an ongoing process

Which is why the more we train it, the better our machine gets

(More Diverse Data -> Greater Accuracy)

14 of 80

Let’s Try It Out!

15 of 80

Machine Learning

Categories of Machine Learning

16 of 80

Supervised Learning

Learning through the use of labelled data

Example 1: Classification (Computer Vision)

Cat

Cat

Cat

Cat/Dog?

Dog

Dog

Dog

17 of 80

Supervised Learning

Learning through the use of labelled data

Example 2: Regression

X-Values

Y-Values

x1

y1

x2

y2

x3

y3

.

.

.

.

.

.

18 of 80

What if we do not have enough data

to train the machine?

19 of 80

Unsupervised Learning

Discovering hidden patterns without human intervention

Example: Clustering

  • Each point does not have a specific

cluster attached to it at the start

  • Algorithm discovers which cluster

each point should belong to on its

own

20 of 80

Advantages of Unsupervised Learning

Disadvantages of Unsupervised Learning

  • Helpful for finding useful insights from the data.
  • Closely imitates how human learns by their own experiences
  • Works on unlabeled and uncategorized data which make unsupervised learning more important. (Saves manual work and expenses)
  • Results maybe less accurate
  • Time consuming during learning phase

21 of 80

What are the tools used in Machine Learning?

Machine Learning Framework

Programming Language

22 of 80

So how does Machine Learning works?

23 of 80

3 Learning Objectives

  1. Neurons, Neural Layers and Network

2. How Neural Network learn

3. What is backpropagation and how does it work?

24 of 80

Credits: GumGum

25 of 80

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

26 of 80

How is the analogy applicable?

Consensus:

9

Consensus: Not 9

+Bias

+Bias

0.32

0.98

0.40

0.30

0.50

0.65

27 of 80

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

28 of 80

How it will turn out..

29 of 80

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

30 of 80

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

31 of 80

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

32 of 80

Visualising Neural Network (Simplified)

Note: This Neural Network has already been trained

33 of 80

What is in the hidden layer?

34 of 80

0.32

0.98

0.40

0.32

8

1

2

9

9 Neurons

.

.

.

.

.

.

.

.

.

.

.

.

35 of 80

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

36 of 80

Activation Function

Linear

Non-Linear

Assume that the red and blue circles as items we are trying to classify

37 of 80

Common Types of Activation Functions

38 of 80

Which Activation Functions do we choose?

Problem Type

Classification

Regression

Binary

Classification

Multiclass

Classification

Multilabel

Classification

Sigmoid

Activation

Softmax

Activation

Sigmoid

Activation

Linear

Activation

39 of 80

x = F((A1*W1 + A2*W2 + A3*W3 + A4*W4) + Bias)

40 of 80

You probably wonder..

Why 2 hidden layers and why the number of neurons in each layer?

  • Deep learning is a combination of art and science. The number of layers and neurons chosen in the hidden layer(s) are arbitrary. It requires you to fine-tune and test to find the right number for the best training result

41 of 80

Let’s Visualize it!

Multilayer Perceptron Visualisation on handwritten numbers:

42 of 80

How Neural Network learn?

43 of 80

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

44 of 80

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

45 of 80

UNTRAINED Neural Network (Animated)

46 of 80

.

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

47 of 80

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

48 of 80

Cost/Loss Function

Quantifying the differences in expected vs actual result

49 of 80

Purpose of Training a neural network

To minimise the cost/loss value to as close to zero

50 of 80

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,

51 of 80

We cannot change the activation of the neurons directly, the only variables here are the weights and bias (The Lines/Channel)

52 of 80

Why is it called Backpropagation

53 of 80

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

54 of 80

How it works?

55 of 80

To summarize:

56 of 80

Coding a Neural Network

57 of 80

Coding a Neural Network

58 of 80

Coding a Neural Network

Predicting y=x Graph

59 of 80

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

60 of 80

Common Problems of Machine Learning

Overfitting and Underfitting

61 of 80

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

62 of 80

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

63 of 80

Coding a Neural Network

Simpler way to process some images

Grayscale (if colour is not important to the model)

Value: 0

Value: 255

64 of 80

Coding a Neural Network

Normalization

  • Transforms data to values between 0-1
  • Helps model better understand the minimum and maximum values of the input data
  • Makes computation easier and learning more accurate

Let's look at an analogy to see why this is useful!

65 of 80

Coding a Neural Network

Normalization

A

B

10 marks

20 marks

Max score: 20

Max score: 100

50%

100%

20%

10%

50%

Difference:

10%

66 of 80

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]

67 of 80

Convolutional Neural Network

Adding Layers Together

68 of 80

Convolutional Neural Network Visualisation

69 of 80

Convolutional Neural Networks

Why convolution?

The problem with conventional neural networks and image processing

  • Unable to account for different positions of the target

???

Algorithm is skewed to detect cats in the centre, but isn't always the case

70 of 80

Convolutional Neural Networks

Why convolution?

Demo with the Number 1:

71 of 80

Convolutional Neural Networks

The Convolutional Layer

Use of filters for feature extraction

  • What are filters exactly?
    • Perform calculations on different

parts of the image

    • Gives a "feature map"
      • New image with calculated results from

the filter

165

1

170

1

2

1

240

238

1

151

160

0

72 of 80

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?

73 of 80

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

74 of 80

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?

  • Reduces amount of information to decrease computation time
  • Extracts the maximum value - able to maintain information while downsampling

75 of 80

Other Pooling Layers

Are there other types of pooling?

  • Every pooling layer has their own advantage
  • Average Pooling Layer
  • Minimum Pooling Layer

76 of 80

Convolutional Neural Network

Adding Layers Together (Recap)

77 of 80

Hands-on Demo

Use the following Link and copy the Notebook onto your own Google drive:

78 of 80

Quiz!

Stand a chance to get a $10 GrabFood Voucher!

79 of 80

80 of 80

Thank you for joining us in this workshop!

Workshop will be recorded and uploaded to

DSC Youtube Channel