Hi Thank you for your reply.
I have made following changes but still get this error : “The size of tensor a (28) must match the size of tensor b (10) at non-singleton dimension 3”
weights = (torch.randn(28, 28) / math.sqrt(28))
weights.requires_grad_()
bias = torch.zeros((10), requires_grad=True)
print(weights.shape)
print(bias.shape)
def log_softmax(x):
return (x - x.exp().sum(-1).log().unsqueeze(-1))

def model(xb):
return log_softmax(xb @ weights + bias)

bs = 1  # batch size
xb = x_train[0:bs]  # a mini-batch from x
preds = model(xb)  # predictions
preds[0], preds.shape
print(preds[0], preds.shape)