Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Fixing unintentional variable overloading #14438

Merged
merged 11 commits into from
Apr 3, 2019
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
---------
Expand Down
8 changes: 4 additions & 4 deletions example/recommenders/matrix_fact.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand All @@ -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)
Expand All @@ -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