Introductie tot Deep Learning met PyTorch
Jasmin Ludolf
Senior Data Science Content Developer, DataCamp
$$







Geeft een waarde tussen 0 en 1
Als output > 0,5, klasselabel = 1 (zoogdier)
import torch import torch.nn as nn input_tensor = torch.tensor([[6]]) sigmoid = nn.Sigmoid()output = sigmoid(input_tensor) print(output)
tensor([[0.9975]])
model = nn.Sequential(
nn.Linear(6, 4), # First linear layer
nn.Linear(4, 1), # Second linear layer
nn.Sigmoid() # Sigmoid activation function
)
Sigmoid als laatste stap in een netwerk van lineaire lagen is gelijkwaardig aan traditionele logistische regressie






import torch import torch.nn as nn # Create an input tensor input_tensor = torch.tensor( [[4.3, 6.1, 2.3]]) # Apply softmax along the last dimensionprobabilities = nn.Softmax(dim=-1) output_tensor = probabilities(input_tensor) print(output_tensor)
tensor([[0.1392, 0.8420, 0.0188]])
dim = -1 geeft aan dat softmax wordt toegepast op de laatste dimensie van de input-tensornn.Softmax() kan als laatste stap in nn.Sequential()Introductie tot Deep Learning met PyTorch