def ptb_iterator(raw_data, batch_size, num_steps):
 raw_data = np.array(raw_data, dtype=np.int32)
 data_len = len(raw_data)
 batch_len = (data_len // batch_size)
 data = np.zeros([batch_size, batch_len], dtype=np.int32)
 for i in range(batch_size):
  data[i] = raw_data[(batch_len * i):(batch_len * (i + 1))]
 epoch_size = ((batch_len - 1) // num_steps)
 if (epoch_size == 0):
  raise ValueError('epoch_size == 0, decrease batch_size or num_steps')
 for i in range(epoch_size):
  x = data[:, (i * num_steps):((i + 1) * num_steps)]
  y = data[:, ((i * num_steps) + 1):(((i + 1) * num_steps) + 1)]
  (yield (x, y))

def ptb_iterator ( raw_data , batch_size , num_steps ) : raw_data = np . array ( raw_data , dtype = np . int32 ) data_len = len ( raw_data ) batch_len = ( data_len // batch_size ) data = np . zeros ( [ batch_size , batch_len ] , dtype = np . int32 ) for i in range ( batch_size ) : data [ i ] = raw_data [ ( batch_len * i ) : ( batch_len * ( i + 1 ) ) ] epoch_size = ( ( batch_len - 1 ) // num_steps ) if ( epoch_size == 0 ) : raise ValueError ( 'epoch_size == 0, decrease batch_size or num_steps' ) for i in range ( epoch_size ) : x = data [ : , ( i * num_steps ) : ( ( i + 1 ) * num_steps ) ] y = data [ : , ( ( i * num_steps ) + 1 ) : ( ( ( i + 1 ) * num_steps ) + 1 ) ] ( yield ( x , y ) )
generate a generator that iterates on a list of words .