Created
December 3, 2017 07:17
-
-
Save odanado/1f190f07c6956949d231bc73ea11f1fa to your computer and use it in GitHub Desktop.
This file contains 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 make_mask(lens, mask_shape): | |
mask = np.ones(mask_shape).astype('uint8') | |
for i, l in enumerate(lens): | |
mask[i, :l] = 0 | |
return mask | |
batch_size = 2 | |
seq_len = 4 | |
lens = np.array([2, 3]) | |
shape = (batch_size, seq_len) | |
mask = make_mask(lens, shape) | |
print(mask) | |
# [[0 0 1 1] | |
# [0 0 0 1]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment