Monday 13 July 2020

Build your own Neuron in a Spreadsheet.

Purpose: 
To start to understand the basic idea behind how a Neural Network works by building the most basic unit a simple neuron using a spreadsheet.



Objectives:
- To see we can start building machine learning tools in commonly used software applications such as a spreadsheet without a lot of programming (though programming is good fun);
- To see if we change a few values and it changes what the neuron does.



What might be helpful to know before we start?

Don't worry the video will mention these and show you them in action.
  • In the press we see a lot of talk about Artificial Intelligence and Machine Learning and one of these often mention is Deep Learning which is a form of something called a Neural Network. One way to think of a Neural Network is in our brains we lots of processing units called neurones, which are connected together to form a massive network of neurones, which is a neural network. What computer scientists have done is taken the idea and used it create an artificial version so we have a tool that learns.
  • The simplest unit in these networks is the neuron, and we are going to build a simple artificial neuron together. It works by doing two things
    • taking the inputs and multipling them with a value, then adding these multipled inputs to get a single number;
    • we take this single number and use it to decided what the neurone's output is.
  • We can do a lot with a neuron, including building logical operations. In this activity, we are going to look at two basic logic operations the AND (when all the inputs are TRUE (in our case today 1), the output of the neuron is TRUE), the other is OR (when one of the inputs are TRUE, the output is TRUE).
  • Spreadsheets cells have some cool features
    • if instead of putting A2 into a formula in a cell, we put $A$2; if we then copied that cell's content and pasted it another cell the value stored in A2 will always be used, otherwise pasting changes the cell that is used.
    • next is IF, we can build a test into our system =IF( whatever the test is, what happens if the test is TRUE, what happens if the test is not true) .


Task 1: Which Spreadsheet to use and setting up.

Google sheets, Excel can all be used; the process is the same. 

Please watch this video first which will take you through the activity it includes pauses to allow you stop the video to type in the things needed. So watch the whole video first; repeat the video if you need help, stopping the video when you need to. 





Copy the spreadsheet above.

At the end of this task we should have
  • The spreadsheet started;
  • All the columns labelled
  • The inputs set-up
  • Set up some initial values called weights.

Task 2 Adding the rules

In Cell H2 enter the following =$E$2*A2+$F$2*B2+$D$2. What is happening is weight 1 is multiped with input 1, weight 2 with input 2 and these are then added together with the bias. This is the weighted sum

The dollar signs set the formula so that it always uses those values such as E2. Now if we copy this cell and paste it into the three  cells H3,H4 and H4 the formula is copied and its output changes based on the inputs and the weights.

Final stage, in J2 add the following =IF(H2>=0,1,0) . What this says is if the weighted sum is greater or equal to 0 then the output of the neuron is 1 (TRUE) otherwise 0 (FALSE). We are done we have our neuron.
 
At the end of this task we should have
  • The inputs and weights multiplied together;
  • Added the multiplied weighted inputs together to create a single number;
  • Created the rules that say the output is based the single number;
  • See we have an OR gate.


Task 3
At the end of the task we should have seen what can happen when changes the weights - in this case OR becomes AND. To this change the bias value to -2.


Have a play with the weights. Do they always have to be whole numbers? What other values of weights work to produce an AND. You only need to alter bias, weight 1 and weight 2.




Where now? Activities to do later if you want.

If you want to take this further these videos might help



Follow on Activity 1: Training a Single Neuron in a spreadsheet




Follow on Activity 2:  Combining three neurone to make a Neural Network in a Spreadsheet




Follow on Activity 3: Can we build a Simple Neural Network using BBC Microbits? 



Follow on Activity 4: Why do we need to learn about Machine Learning






All opinions in this blog are the Author's and should not in any way be seen as reflecting the views of any organisation the Author has any association with. Twitter @scottturneruon

No comments:

Post a Comment

Top posts on this blog in March 2024

The Top 10 viewed post on this blog in March 2024. Covering areas such as small robots, augmented reality, Scratch programming, robots. Micr...