class_docstr: Training pipeline for a nonlinear matrix factorization model.
  
  ``NonlinearMatrixFactorizationModel`` models have an embedding layer for users and items. These
  are sent through separate dense networks, which output more refined embeddings, which are then
  dot producted for a single float ranking / rating.
  
  Collie adds a twist on to this novel framework by allowing separate optimizers for embeddings
  and bias terms. With larger datasets and multiple epochs of training, a model might incorrectly
  learn to only optimize the bias terms for a quicker path towards a local loss minimum,
  essentially memorizing how popular each item is. By using a separate, slower optimizer for the
  bias terms (like Stochastic Gradient Descent), the model must prioritize optimizing the
  embeddings for meaningful, more varied recommendations, leading to a model that is able to
  achieve a much lower loss. See the documentation below for ``bias_lr`` and ``bias_optimizer``
  input arguments for implementation details.
  
  All ``NonlinearMatrixFactorizationModel`` instances are subclasses of the ``LightningModule``
  class provided by PyTorch Lightning. This means to train a model, you will need a
  ``collie.model.CollieTrainer`` object, but the model can be saved and loaded without this
  ``Trainer`` instance. Example usage may look like:
  
  .. code-block:: python
  
      from collie.model import CollieTrainer, NonlinearMatrixFactorizationModel
  
  
      model = NonlinearMatrixFactorizationModel(train=train)
      trainer = CollieTrainer(model)
      trainer.fit(model)
      model.eval()
  
      # do evaluation as normal with ``model``
  
      model.save_model(filename='model.pth')
      new_model = NonlinearMatrixFactorizationModel(load_model_path='model.pth')
  
      # do evaluation as normal with ``new_model``
  
  Parameters
  ----------
  user_embedding_dim: int
      Number of latent factors to use for user embeddings
  item_embedding_dim: int
      Number of latent factors to use for item embeddings
  user_dense_layers_dims: list
      List of linear layer dimensions to apply to the user embedding, starting with the dimension
      directly following ``user_embedding_dim``
  item_dense_layers_dims: list
      List of linear layer dimensions to apply to the item embedding, starting with the dimension
      directly following ``item_embedding_dim``
  embedding_dropout_p: float
      Probability of dropout on the embedding layers
  dense_dropout_p: float
      Probability of dropout on the dense layers
  bias_lr: float
      Bias terms learning rate. If 'infer', will set equal to ``lr``
  optimizer: torch.optim or str
      If a string, one of the following supported optimizers:
  
      * ``'sgd'`` (for ``torch.optim.SGD``)
  
      * ``'adam'`` (for ``torch.optim.Adam``)
  
  bias_optimizer: torch.optim or str
      Optimizer for the bias terms. This supports the same string options as ``optimizer``, with
      the addition of ``infer``, which will set the optimizer equal to ``optimizer``. If
      ``bias_optimizer`` is ``None``, only a single optimizer will be created for all model
      parameters
  y_range: tuple
      Specify as ``(min, max)`` to apply a sigmoid layer to the output score of the model to get
      predicted ratings within the range of ``min`` and ``max``
