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: User counterpart to ``get_item_predictions`` method.
  
  Get predicted rankings/ratings for all users for a given ``item_id``.
  
  This method cannot be called for datasets stored in ``HDF5InteractionsDataLoader`` since
  data in this ``DataLoader`` is read in dynamically.
  
  Parameters
  ----------
  item_id: int
  unseen_users_only: bool
      Filter ``preds`` to only show predictions of unseen users not present in the training
      or validation datasets for that ``item_id``. Note this requires both ``train_loader``
      and ``val_loader`` to be 1) class-level attributes in the model and 2) DataLoaders with
      ``Interactions`` at its core (not ``HDF5Interactions``). If you are loading in a model,
      these two attributes will need to be set manually, since datasets are NOT saved when
      saving the model
  sort_values: bool
      Whether to sort recommendations by descending prediction probability
  
  Returns
  -------
  preds: pd.Series
      Sorted values as predicted ratings for each user in the dataset with the index being
      the user ID
docstr_tok: ["User","counterpart","to","``","get_item_predictions","``","method",".","Get","predicted","rankings\/ratings","for","all","users","for","a","given","``","item_id","``",".","This","method","can","not","be","called","for","datasets","stored","in","``","HDF5InteractionsDataLoader","``","since","data","in","this","``","DataLoader","``","is","read","in","dynamically",".","Parameters","--","--","--","--","--","item_id",":","int","unseen_users_only",":","bool","Filter","``","preds","``","to","only","show","predictions","of","unseen","users","not","present","in","the","training","or","validation","datasets","for","that","``","item_id","``",".","Note","this","requires","both","``","train_loader","``","and","``","val_loader","``","to","be","1",")","class-level","attributes","in","the","model","and","2",")","DataLoaders","with","``","Interactions","``","at","its","core","(","not","``","HDF5Interactions","``",")",".","If","you","are","loading","in","a","model",",","these","two","attributes","will","need","to","be","set","manually",",","since","datasets","are","NOT","saved","when","saving","the","model","sort_values",":","bool","Whether","to","sort","recommendations","by","descending","prediction","probability","Returns","--","--","--","-","preds",":","pd.Series","Sorted","values","as","predicted","ratings","for","each","user","in","the","dataset","with","the","index","being","the","user","ID"]
code: def get_user_predictions(
      self,
      item_id: int = 0,
      unseen_users_only: bool = False,
      sort_values: bool = True,
  ) -> pd.Series:
      """
      User counterpart to ``get_item_predictions`` method.
  
      Get predicted rankings/ratings for all users for a given ``item_id``.
  
      This method cannot be called for datasets stored in ``HDF5InteractionsDataLoader`` since
      data in this ``DataLoader`` is read in dynamically.
  
      Parameters
      ----------
      item_id: int
      unseen_users_only: bool
          Filter ``preds`` to only show predictions of unseen users not present in the training
          or validation datasets for that ``item_id``. Note this requires both ``train_loader``
          and ``val_loader`` to be 1) class-level attributes in the model and 2) DataLoaders with
          ``Interactions`` at its core (not ``HDF5Interactions``). If you are loading in a model,
          these two attributes will need to be set manually, since datasets are NOT saved when
          saving the model
      sort_values: bool
          Whether to sort recommendations by descending prediction probability
  
      Returns
      -------
      preds: pd.Series
          Sorted values as predicted ratings for each user in the dataset with the index being
          the user ID
      """
      if item_id >= self.hparams.num_items:
          raise ValueError(
              f"``item_id`` {item_id} is not in the model. "
              "Expected ID between ``0`` and ``self.hparams.num_items - 1`` "
              f"(``{self.hparams.num_items - 1}``), not ``{item_id}``"
          )
  
      item = torch.tensor(
          [item_id] * self.hparams.num_users,
          dtype=torch.long,
          device=self.device,
      )
      user = torch.arange(
          self.hparams.num_users, dtype=torch.long, device=self.device
      )
  
      preds = self(user, item)
      preds = preds.detach().cpu()
      preds = pd.Series(preds)
      if sort_values:
          preds = preds.sort_values(ascending=False)
  
      if unseen_users_only:
          if self.val_loader is not None:
              idxs_to_drop = np.concatenate(
                  [
                      self.train_loader.mat.tocsr()[
                          :, item_id
                      ].nonzero()[1],
                      self.val_loader.mat.tocsr()[:, item_id].nonzero()[
                          1
                      ],
                  ]
              )
          else:
              idxs_to_drop = self.train_loader.mat.tocsr()[
                  :, item_id
              ].nonzero()[1]
          filtered_preds = preds.drop(idxs_to_drop)
  
          return filtered_preds
      else:
          return preds
  
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 19 for calling the BasePipeline obj's underlying member method code with example usage: obj.get_user_predictions(item_id, unseen_users_only, sort_values) and returns: filtered_preds, preds