Skip to content

Instantly share code, notes, and snippets.

@andreaschandra
Created September 6, 2021 06:08
Show Gist options
  • Save andreaschandra/70fb0308e7a3946c89fb4cdc7cb60150 to your computer and use it in GitHub Desktop.
Save andreaschandra/70fb0308e7a3946c89fb4cdc7cb60150 to your computer and use it in GitHub Desktop.
# import modules
import torch.nn as nn
import torch.optim as optim
# define optimizer
# using previous model that we have built
# using Adam optimizer and learning rate = 0.001
optimizer = optim.Adam(model.parameters(), lr=1e-3)
print(optimizer)
# define loss function
# if the task is regression probem we can use Mean Squared Error
loss_fn = nn.MSELoss()
# if the task is binary classification problem, we can use BCELoss
loss_fn = nn.BCELoss()
# if the task is multiclass classification problem, we can use CrossEntropy
loss_fn = nn.CrossEntropyLoss()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment