class_docstr: Base Pipeline model architectures to inherit from.
  
  All subclasses MUST at least override the following methods:
  
  * ``_setup_model`` - Set up the model architecture
  
  * ``forward`` - Forward pass through a model
  
  For ``item_item_similarity`` to work properly, all subclasses are should also implement:
  
  * ``_get_item_embeddings`` - Returns item embeddings from the model on the device
  
  For ``user_user_similarity`` to work properly, all subclasses are should also implement:
  
  * ``_get_user_embeddings`` - Returns user embeddings from the model on the device
  
  Parameters
  ----------
  train: ``collie.interactions`` object
      Data loader for training data. If an ``Interactions`` object is supplied, an
      ``InteractionsDataLoader`` will automatically be instantiated with ``shuffle=True``
  val: ``collie.interactions`` object
      Data loader for validation data. If an ``Interactions`` object is supplied, an
      ``InteractionsDataLoader`` will automatically be instantiated with ``shuffle=False``
  lr: float
      Model learning rate
  lr_scheduler_func: torch.optim.lr_scheduler
      Learning rate scheduler to use during fitting
  weight_decay: float
      Weight decay passed to the optimizer, if optimizer permits
  optimizer: torch.optim or str
      If a string, one of the following supported optimizers:
  
      * ``'sgd'`` (for ``torch.optim.SGD``)
  
      * ``'adagrad'`` (for ``torch.optim.Adagrad``)
  
      * ``'adam'`` (for ``torch.optim.Adam``)
  
      * ``'sparse_adam'`` (for ``torch.optim.SparseAdam``)
  
  loss: function or str
      If a string, one of the following implemented losses:
  
      * ``'bpr'`` / ``'adaptive_bpr'`` (implicit data)
  
      * ``'hinge'`` / ``'adaptive_hinge'`` (implicit data)
  
      * ``'warp'`` (implicit data)
  
      * ``'mse'`` (explicit data)
  
      * ``'mae'`` (explicit data)
  
      For implicit data, if ``train.num_negative_samples > 1``, the adaptive loss version will
      automatically be used of the losses above (except for WARP loss, which is only adaptive by
      nature).
  
      If a callable is passed, that function will be used for calculating the loss. For implicit
      models, the first two arguments passed will be the positive and negative predictions,
      respectively. Additional keyword arguments passed in order are ``num_items``,
      ``positive_items``, ``negative_items``, ``metadata``, and ``metadata_weights``.
      For explicit models, the only two arguments passed in will be the prediction and actual
      rating values, in order.
  metadata_for_loss: dict
      Keys should be strings identifying each metadata type that match keys in
      ``metadata_weights``. Values should be a ``torch.tensor`` of shape (num_items x 1). Each
      tensor should contain categorical metadata information about items (e.g. a number
      representing the genre of the item)
  metadata_for_loss_weights: dict
      Keys should be strings identifying each metadata type that match keys in ``metadata``.
      Values should be the amount of weight to place on a match of that type of metadata, with
      the sum of all values ``<= 1``.
      e.g. If ``metadata_for_loss_weights = {'genre': .3, 'director': .2}``, then an item is:
  
      * a 100% match if it's the same item,
  
      * a 50% match if it's a different item with the same genre and same director,
  
      * a 30% match if it's a different item with the same genre and different director,
  
      * a 20% match if it's a different item with a different genre and same director,
  
      * a 0% match if it's a different item with a different genre and different director,
        which is equivalent to the loss without any partial credit
  load_model_path: str or Path
      To load a previously-saved model for inference, pass in path to output of
      ``model.save_model()`` method. Note that datasets and optimizers will NOT be restored.
      If ``None``, will initialize model as normal
  map_location: str or torch.device
      If ``load_model_path`` is provided, device specifying how to remap storage locations when
      ``torch.load``-ing the state dictionary
  **kwargs: keyword arguments
      All keyword arguments will be saved to ``self.hparams`` by default
