original_docstring: 
          Build a mini-batch by randomly picking a number of distinct classes ('width') from the training batch.
          This ensures we ended up with a balanced class distribution in each mini-batch
          :param batch_size: number of observations in the current mini-batch. Yann recommends 32, https://arxiv.org/abs/1804.07612
          :param width: number of distinct classes in the current minibatch
          :return: x, y, and sequence length minibatches
          
docstring: Build a mini-batch by randomly picking a number of distinct classes ('width') from the training batch.
  This ensures we ended up with a balanced class distribution in each mini-batch
docstring_tokens: Build a mini - batch by randomly picking a number of distinct classes ( ' width ' ) from the training batch . This ensures we ended up with a balanced class distribution in each mini - batch
code: def next_train_balanced(self, batch_size=32):
          '''
          Build a mini-batch by randomly picking a number of distinct classes ('width') from the training batch.
          This ensures we ended up with a balanced class distribution in each mini-batch
          :param batch_size: number of observations in the current mini-batch. Yann recommends 32, https://arxiv.org/abs/1804.07612
          :param width: number of distinct classes in the current minibatch
          :return: x, y, and sequence length minibatches
          '''
          assert len(self.idx_train) > batch_size
          #class ids are unique elements
          class_ids = np.unique(self.labels)
  
          #class_support: number of elements per class
          class_support = batch_size//len(class_ids)
          idx_train_batch = [np.random.choice(self.trainid_per_labelid[labelid], class_support) for labelid in class_ids]
  
          idx_train_batch = np.array(idx_train_batch).ravel().tolist()
          remaind_len = batch_size - len(idx_train_batch)
  
          idx_remaind_batch = []
          class_ids_remain = np.random.choice(self.labels, remaind_len)
          for class_id in class_ids_remain:
              idx_train_batch.append(np.random.choice(self.trainid_per_labelid[class_id], 1)[0])
  
          np.random.shuffle(idx_train_batch)
          x_batch = self.word_inputs[idx_train_batch]
          y_batch = self.labels[idx_train_batch].ravel()
          batch_seqlen = self.seq_lengths[idx_train_batch]
  
          return x_batch, y_batch, batch_seqlen
code_tokens: def next_train_balanced ( self , batch_size = 32 ) : assert len ( self . idx_train ) > batch_size class_ids = np . unique ( self . labels ) class_support = batch_size // len ( class_ids ) idx_train_batch = [ np . random . choice ( self . trainid_per_labelid [ labelid ] , class_support ) for labelid in class_ids ] idx_train_batch = np . array ( idx_train_batch ) . ravel ( ) . tolist ( ) remaind_len = batch_size - len ( idx_train_batch ) idx_remaind_batch = [ ] class_ids_remain = np . random . choice ( self . labels , remaind_len ) for class_id in class_ids_remain : idx_train_batch . append ( np . random . choice ( self . trainid_per_labelid [ class_id ] , 1 ) [ 0 ] ) np . random . shuffle ( idx_train_batch ) x_batch = self . word_inputs [ idx_train_batch ] y_batch = self . labels [ idx_train_batch ] . ravel ( ) batch_seqlen = self . seq_lengths [ idx_train_batch ] return x_batch , y_batch , batch_seqlen
short_docstring: Build a mini-batch by randomly picking a number of distinct classes ('width') from the training batch.
short_docstring_tokens: Build a mini - batch by randomly picking a number of distinct classes ( ' width ' ) from the training batch .
comment: '''
          Build a mini-batch by randomly picking a number of distinct classes ('width') from the training batch.
          This ensures we ended up with a balanced class distribution in each mini-batch
          :param batch_size: number of observations in the current mini-batch. Yann recommends 32, https://arxiv.org/abs/1804.07612
          :param width: number of distinct classes in the current minibatch
          :return: x, y, and sequence length minibatches
          '''$SEP$#class ids are unique elements$SEP$#class_support: number of elements per class