class_docstr: A computationally more efficient ``DataLoader`` for ``Interactions`` data using approximate
  negative sampling for negative items.
  
  This DataLoader groups ``__getitem__`` calls together into a single operation, which
  dramatically speeds up a traditional DataLoader's process of calling ``__getitem__`` one index
  at a time, then concatenating them together before returning. In an effort to batch operations
  together, all negative samples returned will be approximate, meaning this does not check if a
  user has previously interacted with the item. With a sufficient number of interactions (1M+), we
  have found a speed increase of 2x at the cost of a 1% reduction in MAP @ 10 performance
  compared to ``InteractionsDataLoader``.
  
  For greater efficiency, we disable automated batching by setting the DataLoader's
  ``batch_size`` attribute to ``None``. Thus,
  to access the "true" batch size that the sampler uses, access
  ``ApproximateNegativeSamplingInteractionsDataLoader.approximate_negative_sampler.batch_size``.
  
  Parameters
  ----------
  interactions: Interactions
      If not provided, an ``Interactions`` object will be created with ``mat`` or all of
      ``users``, ``items``, and ``ratings`` with ``max_number_of_samples_to_consider=0``
  mat: scipy.sparse.coo_matrix or numpy.array, 2-dimensional
      If ``interactions is None``, will be used instead of ``users``, ``items``, and ``ratings``
      arguments to create an ``Interactions`` object
  users: Iterable[int], 1-d
      If ``interactions is None and mat is None``, array of user IDs, starting at 0
  items: Iterable[int], 1-d
      If ``interactions is None and mat is None``, array of corresponding item IDs to ``users``,
      starting at 0
  ratings: Iterable[int], 1-d
      If ``interactions is None and mat is None``, array of corresponding ratings to both
      ``users`` and ``items``. If ``None``, will default to each user in ``user`` interacting with
      an item with a rating value of 1
  batch_size: int
      Number of samples per batch to load
  shuffle: bool
      Whether to shuffle the order of data returned or not. This is especially useful for training
      data to ensure the model does not overfit to a specific order of data
  **kwargs: keyword arguments
      Relevant keyword arguments will be passed into ``Interactions`` object creation, if
      ``interactions is None`` and the keyword argument matches one of
      ``Interactions.__init__.__code__.co_varnames``. All other keyword arguments will be passed
      into ``torch.utils.data.DataLoader``:
      https://pytorch.org/docs/stable/data.html#torch.utils.data.DataLoader
  
  Attributes
  ----------
  interactions: Interactions
  
  Original ``torch.utils.data.DataLoader`` docstring as follows:
  ########
