def generate_batches(self, recurrent_net, batch_size, max_seqs=-1, seq_drop=0.0, max_seq_length=sys.maxsize, shuffle_batches=False, used_data_keys=None): """ :type recurrent_net: bool :type batch_size: int :type max_seqs: int :type shuffle_batches: bool :param set(str)|None used_data_keys: :rtype: BatchSetGenerator """ return BatchSetGenerator( dataset=self, generator=self._generate_batches(recurrent_net=recurrent_net, batch_size=batch_size, max_seqs=max_seqs, seq_drop=seq_drop, max_seq_length=max_seq_length, used_data_keys=used_data_keys), shuffle_batches=shuffle_batches, cache_whole_epoch=self.batch_set_generator_cache_whole_epoch())
def generate_batches(self, shuffle_batches=False, **kwargs): """ :param bool shuffle_batches: :param kwargs: will be passed to :func:`_generate_batches` :rtype: BatchSetGenerator """ return BatchSetGenerator( dataset=self, generator=self._generate_batches(**kwargs), shuffle_batches=shuffle_batches, cache_whole_epoch=self.batch_set_generator_cache_whole_epoch())
def forward_single(self, dataset, seq_idx, output_layer_name=None): """ Forwards a single sequence. If you want to perform search, and get a number of hyps out, use :func:`search_single`. :param Dataset.Dataset dataset: :param int seq_idx: :param str|None output_layer_name: e.g. "output". if not set, will read from config "forward_output_layer" :return: numpy array, output in time major format (time,dim) :rtype: numpy.ndarray """ from EngineBatch import Batch, BatchSetGenerator batch = Batch() batch.init_with_one_full_sequence(seq_idx=seq_idx, dataset=dataset) batch_generator = iter([batch]) batches = BatchSetGenerator(dataset, generator=batch_generator) forwarder = ClassificationTaskThread(self.network, self.devices, dataset, batches) forwarder.join() assert forwarder.output.shape[1] == 1 return forwarder.output[:, 0]