Skip to content

Instantly share code, notes, and snippets.

@BetterProgramming
Created October 9, 2020 16:07
Show Gist options
  • Save BetterProgramming/1a69deb3a4086e484372cdc87f06ac9a to your computer and use it in GitHub Desktop.
Save BetterProgramming/1a69deb3a4086e484372cdc87f06ac9a to your computer and use it in GitHub Desktop.
def train_epocs(model, epochs=10, lr=0.01, wd=0.0):
optimizer = torch.optim.Adam(model.parameters(), lr=lr, weight_decay=wd)
model.train()
for i in range(epochs):
usernames = torch.LongTensor(train_df.UserId.values)
game_titles = torch.LongTensor(train_df.TitleId.values)
ratings = torch.FloatTensor(train_df.Userscore.values)
y_hat = model(usernames, game_titles)
loss = F.mse_loss(y_hat, ratings)
optimizer.zero_grad() # reset gradient
loss.backward()
optimizer.step()
print(loss.item())
test(model)
@CrispenGari
Copy link

Hello do you mind sharing the dataset that you used on your blogpost https://betterprogramming.pub/building-a-recommendation-engine-with-pytorch-d64be4856fe7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment