Starting With Weights and Vectors
00:00 In this lesson, you’ll begin to implement a neural network. To get started, you’ll need to represent the inputs. Start off by implementing some operations on vectors, first with Python lists and later using NumPy arrays.
00:15 A vector has a direction and magnitude. You can represent a vector as an arrow in a graph. The magnitude of the vector is the length of the arrow. Here, you can see three vectors: two for the weights of a neural network and another for the input.
This is the purpose of the dot product. As the vectors are two-dimensional, you can compute the dot product of the input and
weights_1 by first multiplying the first index of the input by the first index of
If the dot product is zero, the vectors are not similar at all. However, larger values mean that they are more similar. Since the dot product of the input and
weights_2 is greater than that of the dot product and
weights_2 is more similar.
You don’t need to worry about proving it, but you will implement it here in code. That will be straightforward. The symbol e is a mathematical constant for Euler’s number, and the function
np.exp() in NumPy will handle that.
This diagram shows the different parts that you’ll implement. Hexagons are functions, and the purple rectangles are outputs. You’ll simply compute the dot product of the input and weights and the bias and then apply the sigmoid function to get a number between
make_prediction() will implement the layers. The first layer takes the dot product of the input and the weight, then adds the bias. The second layer uses the
sigmoid() function, and the return value is the prediction. If you run the code, the prediction is
Looking back at the training data, the expected outcome is
1, so this prediction was correct. Try it again with the second example. It yields a prediction of
0.871, which you will assume to again be
But the expected outcome is
0. This prediction is incorrect. You’ll need to adjust the weights to do better next time, but how much should each weight be modified? Watch the next lesson to find out.
Become a Member to join the conversation.