import torch
from tinypytorch.data import get_local_data
from tinypytorch.model import initialize_parameters, Model
from tinypytorch.metrics import accuracy
Dependence libraries - nbdev - torch - matplotlib - pytest
This file will become your README and also the index of your documentation.
pip install tinypytorch
x_train, y_train, x_valid, y_valid = get_local_data()
x_train.shape, y_train.shape
(torch.Size([50000, 784]), torch.Size([50000]))
y_train[1]
tensor(0)
y_train[1:5]
tensor([0, 4, 1, 9])
n, m = x_train.shape # num rows and columns
c = y_train.max() + 1
n, m, c
(50000, 784, tensor(10))
nh = 50 # num hidden
w1, b1, w2, b2 = initialize_parameters(m, nh)
w1.shape, b1.shape
(torch.Size([784, 50]), torch.Size([50]))
w2.shape, b2.shape
(torch.Size([50, 1]), torch.Size([1]))
- Training set’s shape: (50000, 784)
- Weight’s shape: (784, 50)
- Bias’s shape: (50)
model = Model(w1, b1, w2, b2)
loss = model(x_train, y_train)
Model.__call__
l=<tinypytorch.model.Lin object>
Lin.forward
inp=torch.Size([50000, 784])
w=torch.Size([784, 50])
b=torch.Size([50])
output.shape=torch.Size([50000, 50])
x.shape=torch.Size([50000, 50])
Model.__call__
l=<tinypytorch.model.ReLU object>
x.shape=torch.Size([50000, 50])
Model.__call__
l=<tinypytorch.model.Lin object>
Lin.forward
inp=torch.Size([50000, 50])
w=torch.Size([50, 1])
b=torch.Size([1])
output.shape=torch.Size([50000, 1])
x.shape=torch.Size([50000, 1])
loss
tensor(26.1652)
model.backward()
bs = 64
xb = x_train[0:64]