Skip to content
Exit presentation

How AI Learns II: Neural Networks Intuition

Write the sum yourself

This term did the arithmetic by hand. Now you write it as code.

Inputs 6 and 0. Weights 6 and 4. Sum starts at 0.
Step 1 of 4
  1. Inputs 6 and 0. Weights 6 and 4. Sum starts at 0.
  2. Position 0: sum becomes 0 + 6 × 6 = 36.
  3. Position 1: sum stays 36, since 0 × 4 adds nothing.
  4. decide(36, 40): 36 is under 40. Answer: wait.

The rule

The weighted sum and the comparison are two short functions. At or past it says call. The day the sum equals the threshold says call.

A function is a named piece of code. It takes values in and returns one answer. Here inputs and weights are lists of numbers. weightedSum(inputs, weights) starts sum at 0. Position 0 is the first item in a list. A while loop repeats lines while a check is true. Here it goes through the positions, 0 first. Each time, the function adds one input times its own weight. Then decide(sum, threshold) returns true for a sum at or past the threshold. It returns false when the sum is under it. True means call, false means wait.

The lab keeps two days hidden from view. One day's sum equals the threshold exactly. A check of "greater than" alone gives wait there. A check of "at or past" gives call. The other day is an empty day, with no inputs at all. Its sum must still be 0.

Both functions start wrong on purpose. They return a sum of 0 and the verdict wait. Change them until they work out the right answers.

Loading lab…

Jump to lesson

This track

  1. 0 Start here
  2. 1 Holding a rule instead
  3. 2 The weighted sum
  4. 3 The line it crosses
  5. 4 Measuring one wrong
  6. 5 Nudging the weights
  7. 6 Counting what moved
  8. 7 Write the sum yourself
  9. 8 What the word neural buys
  10. 9 The big picture
  11. 10 Track quiz

Other tracks