Skip to content

Instantly share code, notes, and snippets.

@Niranjankumar-c
Created October 20, 2019 06:35
Show Gist options
  • Save Niranjankumar-c/49ec04404eea151c119b6078e1ebde57 to your computer and use it in GitHub Desktop.
Save Niranjankumar-c/49ec04404eea151c119b6078e1ebde57 to your computer and use it in GitHub Desktop.
model for visualizing dropout
#create a neural network with out dropout
N_h = 100 #hidden nodes
model = torch.nn.Sequential(
nn.Linear(1, N_h),
nn.ReLU(),
nn.Linear(N_h, N_h),
nn.ReLU(),
nn.Linear(N_h, 1)
)
#create a network with dropout
model_dropout = nn.Sequential(
nn.Linear(1, N_h),
nn.Dropout(0.5), #50 % probability
nn.ReLU(),
torch.nn.Linear(N_h, N_h),
torch.nn.Dropout(0.2), #20% probability
torch.nn.ReLU(),
torch.nn.Linear(N_h, 1),
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment