class_docstr: Training pipeline for a deep factorization model.
  
  ``DeepFM`` models combine a shallow factorization machine and a deep multilayer perceptron
  network in a single, unified model. The model consists of embedding tables for users and items,
  and model output is the sum of 1) factorization machine output of both embeddings (shallow) and
  2) MLP output for the concatenation of both embeddings (deep).
  
  The implementation here is meant to mimic its original implementation as specified here:
  https://arxiv.org/pdf/1703.04247.pdf [3]_
  
  All ``DeepFM`` 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, DeepFM
  
  
      model = DeepFM(train=train)
      trainer = CollieTrainer(model)
      trainer.fit(model)
      model.eval()
  
      # do evaluation as normal with ``model``
  
      model.save_model(filename='model.pth')
      new_model = DeepFM(load_model_path='model.pth')
  
      # do evaluation as normal with ``new_model``
  
  Parameters
  ----------
  embedding_dim: int
      Number of latent factors to use for the matrix factorization embedding table. For the MLP
      embedding table, the dimensionality will be calculated with the formula
      ``embedding_dim * (2 ** (num_layers - 1))``
  num_layers: int
      Number of MLP layers to apply. Each MLP layer will have its input dimension calculated with
      the formula ``embedding_dim * (2 ** (``num_layers`` - ``current_layer_number``))``
  final_layer: str or function
      Final layer activation function. Available string options include:
  
      * 'sigmoid'
  
      * 'relu'
  
      * 'leaky_relu'
  
  dropout_p: float
      Probability of dropout
  sparse: bool
      Whether or not to treat embeddings as sparse tensors. If ``True``, cannot use weight decay
      on the optimizer
  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``
  
  References
  ----------
  .. [3] Guo, Huifeng, et al. "DeepFM: A Factorization-Machine Based Neural Network for CTR
      Prediction." ArXiv.org, 13 Mar. 2017, arxiv.org/abs/1703.04247.
class_docstr_tok: ["Training","pipeline","for","a","deep","factorization","model",".","``","DeepFM","``","models","combine","a","shallow","factorization","machine","and","a","deep","multilayer","perceptron","network","in","a","single",",","unified","model",".","The","model","consists","of","embedding","tables","for","users","and","items",",","and","model","output","is","the","sum","of","1",")","factorization","machine","output","of","both","embeddings","(","shallow",")","and","2",")","MLP","output","for","the","concatenation","of","both","embeddings","(","deep",")",".","The","implementation","here","is","meant","to","mimic","its","original","implementation","as","specified","here",":","https",":","\/\/arxiv.org\/pdf\/1703.04247.pdf","[","3","]","_","All","``","DeepFM","``","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",",","DeepFM","model","=","DeepFM","(","train=train",")","trainer","=","CollieTrainer","(","model",")","trainer.fit","(","model",")","model.eval","(",")","#","do","evaluation","as","normal","with","``","model","``","model.save_model","(","filename='model.pth","'",")","new_model","=","DeepFM","(","load_model_path='model.pth","'",")","#","do","evaluation","as","normal","with","``","new_model","``","Parameters","--","--","--","--","--","embedding_dim",":","int","Number","of","latent","factors","to","use","for","the","matrix","factorization","embedding","table",".","For","the","MLP","embedding","table",",","the","dimensionality","will","be","calculated","with","the","formula","``","embedding_dim","*","(","2","*","*","(","num_layers","-","1",")",")","``","num_layers",":","int","Number","of","MLP","layers","to","apply",".","Each","MLP","layer","will","have","its","input","dimension","calculated","with","the","formula","``","embedding_dim","*","(","2","*","*","(","``","num_layers","``","-","``","current_layer_number","``",")",")","``","final_layer",":","str","or","function","Final","layer","activation","function",".","Available","string","options","include",":","*","'sigmoid'","*","'relu'","*","'leaky_relu'","dropout_p",":","float","Probability","of","dropout","sparse",":","bool","Whether","or","not","to","treat","embeddings","as","sparse","tensors",".","If","``","True","``",",","can","not","use","weight","decay","on","the","optimizer","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","``","References","--","--","--","--","--","..","[","3","]","Guo",",","Huifeng",",","et","al",".","``","DeepFM",":","A","Factorization-Machine","Based","Neural","Network","for","CTR","Prediction",".","''","ArXiv.org",",","13","Mar",".","2017",",","arxiv.org\/abs\/1703.04247","."]
code: def __init__(
      self,
      train: INTERACTIONS_LIKE_INPUT = None,
      val: INTERACTIONS_LIKE_INPUT = None,
      embedding_dim: int = 8,
      num_layers: int = 3,
      final_layer: Optional[Union[str, Callable[..., Any]]] = None,
      dropout_p: float = 0.0,
      lr: float = 1e-3,
      bias_lr: Optional[Union[float, str]] = 1e-2,
      lr_scheduler_func: Optional[
          torch.optim.lr_scheduler._LRScheduler
      ] = partial(ReduceLROnPlateau, patience=1, verbose=True),
      weight_decay: float = 0.0,
      optimizer: Union[str, torch.optim.Optimizer] = "adam",
      bias_optimizer: Optional[
          Union[str, torch.optim.Optimizer]
      ] = "sgd",
      loss: Union[str, Callable[..., torch.tensor]] = "hinge",
      metadata_for_loss: Optional[Dict[str, torch.tensor]] = None,
      metadata_for_loss_weights: Optional[Dict[str, float]] = None,
      # y_range: Optional[Tuple[float, float]] = None,
      load_model_path: Optional[str] = None,
      map_location: Optional[str] = None,
  ):
      super().__init__(**get_init_arguments())
  
file_path: collie/collie/model/deep_fm.py
imports: from functools import partial
  from typing import Any, Callable, Dict, Optional, 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, trunc_normal
label_desc: Use image node_id 1 to create a new DeepFM object from inherited base classes: BasePipeline with example: obj = DeepFM(train, val, embedding_dim, num_layers, final_layer, dropout_p, lr, bias_lr, lr_scheduler_func, weight_decay, optimizer, bias_optimizer, loss, metadata_for_loss, metadata_for_loss_weights, load_model_path, map_location)