Pytorch Cheatsheet EN
Pytorch Cheatsheet EN
nn.Dropout(p=0.5): Randomly
Train model
nn.BatchNormXd(n): Normalizes a X-dimensional
sets input elements to zero during input batch with n features; X {1, 2, 3} LOSS FUNCTIONS
training to prevent overfitting
PyTorch already offers a bunch of different
loss fuctions, e.g.:
nn.Embedding(m, n): Lookup table nn.RNN/LSTM/GRU: Recurrent networks nn.L1Loss Mean absolute error
to map dictionary of size m to connect neurons of one layer with neurons of the
embedding vector of size n same or a previous layer nn.MSELoss Mean squared error (L2Loss)
nn.CrossEntropyLoss Cross entropy, e.g. for single-label
torch.nn offers a bunch of other building blocks. classification or unbalanced training set
A list of state-of-the-art architectures can be found at https://paperswithcode.com/sota.
nn.BCELoss Binary cross entropy, e.g. for multi-label
classification or autoencoders
Load data Activation functions OPTIMIZATION (torch.optim)
A dataset is represented by a class that Common activation functions include ReLU,
inherits from Dataset (resembles a list Optimization algorithms are used to update
Sigmoid and Tanh, but there are other activation weights and dynamically adapt the learning
of tuples of the form (features, label)). functions as well. rate with gradient descent, e.g.:
DataLoader allows to load a dataset optim.SGD
nn.ReLU() creates a nn.Module for example to be used in Stochastic gradient descent
without caring about its structure.
Sequential models. F.relu() ist just a call of the ReLU function optim.Adam Adaptive moment estimation
Usually the dataset is split into training e.g. to be used in the forward method.
optim.Adagrad Adaptive gradient
(e.g. 80%) and test data (e.g. 20%).
optim.RMSProp Root mean square prop
nn.ReLU() or F.relu()
Output between 0 and ∞,
most frequently used activation function
Evaluate model
The evaluation examines whether the model provides
nn.Sigmoid() or F.sigmoid() satisfactory results on previously withheld data.
Output between 0 and 1, Depending on the objective, different metrics are used,
often used for predicting probabilities such as acurracy, precision, recall, F1, or BLEU.
Stefan Seegerer, hi@stefanseegerer.de Matthias Zürl, matthias.zuerl@fau.de CC-BY-SA Last updated: 10/2021