Created
October 9, 2020 16:07
-
-
Save BetterProgramming/1a69deb3a4086e484372cdc87f06ac9a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello do you mind sharing the dataset that you used on your blogpost https://betterprogramming.pub/building-a-recommendation-engine-with-pytorch-d64be4856fe7