As my first AI model I have decided to make an AI model to predict multiplication of two numbers EX - [2,4] = . I wrote the following code, but the loss is very high, around thousands, and it's very inaccurate. How do I make it more accurate?
import torch import torch.nn as nn import torch.nn.functional as F data = torch.tensor([[2,4],[3,6],[3,3],[4,4],[100,5]],dtype=torch.float) values = torch.tensor([,,,,],dtype=torch.float) lossfun = torch.nn.MSELoss() model=Net() optim = torch.optim.Adam(model.parameters(),lr=0.5) class Net(nn.Module): def __init__(self): super(Net,self).__init__(); self.fc1 = nn.Linear(in_features=2,out_features=3) self.fc2 = nn.Linear(in_features=3,out_features=6) self.out = nn.Linear(in_features=6,out_features=1) def forward(self,x): x = self.fc1(x) x = F.relu(x) x = self.fc2(x) x = F.relu(x) x = self.out(x) return x for epoch in range(1000): y_pred=model.forward(data) loss = lossfun(y_pred,values) print(loss.item()) loss.backward() optim.step()
Note: I am a newbie in AI and ML.