class_docstr_tok: ["Training","pipeline","for","a","nonlinear","matrix","factorization","model",".","``","NonlinearMatrixFactorizationModel","``","models","have","an","embedding","layer","for","users","and","items",".","These","are","sent","through","separate","dense","networks",",","which","output","more","refined","embeddings",",","which","are","then","dot","producted","for","a","single","float","ranking","\/","rating",".","Collie","adds","a","twist","on","to","this","novel","framework","by","allowing","separate","optimizers","for","embeddings","and","bias","terms",".","With","larger","datasets","and","multiple","epochs","of","training",",","a","model","might","incorrectly","learn","to","only","optimize","the","bias","terms","for","a","quicker","path","towards","a","local","loss","minimum",",","essentially","memorizing","how","popular","each","item","is",".","By","using","a","separate",",","slower","optimizer","for","the","bias","terms","(","like","Stochastic","Gradient","Descent",")",",","the","model","must","prioritize","optimizing","the","embeddings","for","meaningful",",","more","varied","recommendations",",","leading","to","a","model","that","is","able","to","achieve","a","much","lower","loss",".","See","the","documentation","below","for","``","bias_lr","``","and","``","bias_optimizer","``","input","arguments","for","implementation","details",".","All","``","NonlinearMatrixFactorizationModel","``","instances","are","subclasses","of","the","``","LightningModule","``","class","provided","by","PyTorch","Lightning",".","This","means","to","train","a","model",",","you","will","need","a","``","collie.model.CollieTrainer","``","object",",","but","the","model","can","be","saved","and","loaded","without","this","``","Trainer","``","instance",".","Example","usage","may","look","like",":","..","code-block",":",":","python","from","collie.model","import","CollieTrainer",",","NonlinearMatrixFactorizationModel","model","=","NonlinearMatrixFactorizationModel","(","train=train",")","trainer","=","CollieTrainer","(","model",")","trainer.fit","(","model",")","model.eval","(",")","#","do","evaluation","as","normal","with","``","model","``","model.save_model","(","filename='model.pth","'",")","new_model","=","NonlinearMatrixFactorizationModel","(","load_model_path='model.pth","'",")","#","do","evaluation","as","normal","with","``","new_model","``","Parameters","--","--","--","--","--","user_embedding_dim",":","int","Number","of","latent","factors","to","use","for","user","embeddings","item_embedding_dim",":","int","Number","of","latent","factors","to","use","for","item","embeddings","user_dense_layers_dims",":","list","List","of","linear","layer","dimensions","to","apply","to","the","user","embedding",",","starting","with","the","dimension","directly","following","``","user_embedding_dim","``","item_dense_layers_dims",":","list","List","of","linear","layer","dimensions","to","apply","to","the","item","embedding",",","starting","with","the","dimension","directly","following","``","item_embedding_dim","``","embedding_dropout_p",":","float","Probability","of","dropout","on","the","embedding","layers","dense_dropout_p",":","float","Probability","of","dropout","on","the","dense","layers","bias_lr",":","float","Bias","terms","learning","rate",".","If","'infer","'",",","will","set","equal","to","``","lr","``","optimizer",":","torch.optim","or","str","If","a","string",",","one","of","the","following","supported","optimizers",":","*","``","'sgd","'","``","(","for","``","torch.optim.SGD","``",")","*","``","'adam","'","``","(","for","``","torch.optim.Adam","``",")","bias_optimizer",":","torch.optim","or","str","Optimizer","for","the","bias","terms",".","This","supports","the","same","string","options","as","``","optimizer","``",",","with","the","addition","of","``","infer","``",",","which","will","set","the","optimizer","equal","to","``","optimizer","``",".","If","``","bias_optimizer","``","is","``","None","``",",","only","a","single","optimizer","will","be","created","for","all","model","parameters","y_range",":","tuple","Specify","as","``","(","min",",","max",")","``","to","apply","a","sigmoid","layer","to","the","output","score","of","the","model","to","get","predicted","ratings","within","the","range","of","``","min","``","and","``","max","``"]
docstr: Get user embeddings on device.
docstr_tok: ["Get","user","embeddings","on","device","."]
code: def _get_user_embeddings(self) -> torch.tensor:
      """Get user embeddings on device."""
      if not hasattr(self, "user_embeddings_"):
          users = torch.arange(
              self.hparams.num_users, device=self.device
          )
  
          user_embeddings = self.user_embeddings(users)
  
          for user_dense_layer in self.user_dense_layers:
              user_embeddings = F.leaky_relu(
                  user_dense_layer(user_embeddings)
              )
  
          self.user_embeddings_ = user_embeddings.detach()
  
      return self.user_embeddings_
  
file_path: collie/collie/model/nonlinear_matrix_factorization.py
imports: from functools import partial
  from typing import Callable, Dict, List, Optional, Tuple, Union
  import torch
  from torch import nn
  import torch.nn.functional
  from torch.optim.lr_scheduler import ReduceLROnPlateau
  from collie.model.base import BasePipeline, INTERACTIONS_LIKE_INPUT, ScaledEmbedding, ZeroEmbedding
  from collie.utils import get_init_arguments, merge_docstrings
label_desc: Use image node_id 5 for calling the NonlinearMatrixFactorizationModel obj's underlying member method code with example usage: obj._get_user_embeddings() and returns: self