class_docstr: Pre-batched training instances for the sLCWA training loop.
  
  .. note ::
      this class is intended to be used with automatic batching disabled, i.e., both parameters `batch_size` and
      `batch_sampler` of torch.utils.data.DataLoader` are set to `None`.
class_docstr_tok: ["Pre-batched","training","instances","for","the","sLCWA","training","loop",".","..","note",":",":","this","class","is","intended","to","be","used","with","automatic","batching","disabled",",","i.e.",",","both","parameters","`","batch_size","`","and","`","batch_sampler","`","of","torch.utils.data.DataLoader","`","are","set","to","`","None","`","."]
docstr: Initialize the dataset.
  
  :param mapped_triples: shape: (num_triples, 3)
      the mapped triples
  :param batch_size:
      the batch size
  :param drop_last:
      whether to drop the last (incomplete) batch
  :param num_entities: >0
      the number of entities, passed to the negative sampler
  :param num_relations: >0
      the number of relations, passed to the negative sampler
  :param negative_sampler:
      the negative sampler, or a hint thereof
  :param negative_sampler_kwargs:
      additional keyword-based parameters used to instantiate the negative sampler
docstr_tok: ["Initialize","the","dataset",".",":","param","mapped_triples",":","shape",":","(","num_triples",",","3",")","the","mapped","triples",":","param","batch_size",":","the","batch","size",":","param","drop_last",":","whether","to","drop","the","last","(","incomplete",")","batch",":","param","num_entities",":",">","0","the","number","of","entities",",","passed","to","the","negative","sampler",":","param","num_relations",":",">","0","the","number","of","relations",",","passed","to","the","negative","sampler",":","param","negative_sampler",":","the","negative","sampler",",","or","a","hint","thereof",":","param","negative_sampler_kwargs",":","additional","keyword-based","parameters","used","to","instantiate","the","negative","sampler"]
code: def __init__(
      self,
      mapped_triples: MappedTriples,
      batch_size: int = 1,
      drop_last: bool = True,
      num_entities: Optional[int] = None,
      num_relations: Optional[int] = None,
      negative_sampler: HintOrType[NegativeSampler] = None,
      negative_sampler_kwargs: OptionalKwargs = None,
  ):
      """
      Initialize the dataset.
  
      :param mapped_triples: shape: (num_triples, 3)
          the mapped triples
      :param batch_size:
          the batch size
      :param drop_last:
          whether to drop the last (incomplete) batch
      :param num_entities: >0
          the number of entities, passed to the negative sampler
      :param num_relations: >0
          the number of relations, passed to the negative sampler
      :param negative_sampler:
          the negative sampler, or a hint thereof
      :param negative_sampler_kwargs:
          additional keyword-based parameters used to instantiate the negative sampler
      """
      self.mapped_triples = mapped_triples
      self.batch_size = batch_size
      self.drop_last = drop_last
      self.negative_sampler = negative_sampler_resolver.make(
          negative_sampler,
          pos_kwargs=negative_sampler_kwargs,
          mapped_triples=self.mapped_triples,
          num_entities=num_entities,
          num_relations=num_relations,
      )
  
imports: import math
  from abc import ABC, abstractmethod
  from typing import Callable, Generic, Iterable, Iterator, List, NamedTuple, Optional, Tuple, TypeVar
  import numpy
  import scipy.sparse
  import torch
  from class_resolver import HintOrType, OptionalKwargs
  from torch.utils import data
  from .utils import compute_compressed_adjacency_list
  from ..sampling import NegativeSampler, negative_sampler_resolver
  from ..typing import MappedTriples
label_desc: Use image node_id 1 to create a new BaseBatchedSLCWAInstances object from inherited base classes: data.IterableDataset with example: obj = BaseBatchedSLCWAInstances(mapped_triples, batch_size, drop_last, num_entities, num_relations, negative_sampler, negative_sampler_kwargs)