Skip to content

Instantly share code, notes, and snippets.

@fatalure
Last active December 9, 2019 06:48
Show Gist options
  • Save fatalure/6f92a4afd9cc2de4985f4f1a1cf6e4e4 to your computer and use it in GitHub Desktop.
Save fatalure/6f92a4afd9cc2de4985f4f1a1cf6e4e4 to your computer and use it in GitHub Desktop.
keep_prob = 0.5
def train_step(X):
hidden_layer_1 = np.maximum(0, np.dot(W1, X) + b1)
dropout_mask_1 = np.random.binomial(1, keep_prob, hidden_layer_1.shape)
hidden_layer_1 *= dropout_mask_1
hidden_layer_2 = np.maximum(0, np.dot(W2, hidden_layer_1) + b2)
dropout_mask_2 = np.random.binomial(1, keep_prob, hidden_layer_2.shape)
hidden_layer_2 *= dropout_mask_2
out = np.dot(W3, hidden_layer_2) + b3
# backward pass: compute gradients... (not shown)
# perform parameter update... (not shown)
def predict(X):
# ensembled forward pass
hidden_layer_1 = np.maximum(0, np.dot(W1, X) + b1) * keep_prob # NOTE: scale the activations
hidden_layer_2 = np.maximum(0, np.dot(W2, hidden_layer_1) + b2) * keep_prob # NOTE: scale the activations
out = np.dot(W3, hidden_layer_2) + b3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment