PyTorch로 배우는 딥러닝 입문
Jasmin Ludolf
Senior Data Science Content Developer, DataCamp
$$







0과 1 사이 값을 얻습니다
출력 > 0.5 이면 레이블 = 1(포유류)
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
)
선형 계층 뒤 마지막 단계로 시그모이드를 쓰면 전통적 로지스틱 회귀와 동일합니다






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은 입력 텐서의 마지막 차원에 소프트맥스를 적용함을 의미합니다nn.Softmax()는 nn.Sequential()의 마지막 단계로 사용할 수 있습니다PyTorch로 배우는 딥러닝 입문