Created
August 15, 2020 23:38
-
-
Save khanhnamle1994/5fb9f809ab4205459548c7a50d2b0b4f to your computer and use it in GitHub Desktop.
Neural Autoregressive Distribution Estimator for Collaborative Filtering architecture
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 NADE(Layer): | |
def __init__(self, hidden_dim, activation, W_regularizer=None, V_regularizer=None, | |
b_regularizer=None, c_regularizer=None, bias=False, args=None, **kwargs): | |
self.init = initializers.get('uniform') | |
self.bias = bias | |
self.activation = activation | |
self.hidden_dim = hidden_dim | |
self.W_regularizer = regularizers.get(W_regularizer) | |
self.V_regularizer = regularizers.get(V_regularizer) | |
self.b_regularizer = regularizers.get(b_regularizer) | |
self.c_regularizer = regularizers.get(c_regularizer) | |
self.args = args | |
super(NADE, self).__init__(**kwargs) | |
def build(self, input_shape): | |
""" | |
Build the NADE architecture | |
:param input_shape: Shape of the input | |
""" | |
self.input_dim1 = input_shape[1] | |
self.input_dim2 = input_shape[2] | |
self.W = self.add_weight(shape=(self.input_dim1, self.input_dim2, self.hidden_dim), | |
initializer=self.init, name='{}_W'.format(self.name), regularizer=self.W_regularizer) | |
if self.bias: | |
self.c = self.add_weight(shape=(self.hidden_dim,), initializer=self.init, | |
name='{}_c'.format(self.name), regularizer=self.c_regularizer) | |
if self.bias: | |
self.b = self.add_weight(shape=(self.input_dim1, self.input_dim2), initializer=self.init, | |
name='{}_b'.format(self.name), regularizer=self.b_regularizer) | |
self.V = self.add_weight(shape=(self.hidden_dim, self.input_dim1, self.input_dim2), | |
initializer=self.init, name='{}_V'.format(self.name), regularizer=self.V_regularizer) | |
super(NADE, self).build(input_shape) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment