From 9b06a518163b303c8912e64ac726a2b389c121d5 Mon Sep 17 00:00:00 2001 From: Jaime Hieu Do Date: Tue, 24 Oct 2023 11:28:20 +0800 Subject: [PATCH] NCF fix, normalize running loss (#537) Correct printed running loss --------- Co-authored-by: Quoc-Tuan Truong --- cornac/models/ncf/recom_ncf_base.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cornac/models/ncf/recom_ncf_base.py b/cornac/models/ncf/recom_ncf_base.py index 2541a4272..4f47877ea 100644 --- a/cornac/models/ncf/recom_ncf_base.py +++ b/cornac/models/ncf/recom_ncf_base.py @@ -178,8 +178,8 @@ def _fit_tf(self): batch_users, batch_items, batch_ratings ), ) - count += len(batch_ratings) - sum_loss += _loss * len(batch_ratings) + count += len(batch_users) + sum_loss += len(batch_users) * _loss if i % 10 == 0: loop.set_postfix(loss=(sum_loss / count)) @@ -242,7 +242,7 @@ def _fit_pt(self): optimizer.step() count += len(batch_users) - sum_loss += loss.data.item() + sum_loss += len(batch_users) * loss.data.item() if batch_id % 10 == 0: loop.set_postfix(loss=(sum_loss / count))