Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def make_batch(self, batch_size):
- contexts = self.build_contexts()
- data = np.array([context for word, context in contexts if len(context) == 2 * self.window_size and word != 0])
- label = np.array([word for word, context in contexts if len(context) == 2 * self.window_size and word != 0])
- batch_count = int(math.ceil(len(data) / batch_size))
- idx = 0
- begin, end = idx * batch_size, min((idx + 1) * batch_size, len(contexts))
- indices = np.arange(len(data))
- while (idx < batch_count):
- batch_indices = indices[begin: end]
- batch_data, batch_labels = [], []
- np.random.shuffle(data)
- for data_ind in batch_indices:
- central_word, context = label[data_ind], data[data_ind]
- batch_labels.extend([central_word])
- batch_data.extend(context.reshape(-1, 2 * self.window_size))
- yield batch_data, batch_labels
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement