March 2020
Beginner to intermediate
342 pages
8h 38m
English
It’s been a while since we reviewed the code of the neural network. Here it is—all of it, for the last time:
| | import numpy as np |
| | |
| | |
| | def sigmoid(z): |
| | return 1 / (1 + np.exp(-z)) |
| | |
| | |
| | def softmax(logits): |
| | exponentials = np.exp(logits) |
| | return exponentials / np.sum(exponentials, axis=1).reshape(-1, 1) |
| | |
| | |
| | def sigmoid_gradient(sigmoid): |
| | return np.multiply(sigmoid, (1 - sigmoid)) |
| | |
| | |
| | def loss(Y, y_hat): |
| | return -np.sum(Y * np.log(y_hat)) / Y.shape[0] |
| | |
| | |
| | def prepend_bias(X): |
| | return np.insert(X, 0, 1, axis=1) |
| | def forward(X, w1, w2): |
| | h = sigmoid(np.matmul(prepend_bias(X), w1)) |
| | y_hat = softmax(np.matmul(prepend_bias(h), w2)) |
| | return (y_hat, ... |
Read now
Unlock full access