Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2020
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.89 KB | None | 0 0
  1. def make_batch(self, batch_size):
  2.         contexts = self.build_contexts()
  3.  
  4.         data = np.array([context for word, context in contexts if len(context) == 2 * self.window_size and word != 0])
  5.         label = np.array([word for word, context in contexts if len(context) == 2 * self.window_size and word != 0])
  6.  
  7.         batch_count = int(math.ceil(len(data) / batch_size))
  8.     idx = 0
  9.     begin, end = idx * batch_size, min((idx + 1) * batch_size, len(contexts))
  10.     indices = np.arange(len(data))
  11.         while (idx < batch_count):
  12.         batch_indices = indices[begin: end]
  13.         batch_data, batch_labels = [], []
  14.             np.random.shuffle(data)
  15.         for data_ind in batch_indices:
  16.             central_word, context = label[data_ind], data[data_ind]
  17.             batch_labels.extend([central_word])
  18.             batch_data.extend(context.reshape(-1, 2 * self.window_size))
  19.  
  20.                 yield batch_data, batch_labels
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement