YouTip LogoYouTip

PyTorch Tutorial - Getting Started

Tensors

import torch
x = torch.tensor([1.0, 2.0, 3.0])
y = torch.randn(3, 3)
print(x + x)

Neural Network

import torch.nn as nn
model = nn.Sequential(
    nn.Linear(784, 128),
    nn.ReLU(),
    nn.Linear(128, 10)
)
optimizer = torch.optim.Adam(model.parameters())

Summary

  • Tensors are like NumPy arrays with GPU support
  • nn.Sequential stacks layers
← Scikit-learn Tutorial - GettinTensorFlow Tutorial - Getting β†’