From 891fc8534969f68a45fd1708e3434fe41aa5c676 Mon Sep 17 00:00:00 2001 From: sumana sree Date: Thu, 4 Jul 2024 23:12:40 +0530 Subject: [PATCH 1/6] modified 2 files to update newsrec model Signed-off-by: sumana sree --- recommenders/models/newsrec/models/base_model.py | 4 ++++ .../smoke/recommenders/recommender/test_newsrec_model.py | 8 ++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/recommenders/models/newsrec/models/base_model.py b/recommenders/models/newsrec/models/base_model.py index e0f4da017..1e2f2cdd4 100644 --- a/recommenders/models/newsrec/models/base_model.py +++ b/recommenders/models/newsrec/models/base_model.py @@ -186,6 +186,8 @@ def fit( valid_behaviors_file, test_news_file=None, test_behaviors_file=None, + steps=None, + ): """Fit the model with train_file. Evaluate the model on valid_file per epoch to observe the training status. If test_news_file is not None, evaluate it too. @@ -212,6 +214,8 @@ def fit( ) for batch_data_input in tqdm_util: + if steps is not None and steps>=steps: + break step_result = self.train(batch_data_input) step_data_loss = step_result diff --git a/tests/smoke/recommenders/recommender/test_newsrec_model.py b/tests/smoke/recommenders/recommender/test_newsrec_model.py index 7cad05ba3..8abd2d433 100644 --- a/tests/smoke/recommenders/recommender/test_newsrec_model.py +++ b/tests/smoke/recommenders/recommender/test_newsrec_model.py @@ -62,7 +62,7 @@ def test_model_nrms(mind_resource_path): assert model.run_eval(valid_news_file, valid_behaviors_file) is not None assert isinstance( model.fit( - train_news_file, train_behaviors_file, valid_news_file, valid_behaviors_file + train_news_file, train_behaviors_file, valid_news_file, valid_behaviors_file,steps=1 ), BaseModel, ) @@ -115,7 +115,7 @@ def test_model_naml(mind_resource_path): assert model.run_eval(valid_news_file, valid_behaviors_file) is not None assert isinstance( model.fit( - train_news_file, train_behaviors_file, valid_news_file, valid_behaviors_file + train_news_file, train_behaviors_file, valid_news_file, valid_behaviors_file,steps=1 ), BaseModel, ) @@ -166,7 +166,7 @@ def test_model_lstur(mind_resource_path): assert model.run_eval(valid_news_file, valid_behaviors_file) is not None assert isinstance( model.fit( - train_news_file, train_behaviors_file, valid_news_file, valid_behaviors_file + train_news_file, train_behaviors_file, valid_news_file, valid_behaviors_file,steps=1 ), BaseModel, ) @@ -217,7 +217,7 @@ def test_model_npa(mind_resource_path): assert model.run_eval(valid_news_file, valid_behaviors_file) is not None assert isinstance( model.fit( - train_news_file, train_behaviors_file, valid_news_file, valid_behaviors_file + train_news_file, train_behaviors_file, valid_news_file, valid_behaviors_file,steps=1 ), BaseModel, ) From 7c9a6931031d78c5f956d4bcb13f3156dbaa8989 Mon Sep 17 00:00:00 2001 From: sumana sree Date: Fri, 5 Jul 2024 19:22:43 +0530 Subject: [PATCH 2/6] changed the parameter name from steps to step_limit Signed-off-by: sumana sree --- recommenders/models/newsrec/models/base_model.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/recommenders/models/newsrec/models/base_model.py b/recommenders/models/newsrec/models/base_model.py index 1e2f2cdd4..c19679c95 100644 --- a/recommenders/models/newsrec/models/base_model.py +++ b/recommenders/models/newsrec/models/base_model.py @@ -186,7 +186,7 @@ def fit( valid_behaviors_file, test_news_file=None, test_behaviors_file=None, - steps=None, + step_limit=None, ): """Fit the model with train_file. Evaluate the model on valid_file per epoch to observe the training status. @@ -214,7 +214,7 @@ def fit( ) for batch_data_input in tqdm_util: - if steps is not None and steps>=steps: + if step_limit is not None and step_limit>=step_limit: break step_result = self.train(batch_data_input) From 2a9604e49663773b2c2b8239edf7f627614e5100 Mon Sep 17 00:00:00 2001 From: sumana sree Date: Fri, 5 Jul 2024 19:26:09 +0530 Subject: [PATCH 3/6] changed parameter name to step_limit from steps Signed-off-by: sumana sree --- .../smoke/recommenders/recommender/test_newsrec_model.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/smoke/recommenders/recommender/test_newsrec_model.py b/tests/smoke/recommenders/recommender/test_newsrec_model.py index 8abd2d433..f52f20cdd 100644 --- a/tests/smoke/recommenders/recommender/test_newsrec_model.py +++ b/tests/smoke/recommenders/recommender/test_newsrec_model.py @@ -62,7 +62,7 @@ def test_model_nrms(mind_resource_path): assert model.run_eval(valid_news_file, valid_behaviors_file) is not None assert isinstance( model.fit( - train_news_file, train_behaviors_file, valid_news_file, valid_behaviors_file,steps=1 + train_news_file, train_behaviors_file, valid_news_file, valid_behaviors_file,step_limit=1 ), BaseModel, ) @@ -115,7 +115,7 @@ def test_model_naml(mind_resource_path): assert model.run_eval(valid_news_file, valid_behaviors_file) is not None assert isinstance( model.fit( - train_news_file, train_behaviors_file, valid_news_file, valid_behaviors_file,steps=1 + train_news_file, train_behaviors_file, valid_news_file, valid_behaviors_file,step_limit=1 ), BaseModel, ) @@ -166,7 +166,7 @@ def test_model_lstur(mind_resource_path): assert model.run_eval(valid_news_file, valid_behaviors_file) is not None assert isinstance( model.fit( - train_news_file, train_behaviors_file, valid_news_file, valid_behaviors_file,steps=1 + train_news_file, train_behaviors_file, valid_news_file, valid_behaviors_file,step_limit=1 ), BaseModel, ) @@ -217,7 +217,7 @@ def test_model_npa(mind_resource_path): assert model.run_eval(valid_news_file, valid_behaviors_file) is not None assert isinstance( model.fit( - train_news_file, train_behaviors_file, valid_news_file, valid_behaviors_file,steps=1 + train_news_file, train_behaviors_file, valid_news_file, valid_behaviors_file,step_limit=1 ), BaseModel, ) From 650ad365748b3be297c4a9a14d6c21c2b1c63034 Mon Sep 17 00:00:00 2001 From: Sumana Sree <110307215+sumana-2705@users.noreply.github.com> Date: Sat, 6 Jul 2024 09:07:57 +0530 Subject: [PATCH 4/6] Update recommenders/models/newsrec/models/base_model.py Co-authored-by: Miguel Fierro <3491412+miguelgfierro@users.noreply.github.com> --- recommenders/models/newsrec/models/base_model.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recommenders/models/newsrec/models/base_model.py b/recommenders/models/newsrec/models/base_model.py index c19679c95..344ea8f7c 100644 --- a/recommenders/models/newsrec/models/base_model.py +++ b/recommenders/models/newsrec/models/base_model.py @@ -214,7 +214,7 @@ def fit( ) for batch_data_input in tqdm_util: - if step_limit is not None and step_limit>=step_limit: + if step_limit is not None and step>=step_limit: break step_result = self.train(batch_data_input) From 6cb04d3a7a82cb4ddc31945abb2bc9e9b83e411d Mon Sep 17 00:00:00 2001 From: sumana sree Date: Sat, 6 Jul 2024 09:15:07 +0530 Subject: [PATCH 5/6] corrected mistake Signed-off-by: sumana sree --- recommenders/models/newsrec/models/base_model.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recommenders/models/newsrec/models/base_model.py b/recommenders/models/newsrec/models/base_model.py index c19679c95..344ea8f7c 100644 --- a/recommenders/models/newsrec/models/base_model.py +++ b/recommenders/models/newsrec/models/base_model.py @@ -214,7 +214,7 @@ def fit( ) for batch_data_input in tqdm_util: - if step_limit is not None and step_limit>=step_limit: + if step_limit is not None and step>=step_limit: break step_result = self.train(batch_data_input) From 3fbbefe62e8895e2f829d91baf5eedaedab8de5b Mon Sep 17 00:00:00 2001 From: sumana sree Date: Sun, 7 Jul 2024 14:12:57 +0530 Subject: [PATCH 6/6] set step_limit = 10 Signed-off-by: sumana sree --- .../smoke/recommenders/recommender/test_newsrec_model.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/smoke/recommenders/recommender/test_newsrec_model.py b/tests/smoke/recommenders/recommender/test_newsrec_model.py index f52f20cdd..db609f098 100644 --- a/tests/smoke/recommenders/recommender/test_newsrec_model.py +++ b/tests/smoke/recommenders/recommender/test_newsrec_model.py @@ -62,7 +62,7 @@ def test_model_nrms(mind_resource_path): assert model.run_eval(valid_news_file, valid_behaviors_file) is not None assert isinstance( model.fit( - train_news_file, train_behaviors_file, valid_news_file, valid_behaviors_file,step_limit=1 + train_news_file, train_behaviors_file, valid_news_file, valid_behaviors_file,step_limit=10 ), BaseModel, ) @@ -115,7 +115,7 @@ def test_model_naml(mind_resource_path): assert model.run_eval(valid_news_file, valid_behaviors_file) is not None assert isinstance( model.fit( - train_news_file, train_behaviors_file, valid_news_file, valid_behaviors_file,step_limit=1 + train_news_file, train_behaviors_file, valid_news_file, valid_behaviors_file,step_limit=10 ), BaseModel, ) @@ -166,7 +166,7 @@ def test_model_lstur(mind_resource_path): assert model.run_eval(valid_news_file, valid_behaviors_file) is not None assert isinstance( model.fit( - train_news_file, train_behaviors_file, valid_news_file, valid_behaviors_file,step_limit=1 + train_news_file, train_behaviors_file, valid_news_file, valid_behaviors_file,step_limit=10 ), BaseModel, ) @@ -217,7 +217,7 @@ def test_model_npa(mind_resource_path): assert model.run_eval(valid_news_file, valid_behaviors_file) is not None assert isinstance( model.fit( - train_news_file, train_behaviors_file, valid_news_file, valid_behaviors_file,step_limit=1 + train_news_file, train_behaviors_file, valid_news_file, valid_behaviors_file,step_limit=10 ), BaseModel, )