Explicit factorization models

Factorization models for explicit feedback problems.

class spotlight.factorization.explicit.ExplicitFactorizationModel(loss='regression', embedding_dim=32, n_iter=10, batch_size=256, l2=0.0, learning_rate=0.01, optimizer_func=None, use_cuda=False, representation=None, sparse=False, random_state=None)[source]

An explicit feedback matrix factorization model. Uses a classic matrix factorization 1 approach, with latent vectors used to represent both users and items. Their dot product gives the predicted score for a user-item pair.

The latent representation is given by spotlight.factorization.representations.BilinearNet.

1

Koren, Yehuda, Robert Bell, and Chris Volinsky. “Matrix factorization techniques for recommender systems.” Computer 42.8 (2009).

Parameters
  • loss (string, optional) – One of ‘regression’, ‘poisson’, ‘logistic’ corresponding to losses from spotlight.losses.

  • embedding_dim (int, optional) – Number of embedding dimensions to use for users and items.

  • n_iter (int, optional) – Number of iterations to run.

  • batch_size (int, optional) – Minibatch size.

  • l2 (float, optional) – L2 loss penalty.

  • learning_rate (float, optional) – Initial learning rate.

  • optimizer_func (function, optional) – Function that takes in module parameters as the first argument and returns an instance of a PyTorch optimizer. Overrides l2 and learning rate if supplied. If no optimizer supplied, then use ADAM by default.

  • use_cuda (boolean, optional) – Run the model on a GPU.

  • representation (a representation module, optional) – If supplied, will override default settings and be used as the main network module in the model. Intended to be used as an escape hatch when you want to reuse the model’s training functions but want full freedom to specify your network topology.

  • sparse (boolean, optional) – Use sparse gradients for embedding layers.

  • random_state (instance of numpy.random.RandomState, optional) – Random state to use when fitting.

fit(interactions, verbose=False)[source]

Fit the model.

When called repeatedly, model fitting will resume from the point at which training stopped in the previous fit call.

Parameters
predict(user_ids, item_ids=None)[source]

Make predictions: given a user id, compute the recommendation scores for items.

Parameters
  • user_ids (int or array) – If int, will predict the recommendation scores for this user for all items in item_ids. If an array, will predict scores for all (user, item) pairs defined by user_ids and item_ids.

  • item_ids (array, optional) – Array containing the item ids for which prediction scores are desired. If not supplied, predictions for all items will be computed.

Returns

predictions – Predicted scores for all items in item_ids.

Return type

np.array