Last active
August 7, 2018 10:28
-
-
Save joshlk/bf2e2960281b99fb4060d674ad8fdd18 to your computer and use it in GitHub Desktop.
Keras one-hot-encode layer
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
class OneHotEncode(Embedding): | |
""" | |
One-hot-encode layer eg. [[1, 3]] -> [[[0,1,0,0],[0,0,0,1]]] | |
input_dim: Number of categories to one-hot encode | |
input_length: length of X vecotrs (optional) | |
mask_zero: treat 0 as masking | |
""" | |
def __init__(self, input_dim, input_length=None, mask_zero=False): | |
super().__init__(input_dim=input_dim, output_dim=input_dim, input_length=input_length, | |
embeddings_initializer='identity', trainable=False, mask_zero=mask_zero) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment