class_docstr: Bucket-based partition strategy.
  
  This strategy first splits entities into :math:`k` buckets and creates:
  
  + `k` partitions where the `i`-th includes triples such that subject and object belong to the `i`-th partition.
  + :math:`\frac{(k^2-k)}{2}` partitions indexed by :math:`(i,j)` with :math:`i,j=1,...,k`, :math:`i \neq j` where
    the  :math:`(i,j)`-th partition contains triples such that the subject belongs to the :math:`i`-th partition
    and the object to the :math:`j`-th partition or viceversa.
  
  Example
  -------
  >>> from ampligraph.datasets import load_fb15k_237, GraphDataLoader, BucketGraphPartitioner
  >>> from ampligraph.datasets.sqlite_adapter import SQLiteAdapter
  >>> from ampligraph.latent_features import ScoringBasedEmbeddingModel
  >>> dataset = load_fb15k_237()
  >>> dataset_loader = GraphDataLoader(dataset['train'],
  >>>                                  backend=SQLiteAdapter, # Type of backend to use
  >>>                                  batch_size=1000,       # Batch size to use while iterating over the dataset
  >>>                                  dataset_type='train',  # Dataset type
  >>>                                  use_filter=False,      # Whether to use filter or not
  >>>                                  use_indexer=True)      # indicates that the data needs to be mapped to index
  >>> partitioner = BucketGraphPartitioner(dataset_loader, k=2)
  >>> # create and compile a model as usual
  >>> partitioned_model = ScoringBasedEmbeddingModel(eta=2, k=50, scoring_type='DistMult')
  >>> partitioned_model.compile(optimizer='adam', loss='multiclass_nll')
  >>> partitioned_model.fit(partitioner,       # The partitioner object generate data for the model during training
  >>>                       epochs=10)         # Number of epochs
  
  Example
  -------
  >>> import numpy as np
  >>> from ampligraph.datasets import GraphDataLoader, BucketGraphPartitioner
  >>> d = np.array([[1,1,2], [1,1,3],[1,1,4],[5,1,3],[5,1,2],[6,1,3],[6,1,2],[6,1,4],[6,1,7]])
  >>> data = GraphDataLoader(d, batch_size=1, dataset_type="test")
  >>> partitioner = BucketGraphPartitioner(data, k=2)
  >>> for i, partition in enumerate(partitioner):
  >>>    print("partition ", i)
  >>>    for batch in partition:
  >>>        print(batch)
  partition  0
  [['0,0,1']]
  [['0,0,2']]
  [['0,0,3']]
  partition  1
  [['4,0,1']]
  [['4,0,2']]
  [['5,0,1']]
  [['5,0,2']]
  [['5,0,3']]
  partition  2
  [['5,0,6']]
