-
Notifications
You must be signed in to change notification settings - Fork 20
/
CDAE.py
37 lines (32 loc) · 1.46 KB
/
CDAE.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from keras.layers import Input, Dense, Embedding, Flatten, Dropout, merge, Activation
from keras.models import Model
from keras.regularizers import l2
def create(I, U, K, hidden_activation, output_activation, q=0.5, l=0.01):
'''
create model
Reference:
Yao Wu, Christopher DuBois, Alice X. Zheng, Martin Ester.
Collaborative Denoising Auto-Encoders for Top-N Recommender Systems.
The 9th ACM International Conference on Web Search and Data Mining (WSDM'16), p153--162, 2016.
:param I: number of items
:param U: number of users
:param K: number of units in hidden layer
:param hidden_activation: activation function of hidden layer
:param output_activation: activation function of output layer
:param q: drop probability
:param l: regularization parameter of L2 regularization
:return: CDAE
:rtype: keras.models.Model
'''
x_item = Input((I,), name='x_item')
h_item = Dropout(q)(x_item)
h_item = Dense(K, W_regularizer=l2(l), b_regularizer=l2(l))(h_item)
# dtype should be int to connect to Embedding layer
x_user = Input((1,), dtype='int32', name='x_user')
h_user = Embedding(input_dim=U, output_dim=K, input_length=1, W_regularizer=l2(l))(x_user)
h_user = Flatten()(h_user)
h = merge([h_item, h_user], mode='sum')
if hidden_activation:
h = Activation(hidden_activation)(h)
y = Dense(I, activation=output_activation)(h)
return Model(input=[x_item, x_user], output=y)