From 6478691dc0a11255ee569e0b8d95c1064a830de7 Mon Sep 17 00:00:00 2001 From: zjost Date: Tue, 2 Apr 2019 21:09:40 -0700 Subject: [PATCH] Fixing unintentional variable overloading (#14438) * Fixing unintentional variable overloading * Adding to conbributor list * Fixing unintentional variable overloading * Adding to conbributor list * Fixing unintentional variable overloading * Adding to conbributor list * Fixing unintentional variable overloading * Adding to conbributor list --- CONTRIBUTORS.md | 1 + example/recommenders/matrix_fact.py | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 2b74e12c412d..5c5c217b47eb 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -235,6 +235,7 @@ List of Contributors * [Xinyu Chen](https://github.com/xinyu-intel) * [Zhennan Qin](https://github.com/ZhennanQin) * [Zhiyuan Huang](https://github.com/huangzhiyuan) +* [Zak Jost](https://github.com/zjost) Label Bot --------- diff --git a/example/recommenders/matrix_fact.py b/example/recommenders/matrix_fact.py index 5f7d173f4e1f..4a438c757710 100644 --- a/example/recommenders/matrix_fact.py +++ b/example/recommenders/matrix_fact.py @@ -28,14 +28,14 @@ def evaluate_network(network, data_iterator, ctx): loss_acc = 0. l2 = gluon.loss.L2Loss() - for i, (users, items, scores) in enumerate(data_iterator): + for idx, (users, items, scores) in enumerate(data_iterator): users_ = gluon.utils.split_and_load(users, ctx) items_ = gluon.utils.split_and_load(items, ctx) scores_ =gluon.utils.split_and_load(scores, ctx) preds = [network(u, i) for u, i in zip(users_, items_)] losses = [l2(p, s).asnumpy() for p, s in zip(preds, scores_)] loss_acc += sum(losses).mean()/len(ctx) - return loss_acc/(i+1) + return loss_acc/(idx+1) def train(network, train_data, test_data, epochs, learning_rate=0.01, optimizer='sgd', ctx=mx.gpu(0), num_epoch_lr=5, factor=0.2): @@ -56,7 +56,7 @@ def train(network, train_data, test_data, epochs, learning_rate=0.01, optimizer= losses_output = [] for e in range(epochs): loss_acc = 0. - for i, (users, items, scores) in enumerate(train_data): + for idx, (users, items, scores) in enumerate(train_data): users_ = gluon.utils.split_and_load(users, ctx) items_ = gluon.utils.split_and_load(items, ctx) @@ -71,7 +71,7 @@ def train(network, train_data, test_data, epochs, learning_rate=0.01, optimizer= trainer.update(users.shape[0]) test_loss = evaluate_network(network, test_data, ctx) - train_loss = loss_acc/(i+1) + train_loss = loss_acc/(idx+1) print("Epoch [{}], Training RMSE {:.4f}, Test RMSE {:.4f}".format(e, train_loss, test_loss)) losses_output.append((train_loss, test_loss)) return losses_output \ No newline at end of file