class_docstr_tok: ["Bucket-based","partition","strategy",".","This","strategy","first","splits","entities","into",":","math",":","`","k","`","buckets","and","creates",":","+","`","k","`","partitions","where","the","`","i","`","-th","includes","triples","such","that","subject","and","object","belong","to","the","`","i","`","-th","partition",".","+",":","math",":","`","\\frac","{","(","k^2-k",")","}","{","2","}","`","partitions","indexed","by",":","math",":","`","(","i",",","j",")","`","with",":","math",":","`","i",",","j=1",",","...",",","k","`",",",":","math",":","`","i","\\neq","j","`","where","the",":","math",":","`","(","i",",","j",")","`","-th","partition","contains","triples","such","that","the","subject","belongs","to","the",":","math",":","`","i","`","-th","partition","and","the","object","to","the",":","math",":","`","j","`","-th","partition","or","viceversa",".","Example","--","--","--","-",">",">",">","from","ampligraph.datasets","import","load_fb15k_237",",","GraphDataLoader",",","BucketGraphPartitioner",">",">",">","from","ampligraph.datasets.sqlite_adapter","import","SQLiteAdapter",">",">",">","from","ampligraph.latent_features","import","ScoringBasedEmbeddingModel",">",">",">","dataset","=","load_fb15k_237","(",")",">",">",">","dataset_loader","=","GraphDataLoader","(","dataset","[","'train","'","]",",",">",">",">","backend=SQLiteAdapter",",","#","Type","of","backend","to","use",">",">",">","batch_size=1000",",","#","Batch","size","to","use","while","iterating","over","the","dataset",">",">",">","dataset_type='train","'",",","#","Dataset","type",">",">",">","use_filter=False",",","#","Whether","to","use","filter","or","not",">",">",">","use_indexer=True",")","#","indicates","that","the","data","needs","to","be","mapped","to","index",">",">",">","partitioner","=","BucketGraphPartitioner","(","dataset_loader",",","k=2",")",">",">",">","#","create","and","compile","a","model","as","usual",">",">",">","partitioned_model","=","ScoringBasedEmbeddingModel","(","eta=2",",","k=50",",","scoring_type='DistMult","'",")",">",">",">","partitioned_model.compile","(","optimizer='adam","'",",","loss='multiclass_nll","'",")",">",">",">","partitioned_model.fit","(","partitioner",",","#","The","partitioner","object","generate","data","for","the","model","during","training",">",">",">","epochs=10",")","#","Number","of","epochs","Example","--","--","--","-",">",">",">","import","numpy","as","np",">",">",">","from","ampligraph.datasets","import","GraphDataLoader",",","BucketGraphPartitioner",">",">",">","d","=","np.array","(","[","[","1,1,2","]",",","[","1,1,3","]",",","[","1,1,4","]",",","[","5,1,3","]",",","[","5,1,2","]",",","[","6,1,3","]",",","[","6,1,2","]",",","[","6,1,4","]",",","[","6,1,7","]","]",")",">",">",">","data","=","GraphDataLoader","(","d",",","batch_size=1",",","dataset_type=","''","test","''",")",">",">",">","partitioner","=","BucketGraphPartitioner","(","data",",","k=2",")",">",">",">","for","i",",","partition","in","enumerate","(","partitioner",")",":",">",">",">","print","(","``","partition","``",",","i",")",">",">",">","for","batch","in","partition",":",">",">",">","print","(","batch",")","partition","0","[","[","'","0,0,1","'","]","]","[","[","'","0,0,2","'","]","]","[","[","'","0,0,3","'","]","]","partition","1","[","[","'","4,0,1","'","]","]","[","[","'","4,0,2","'","]","]","[","[","'","5,0,1","'","]","]","[","[","'","5,0,2","'","]","]","[","[","'","5,0,3","'","]","]","partition","2","[","[","'","5,0,6","'","]","]"]
docstr: Split data into `self.k` buckets based on unique entities and assign
  accordingly triples to `k` partitions and intermediate partitions.
docstr_tok: ["Split","data","into","`","self.k","`","buckets","based","on","unique","entities","and","assign","accordingly","triples","to","`","k","`","partitions","and","intermediate","partitions","."]
code: def _split(self, seed=None, verbose=False, batch_size=1, **kwargs):
      """Split data into `self.k` buckets based on unique entities and assign
      accordingly triples to `k` partitions and intermediate partitions.
  
      """
      timestamp = datetime.now().strftime("%d-%m-%Y_%I-%M-%S_%p")
      self.ents_size = self._data.backend.mapper.get_entities_count()
      logger.debug(self.ents_size)
      self.bucket_size = int(np.ceil(self.ents_size / self._k))
      self.buckets_generator = (
          self._data.backend.mapper.get_entities_in_batches(
              batch_size=self.bucket_size
          )
      )
  
      for i, bucket in enumerate(self.buckets_generator):
          # dump entities in partition shelve/file
          fname = "bucket_{}_{}.shf".format(i, timestamp)
          fname = os.path.join(self.root_dir, fname)
          self.files.append(fname)
          with shelve.open(fname, writeback=True) as bucket_partition:
              bucket_partition["indexes"] = bucket
          # logger.debug(bucket)
  
      partition_nb = 0
      # ensure that the "same" bucket partitions are generated first
      for i in range(self._k):
          # condition that excludes duplicated partitions
          # from k x k possibilities, partition 0-1 and 1-0 is the same - not
          # needed
          status_not_ok = self.create_single_partition(
              i, i, timestamp, partition_nb, batch_size=batch_size
          )
          if status_not_ok:
              continue
          partition_nb += 1
  
      # Now generate across bucket partitions
      for i in range(self._k):
          for j in range(self._k):
              if j > i:
                  # condition that excludes duplicated partitions
                  # from k x k possibilities, partition 0-1 and 1-0 are the
                  # same - not needed
                  status_not_ok = self.create_single_partition(
                      i,
                      j,
                      timestamp,
                      partition_nb,
                      batch_size=batch_size,
                  )
                  if status_not_ok:
                      continue
                  partition_nb += 1
  
imports: import logging
  import os
  import shelve
  import tempfile
  from abc import ABC
  from datetime import datetime
  import numpy
  from ampligraph.utils.profiling import timing_and_memory
  from .graph_data_loader import GraphDataLoader
label_desc: Use image node_id 3 for calling the BucketGraphPartitioner obj's underlying member method code with example usage: obj._split(seed, verbose, batch_size) without return types