No, but actually, how does a Neural NetWORK?šŸ¤”- Part 1

A quick and fluff-free introduction to neural networks in machine learning, and how to build your first neural network model! šŸ˜„

Evan Lin
Analytics Vidhya
7 min readNov 28, 2020

--

Caveat:

Note: If youā€™re new to deep learning and this is your first article, or youā€™re expecting to really understand this article, expect to spend 3-4x more reading time than what Medium says. Iā€™d also recommend you to grab a pencil and paper while following along. If not, then maybe read it out loud.

My Intention:

I want this article to help build your intuition in understanding how and for what reason (why) neural networks work. My goal is to help fill in any nooks and crannies of uncertainties that may arise in your introduction to deep learning.

Letā€™s get started!

Alright, let's make sure we understand these three things first:

  1. MINDSET to learn!
  2. What is a Neural Network and how does it work?
  3. What technical skills and resources do I need to build one?

šŸ§ MINDSET to learn!

The most important one of them all, and the most overlooked. That's why I capitalized it in the first place! Look at the image above. Iā€™m sure many if not all of us have experienced this same moment. If youā€™re like me, youā€™d probably go through this process of thinking: look at the nearest object in sight that's carryable, contemplate whether or not to throw or smash the object and then actually doing what you contemplated. Yeah, donā€™t. To people who are experienced at coding and are reading this, this might sound repetitive, but for the majority that isn't, understand this:

BOIL down each problem individually into ideas that YOU can understand.

Expect to enter a rabbit hole of research. One search question will become 3, those 3 searches become 5, those 5 become 10ā€¦. and so on.

Coding is 95% researching code and 5% actually coding it.

During deep learning research sessions, Iā€™m watching youtube videos or stack overflow 95% of the time, trying to wrap my head around concepts.

Youā€™re bound to make mistakes.

We type with our fingers. Out of hundreds to thousands of characters, do you really think weā€™d type them all correctly?

And the biggest one of them allā€¦

DONT COMPARE YOURSELF TO OTHERS.

Coming from personal experience, I used to always feel the need to compare my progress to others, and it's even hard admitting this to myself. Remember that everybody has different methods of learning and varying levels of experience.

Donā€™t hesitate to pause and ponder. Donā€™t be ashamed of watching the entire video 3 times. Experience takes TIME.

Ok so now we got that covered:

What is a Neural Network?

A Neural Network (or Artificial Neural Network) is a class of machine learning systems comprised of a series of algorithms made to replicate the thinking process of a human brain.

To further simplify:

It's the type of system a machine uses to ā€œthinkā€ like a human brain.

How does a Neural Network work?

Take a look at this image. In order to solve this sheet, weā€™d solve by looking at the numbers and arithmetic operators in black. In our brains, we intrinsically know that 1 + 3 is equal to 4, and 3+1 is also equal to 4 because weā€™ve practiced them when we were younger. Itā€™s hard to imagine that now, but we really did train our minds. Learning 1 + 3 made sense because we counted with plenty of experience, meaning that somewhere along our journey of counting, we failed over and over again!

Now let's say oops! 4 year old me got frustrated because I got the wrong answers, so I decided to be a party pooper and ruin the answer key for the rest of the other kindergarteners by scribbling on some red crayon. For simplicity's sake Now this image above is a problem that a neural network would try to solve (But in reality due to the simplicity of the question, you really wouldnā€™t need to).

So how would a neural network LEARN in this situation?

Ever raised up your hand in class to answer a question that you never knew in the first place? That's exactly what a neural network does when it begins training. But now imagine if you tried to memorize the answer key without understanding how basic addition worksā€¦Your answer would still be just as random. This is exactly what a neural network does!

Neural Networks begin their learning by making totally random guesses

So let's start thinking like a computer. Out of the 8 questions above, let's take a look at the first one. How would a neural network solve this? Well in our brains, we can see that 3 and 4 have a difference of 1. But remember the machine has NO CLUE what calculations to do, so it can really do anything. Totally random. That means for the missing number in the red scribble, the machine could guess a number of 100, 27, 99999999999, literally anything, or maybe even an equation? In deep learning, these random changes are called stochastic changes. But wait a minute, isnā€™t this only one example? How can a machine learn with such little experience?

Let's take a look at this image again. This is where weā€™ll drive our point home.

Alright, so now that we know how a machine BEGINS their learning, how can we apply that to the other 7 numbers? Well, the machine does the EXACT same thing! For every red scribble, a random number or equation would fill in that spot! So the scribble in question 2 might be -1000, the scribble in question 3 might be 2341879, the scribble in question 4 could be 4273242342482943824. Yeah, and to really demonstrate the randomness of these numbers, I just slammed my keyboard to type these.

Ok, that's cool and all but you haven't explained the goal yet?

Hold on, Iā€™m getting there. So weā€™ve established that a machine would guess a completely random scribble when it begins to learn. Now what I want you to remember is that it's only going to be completely random for the first few tries but for the simplicity of the example, weā€™ll say that it will only be random for the first try.

So let's keep track of these numbers for what values they have in their red scribbles:

  • Question 1: 27
  • Question 2: -1000
  • Question 3: 2341879
  • Question 4: 4273242342482943824
  • Question 5: -243
  • Question 6: 94398
  • Question 7: -4270
  • Question 8: 99

Once the computer completes making its guesses for all 8 of these questions, we can say that it has completed an epoch, and it's pronounced as ā€œepic.ā€ (Caveat/warning: I am only loosely describing what an epoch is, but the idea I am trying to convey here is that one iteration is complete)

Now, what do you think will happen in the next epoch?

Well, the machine is going to look at the answer sheet, in order to confirm the accuracy of its answers.

ā€¦.. and it's going to realize that it was really really wrong in the first place. So its goal? Well, the neural networkā€™s goal is to learn how to get the blue number as accurately as possible. These blue numbers are called target data. Therefore, the machineā€™s goal is to correctly learn how to find this target data. So when the machine checks its answers (guessed), to ACTUAL answers (The blue numbers), the machine is going to try and get a closer answer to the target data, called a label.

So the second epoch might have red scribbles that look like this:

  • Question 1: 13
  • Question 2: -700
  • Question 3: 23418
  • Question 4: 427324234
  • Question 5: -50
  • Question 6: 943
  • Question 7: -2021
  • Question 8: 37

And if you compare these numbers to the previous 8 numbers, theyā€™re a bit closer to the target data! I think youā€™d agree with me that 13 is most definitely closer to 4 than 27 is. Now, remember that in order for these numbers to become labels, you need to account for its features, the inputs! And in our situation, our features are the given black numbers.

If you made it this far, congratulations! You now should have an idea of how a neural network works!

Make sure you understand all of the following concepts above before moving on. If you donā€™t, reread the article from the start or go back to where you felt confused.

Hereā€™s the real reward: Weā€™re going to build a neural network from scratch. Hereā€™s the link to the second part of the series:

https://evxxan.medium.com/no-but-actually-how-does-a-neural-network-part-2-2f5c5e3cdf78

See you on the other side!

If you enjoyed this article, hit the clap button! šŸ‘ŠšŸŽÆ

Feel free to connect with me on my LinkedIn or contact me through email:

My LinkedIn:

My Email: evanlin416@gmail.com

--

--

Evan Lin
Analytics Vidhya

Innovator at The Knowledge Society (TKS). Interested in Machine Learning and Quantum Computing.