Created
June 10, 2019 01:27
-
-
Save ashunigion/abac55dea75c113089e7796ee0c25515 to your computer and use it in GitHub Desktop.
creating the batch of words and and their corresponding context words.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_batches(words, batch_size, window_size=5): | |
''' Create a generator of word batches as a tuple (inputs, targets) ''' | |
n_batches = len(words)//batch_size | |
# only full batches | |
words = words[:n_batches*batch_size] | |
for idx in range(0, len(words), batch_size): | |
x, y = [], [] | |
batch = words[idx:idx+batch_size] | |
for ii in range(len(batch)): | |
batch_x = batch[ii] | |
batch_y = get_target(batch, ii, window_size) | |
y.extend(batch_y) | |
x.extend([batch_x]*len(batch_y)) | |
yield x, y |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment