Machine Learning - Neural Networks (Foundations)
Quick start (PyTorch)
import torch, torch.nn as nn
X = torch.randn(128, 10)
y = torch.randint(0, 2, (128,))
model = nn.Sequential(
nn.Linear(10, 32), nn.ReLU(),
nn.Linear(32, 2)
)
loss_fn = nn.CrossEntropyLoss()
opt = torch.optim.Adam(model.parameters(), lr=1e-3)
for epoch in range(20):
opt.zero_grad(); loss = loss_fn(model(X), y); loss.backward(); opt.step()