def seq_minibatches(inputs, targets, batch_size, seq_length, stride=1):
 assert (len(inputs) == len(targets))
 n_loads = ((batch_size * stride) + (seq_length - stride))
 for start_idx in range(0, ((len(inputs) - n_loads) + 1), (batch_size * stride)):
  seq_inputs = np.zeros(((batch_size, seq_length) + inputs.shape[1:]), dtype=inputs.dtype)
  seq_targets = np.zeros(((batch_size, seq_length) + targets.shape[1:]), dtype=targets.dtype)
  for b_idx in xrange(batch_size):
   start_seq_idx = (start_idx + (b_idx * stride))
   end_seq_idx = (start_seq_idx + seq_length)
   seq_inputs[b_idx] = inputs[start_seq_idx:end_seq_idx]
   seq_targets[b_idx] = targets[start_seq_idx:end_seq_idx]
  flatten_inputs = seq_inputs.reshape((((-1),) + inputs.shape[1:]))
  flatten_targets = seq_targets.reshape((((-1),) + targets.shape[1:]))
  (yield (flatten_inputs, flatten_targets))

def seq_minibatches ( inputs , targets , batch_size , seq_length , stride = 1 ) : assert ( len ( inputs ) == len ( targets ) ) n_loads = ( ( batch_size * stride ) + ( seq_length - stride ) ) for start_idx in range ( 0 , ( ( len ( inputs ) - n_loads ) + 1 ) , ( batch_size * stride ) ) : seq_inputs = np . zeros ( ( ( batch_size , seq_length ) + inputs . shape [ 1 : ] ) , dtype = inputs . dtype ) seq_targets = np . zeros ( ( ( batch_size , seq_length ) + targets . shape [ 1 : ] ) , dtype = targets . dtype ) for b_idx in xrange ( batch_size ) : start_seq_idx = ( start_idx + ( b_idx * stride ) ) end_seq_idx = ( start_seq_idx + seq_length ) seq_inputs [ b_idx ] = inputs [ start_seq_idx : end_seq_idx ] seq_targets [ b_idx ] = targets [ start_seq_idx : end_seq_idx ] flatten_inputs = seq_inputs . reshape ( ( ( ( - 1 ) , ) + inputs . shape [ 1 : ] ) ) flatten_targets = seq_targets . reshape ( ( ( ( - 1 ) , ) + targets . shape [ 1 : ] ) ) ( yield ( flatten_inputs , flatten_targets ) )
generate a generator that return a batch of sequence inputs and targets .