diff --git a/docs/source/index.rst b/docs/source/index.rst index d9db2a1e2..c2dc7ab57 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -11,7 +11,7 @@ Introduction RecBole is a unified, comprehensive and efficient framework developed based on PyTorch. It aims to help the researchers to reproduce and develop recommendation models. -In the lastest release, our library includes 88 recommendation algorithms `[Model List]`_, covering four major categories: +In the lastest release, our library includes 89 recommendation algorithms `[Model List]`_, covering four major categories: - General Recommendation - Sequential Recommendation diff --git a/docs/source/user_guide/model/general/random.rst b/docs/source/user_guide/model/general/random.rst new file mode 100644 index 000000000..fb6c95fd7 --- /dev/null +++ b/docs/source/user_guide/model/general/random.rst @@ -0,0 +1,38 @@ +Random +=========== + +Introduction +--------------------- + +When discussing recommendation systems, accuracy is often regarded as the most crucial metric. +However, besides accuracy, several other key metrics can evaluate the effectiveness of a recommendation system, such as diversity, coverage, and efficiency. +In this context, the random recommendation algorithm is a valuable baseline. +In terms of implementation, for a given user and item, the random recommendation algorithm provides a random rating. + +Running with RecBole + + + +**A Running Example:** + +Write the following code to a python file, such as `run.py` + +.. code:: python + + from recbole.quick_start import run_recbole + + run_recbole(model='Random', dataset='ml-100k') + +And then: + +.. code:: bash + + python run.py + + +If you want to change parameters, dataset or evaluation settings, take a look at + +- :doc:`../../../user_guide/config_settings` +- :doc:`../../../user_guide/data_intro` +- :doc:`../../../user_guide/train_eval_intro` +- :doc:`../../../user_guide/usage` \ No newline at end of file diff --git a/docs/source/user_guide/model_intro.rst b/docs/source/user_guide/model_intro.rst index f3ffcbfc3..c4b31315e 100644 --- a/docs/source/user_guide/model_intro.rst +++ b/docs/source/user_guide/model_intro.rst @@ -42,6 +42,7 @@ task of top-n recommendation. All the collaborative filter(CF) based models are model/general/nceplrec model/general/simplex model/general/ncl + model/general/random model/general/diffrec model/general/ldiffrec diff --git a/recbole/model/general_recommender/__init__.py b/recbole/model/general_recommender/__init__.py index 8113b6236..04187e129 100644 --- a/recbole/model/general_recommender/__init__.py +++ b/recbole/model/general_recommender/__init__.py @@ -21,6 +21,7 @@ from recbole.model.general_recommender.nncf import NNCF from recbole.model.general_recommender.pop import Pop from recbole.model.general_recommender.ract import RaCT +from recbole.model.general_recommender.random import Random from recbole.model.general_recommender.recvae import RecVAE from recbole.model.general_recommender.slimelastic import SLIMElastic from recbole.model.general_recommender.spectralcf import SpectralCF diff --git a/recbole/model/general_recommender/random.py b/recbole/model/general_recommender/random.py new file mode 100644 index 000000000..e2b8d2e26 --- /dev/null +++ b/recbole/model/general_recommender/random.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# @Time : 2023/03/01 +# @Author : João Felipe Guedes +# @Email : guedes.joaofelipe@poli.ufrj.br +# UPDATE + +r""" +Random +################################################ + +""" + +import torch +import random + +from recbole.model.abstract_recommender import GeneralRecommender +from recbole.utils import InputType, ModelType + + +class Random(GeneralRecommender): + """Random is an fundamental model that recommends random items.""" + + input_type = InputType.POINTWISE + type = ModelType.TRADITIONAL + + def __init__(self, config, dataset): + super(Random, self).__init__(config, dataset) + torch.manual_seed(config["seed"] + self.n_users + self.n_items) + self.fake_loss = torch.nn.Parameter(torch.zeros(1)) + + def forward(self): + pass + + def calculate_loss(self, interaction): + return torch.nn.Parameter(torch.zeros(1)) + + def predict(self, interaction): + return torch.rand(len(interaction)).squeeze(-1) + + def full_sort_predict(self, interaction): + batch_user_num = interaction[self.USER_ID].shape[0] + result = torch.rand(self.n_items, 1).to(torch.float64) + result = torch.repeat_interleave(result.unsqueeze(0), batch_user_num, dim=0) + return result.view(-1) diff --git a/tests/model/test_model_auto.py b/tests/model/test_model_auto.py index a36111010..672d8b659 100644 --- a/tests/model/test_model_auto.py +++ b/tests/model/test_model_auto.py @@ -30,6 +30,12 @@ def test_pop(self): } quick_test(config_dict) + def test_random(self): + config_dict = { + "model": "Random", + } + quick_test(config_dict) + def test_itemknn(self): config_dict = { "model": "ItemKNN",