(self)
Takes Examples out of example queue, sorts them by encoder sequence length, processes into Batches and places them in the batch queue.

    In decode mode, makes batches that each contain a single example repeated.
Takes Examples out of example queue, sorts them by encoder sequence length, processes into Batches and places them in the batch queue.
Takes Examples out of example queue sorts them by encoder sequence length processes into Batches and places them in the batch queue .
def fill_batch_queue(self):
    """Takes Examples out of example queue, sorts them by encoder sequence length, processes into Batches and places them in the batch queue.

    In decode mode, makes batches that each contain a single example repeated.
    """
    while True:
      if self._hps.mode != 'decode':
        # Get bucketing_cache_size-many batches of Examples into a list, then sort
        inputs = []
        for _ in xrange(self._hps.batch_size * self._bucketing_cache_size):
          inputs.append(self._example_queue.get())
        inputs = sorted(inputs, key=lambda inp: inp.enc_len) # sort by length of encoder sequence

        # Group the sorted Examples into batches, optionally shuffle the batches, and place in the batch queue.
        batches = []
        for i in xrange(0, len(inputs), self._hps.batch_size):
          batches.append(inputs[i:i + self._hps.batch_size])
        if not self._single_pass:
          shuffle(batches)
        for b in batches:  # each b is a list of Example objects
          self._batch_queue.put(Batch(b, self._hps, self._vocab))

      else: # beam search decode mode
        ex = self._example_queue.get()
        b = [ex for _ in xrange(self._hps.batch_size)]
        self._batch_queue.put(Batch(b, self._hps, self._vocab))
def fill_batch_queue ( self ) : while True : if self . _hps . mode != 'decode' : # Get bucketing_cache_size-many batches of Examples into a list, then sort inputs = [ ] for _ in xrange ( self . _hps . batch_size * self . _bucketing_cache_size ) : inputs . append ( self . _example_queue . get ( ) ) inputs = sorted ( inputs , key = lambda inp : inp . enc_len ) # sort by length of encoder sequence # Group the sorted Examples into batches, optionally shuffle the batches, and place in the batch queue. batches = [ ] for i in xrange ( 0 , len ( inputs ) , self . _hps . batch_size ) : batches . append ( inputs [ i : i + self . _hps . batch_size ] ) if not self . _single_pass : shuffle ( batches ) for b in batches : # each b is a list of Example objects self . _batch_queue . put ( Batch ( b , self . _hps , self . _vocab ) ) else : # beam search decode mode ex = self . _example_queue . get ( ) b = [ ex for _ in xrange ( self . _hps . batch_size ) ] self . _batch_queue . put ( Batch ( b , self . _hps , self . _vocab ) )