class_docstr_tok: ["A","computationally","more","efficient","``","DataLoader","``","for","``","Interactions","``","data","using","approximate","negative","sampling","for","negative","items",".","This","DataLoader","groups","``","__getitem__","``","calls","together","into","a","single","operation",",","which","dramatically","speeds","up","a","traditional","DataLoader","'s","process","of","calling","``","__getitem__","``","one","index","at","a","time",",","then","concatenating","them","together","before","returning",".","In","an","effort","to","batch","operations","together",",","all","negative","samples","returned","will","be","approximate",",","meaning","this","does","not","check","if","a","user","has","previously","interacted","with","the","item",".","With","a","sufficient","number","of","interactions","(","1M+",")",",","we","have","found","a","speed","increase","of","2x","at","the","cost","of","a","1","%","reduction","in","MAP","@","10","performance","compared","to","``","InteractionsDataLoader","``",".","For","greater","efficiency",",","we","disable","automated","batching","by","setting","the","DataLoader's","``","batch_size","``","attribute","to","``","None","``",".","Thus",",","to","access","the","``","true","''","batch","size","that","the","sampler","uses",",","access","``","ApproximateNegativeSamplingInteractionsDataLoader.approximate_negative_sampler.batch_size","``",".","Parameters","--","--","--","--","--","interactions",":","Interactions","If","not","provided",",","an","``","Interactions","``","object","will","be","created","with","``","mat","``","or","all","of","``","users","``",",","``","items","``",",","and","``","ratings","``","with","``","max_number_of_samples_to_consider=0","``","mat",":","scipy.sparse.coo_matrix","or","numpy.array",",","2-dimensional","If","``","interactions","is","None","``",",","will","be","used","instead","of","``","users","``",",","``","items","``",",","and","``","ratings","``","arguments","to","create","an","``","Interactions","``","object","users",":","Iterable","[","int","]",",","1-d","If","``","interactions","is","None","and","mat","is","None","``",",","array","of","user","IDs",",","starting","at","0","items",":","Iterable","[","int","]",",","1-d","If","``","interactions","is","None","and","mat","is","None","``",",","array","of","corresponding","item","IDs","to","``","users","``",",","starting","at","0","ratings",":","Iterable","[","int","]",",","1-d","If","``","interactions","is","None","and","mat","is","None","``",",","array","of","corresponding","ratings","to","both","``","users","``","and","``","items","``",".","If","``","None","``",",","will","default","to","each","user","in","``","user","``","interacting","with","an","item","with","a","rating","value","of","1","batch_size",":","int","Number","of","samples","per","batch","to","load","shuffle",":","bool","Whether","to","shuffle","the","order","of","data","returned","or","not",".","This","is","especially","useful","for","training","data","to","ensure","the","model","does","not","overfit","to","a","specific","order","of","data","*","*","kwargs",":","keyword","arguments","Relevant","keyword","arguments","will","be","passed","into","``","Interactions","``","object","creation",",","if","``","interactions","is","None","``","and","the","keyword","argument","matches","one","of","``","Interactions.__init__.__code__.co_varnames","``",".","All","other","keyword","arguments","will","be","passed","into","``","torch.utils.data.DataLoader","``",":","https",":","\/\/pytorch.org\/docs\/stable\/data.html","#","torch.utils.data.DataLoader","Attributes","--","--","--","--","--","interactions",":","Interactions","Original","``","torch.utils.data.DataLoader","``","docstring","as","follows",":","#","#","#","#","#","#","#","#"]
code: def __init__(
      self,
      interactions: Interactions = None,
      mat: Optional[Union[coo_matrix, np.array]] = None,
      users: Optional[Iterable[int]] = None,
      items: Optional[Iterable[int]] = None,
      ratings: Optional[Iterable[int]] = None,
      batch_size: int = 1024,
      shuffle: bool = False,
      **kwargs,
  ):
      if isinstance(interactions, ExplicitInteractions):
          raise ValueError(
              "``ApproximateNegativeSamplingInteractionsDataLoader`` does not support explicit"
              " data types!"
          )
  
      if interactions is None:
          interactions_only_kwargs = {
              k: v
              for k, v in kwargs.items()
              if k in Interactions.__init__.__code__.co_varnames
          }
          kwargs = {
              k: v
              for k, v in kwargs.items()
              if k not in Interactions.__init__.__code__.co_varnames
              or k
              in torch.utils.data.DataLoader.__init__.__code__.co_varnames
          }
  
          interactions = Interactions(
              mat=mat,
              users=users,
              items=items,
              ratings=ratings,
              max_number_of_samples_to_consider=0,
              **interactions_only_kwargs,
          )
      else:
          # we need ``max_number_of_samples_to_consider`` to be 0 in order to do approximate
          # negative sampling
          interactions.max_number_of_samples_to_consider = 0
  
      approximate_negative_sampler = ApproximateNegativeSampler(
          interactions=interactions,
          batch_size=batch_size,
          shuffle=shuffle,
          seed=interactions.seed,
      )
  
      super().__init__(
          interactions=interactions,
          sampler=approximate_negative_sampler,
          batch_size=None,  # Disable automated batching
          **kwargs,
      )
  
      self.approximate_negative_sampler = approximate_negative_sampler
      self.shuffle = shuffle
  
imports: import textwrap
  from typing import Iterable, Optional, Union
  import numpy
  from scipy.sparse import coo_matrix
  import torch
  from collie.interactions.datasets import BaseInteractions, ExplicitInteractions, HDF5Interactions, Interactions
  from collie.interactions.samplers import ApproximateNegativeSampler, HDF5Sampler
label_desc: Use image node_id 1 to create a new ApproximateNegativeSamplingInteractionsDataLoader object from inherited base classes: BaseInteractionsDataLoader with example: obj = ApproximateNegativeSamplingInteractionsDataLoader(interactions, mat, users, items, ratings, batch_size, shuffle)