class_docstr_tok: ["Base","Pipeline","model","architectures","to","inherit","from",".","All","subclasses","MUST","at","least","override","the","following","methods",":","*","``","_setup_model","``","-","Set","up","the","model","architecture","*","``","forward","``","-","Forward","pass","through","a","model","For","``","item_item_similarity","``","to","work","properly",",","all","subclasses","are","should","also","implement",":","*","``","_get_item_embeddings","``","-","Returns","item","embeddings","from","the","model","on","the","device","For","``","user_user_similarity","``","to","work","properly",",","all","subclasses","are","should","also","implement",":","*","``","_get_user_embeddings","``","-","Returns","user","embeddings","from","the","model","on","the","device","Parameters","--","--","--","--","--","train",":","``","collie.interactions","``","object","Data","loader","for","training","data",".","If","an","``","Interactions","``","object","is","supplied",",","an","``","InteractionsDataLoader","``","will","automatically","be","instantiated","with","``","shuffle=True","``","val",":","``","collie.interactions","``","object","Data","loader","for","validation","data",".","If","an","``","Interactions","``","object","is","supplied",",","an","``","InteractionsDataLoader","``","will","automatically","be","instantiated","with","``","shuffle=False","``","lr",":","float","Model","learning","rate","lr_scheduler_func",":","torch.optim.lr_scheduler","Learning","rate","scheduler","to","use","during","fitting","weight_decay",":","float","Weight","decay","passed","to","the","optimizer",",","if","optimizer","permits","optimizer",":","torch.optim","or","str","If","a","string",",","one","of","the","following","supported","optimizers",":","*","``","'sgd","'","``","(","for","``","torch.optim.SGD","``",")","*","``","'adagrad","'","``","(","for","``","torch.optim.Adagrad","``",")","*","``","'adam","'","``","(","for","``","torch.optim.Adam","``",")","*","``","'sparse_adam","'","``","(","for","``","torch.optim.SparseAdam","``",")","loss",":","function","or","str","If","a","string",",","one","of","the","following","implemented","losses",":","*","``","'bpr","'","``","\/","``","'adaptive_bpr","'","``","(","implicit","data",")","*","``","'hinge","'","``","\/","``","'adaptive_hinge","'","``","(","implicit","data",")","*","``","'warp","'","``","(","implicit","data",")","*","``","'mse","'","``","(","explicit","data",")","*","``","'mae","'","``","(","explicit","data",")","For","implicit","data",",","if","``","train.num_negative_samples",">","1","``",",","the","adaptive","loss","version","will","automatically","be","used","of","the","losses","above","(","except","for","WARP","loss",",","which","is","only","adaptive","by","nature",")",".","If","a","callable","is","passed",",","that","function","will","be","used","for","calculating","the","loss",".","For","implicit","models",",","the","first","two","arguments","passed","will","be","the","positive","and","negative","predictions",",","respectively",".","Additional","keyword","arguments","passed","in","order","are","``","num_items","``",",","``","positive_items","``",",","``","negative_items","``",",","``","metadata","``",",","and","``","metadata_weights","``",".","For","explicit","models",",","the","only","two","arguments","passed","in","will","be","the","prediction","and","actual","rating","values",",","in","order",".","metadata_for_loss",":","dict","Keys","should","be","strings","identifying","each","metadata","type","that","match","keys","in","``","metadata_weights","``",".","Values","should","be","a","``","torch.tensor","``","of","shape","(","num_items","x","1",")",".","Each","tensor","should","contain","categorical","metadata","information","about","items","(","e.g",".","a","number","representing","the","genre","of","the","item",")","metadata_for_loss_weights",":","dict","Keys","should","be","strings","identifying","each","metadata","type","that","match","keys","in","``","metadata","``",".","Values","should","be","the","amount","of","weight","to","place","on","a","match","of","that","type","of","metadata",",","with","the","sum","of","all","values","``","<","=","1","``",".","e.g",".","If","``","metadata_for_loss_weights","=","{","'genre","'",":",".3",",","'director","'",":",".2","}","``",",","then","an","item","is",":","*","a","100","%","match","if","it","'s","the","same","item",",","*","a","50","%","match","if","it","'s","a","different","item","with","the","same","genre","and","same","director",",","*","a","30","%","match","if","it","'s","a","different","item","with","the","same","genre","and","different","director",",","*","a","20","%","match","if","it","'s","a","different","item","with","a","different","genre","and","same","director",",","*","a","0","%","match","if","it","'s","a","different","item","with","a","different","genre","and","different","director",",","which","is","equivalent","to","the","loss","without","any","partial","credit","load_model_path",":","str","or","Path","To","load","a","previously-saved","model","for","inference",",","pass","in","path","to","output","of","``","model.save_model","(",")","``","method",".","Note","that","datasets","and","optimizers","will","NOT","be","restored",".","If","``","None","``",",","will","initialize","model","as","normal","map_location",":","str","or","torch.device","If","``","load_model_path","``","is","provided",",","device","specifying","how","to","remap","storage","locations","when","``","torch.load","``","-ing","the","state","dictionary","*","*","kwargs",":","keyword","arguments","All","keyword","arguments","will","be","saved","to","``","self.hparams","``","by","default"]
docstr: Method that contains logic for what happens inside the training loop.
  
  This method will be called after ``train_dataloader``.
docstr_tok: ["Method","that","contains","logic","for","what","happens","inside","the","training","loop",".","This","method","will","be","called","after","``","train_dataloader","``","."]
code: def training_step(
      self,
      batch: Tuple[Tuple[torch.tensor, torch.tensor], torch.tensor],
      batch_idx: int,
      optimizer_idx: Optional[int] = None,
  ) -> torch.tensor:
      """
      Method that contains logic for what happens inside the training loop.
  
      This method will be called after ``train_dataloader``.
  
      """
      loss = self.calculate_loss(batch)
  
      # add logging
      self.log(name="train_loss_step", value=loss)
  
      return loss
  
imports: from abc import ABCMeta, abstractmethod
  from collections.abc import Iterable
  from pathlib import Path
  import textwrap
  from typing import Callable, Dict, List, Optional, Tuple, Union
  import warnings
  import numpy
  import pandas
  from pytorch_lightning import LightningModule
  import torch
  from collie.interactions import ApproximateNegativeSamplingInteractionsDataLoader, ExplicitInteractions, Interactions, InteractionsDataLoader
  from collie.loss import adaptive_bpr_loss, adaptive_hinge_loss, bpr_loss, hinge_loss, warp_loss
  from collie.utils import get_init_arguments
label_desc: Use image node_id 12 for calling the BasePipeline obj's underlying member method code with example usage: obj.training_step(batch, batch_idx, optimizer_idx) and returns: loss