Last active
October 30, 2019 06:16
-
-
Save ChunML/3ac180bb985db20a97d760772e32e881 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 positional_embedding(pos, model_size): | |
PE = np.zeros((1, model_size)) | |
for i in range(model_size): | |
if i % 2 == 0: | |
PE[:, i] = np.sin(pos / 10000 ** (i / model_size)) | |
else: | |
PE[:, i] = np.cos(pos / 10000 ** ((i - 1) / model_size)) | |
return PE | |
max_length = max(len(data_en[0]), len(data_fr_in[0])) | |
MODEL_SIZE = 128 | |
pes = [] | |
for i in range(max_length): | |
pes.append(positional_embedding(i, MODEL_SIZE)) | |
pes = np.concatenate(pes, axis=0) | |
pes = tf.constant(pes, dtype=tf.float32) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment