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 |
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
def rbm(movies_df): | |
""" | |
Implement RBM architecture in TensorFlow | |
:param movies_df: data frame that stores movies information | |
:return: variables to be used during TensorFlow training | |
""" | |
hiddenUnits = 100 # Number of hidden layers | |
visibleUnits = len(movies_df) # Number of visible layers | |
# Create respective placeholder variables for storing visible and hidden layer biases and weights |
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 RBM: | |
def __init__(self, n_vis, n_hid): | |
""" | |
Initialize the parameters (weights and biases) we optimize during the training process | |
:param n_vis: number of visible units | |
:param n_hid: number of hidden units | |
""" | |
# Weights used for the probability of the visible units given the hidden units | |
self.W = torch.randn(n_hid, n_vis) # torch.rand: random normal distribution mean = 0, variance = 1 |
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 AutoRec: | |
""" | |
Function to define the AutoRec model class | |
""" | |
def prepare_model(self): | |
""" | |
Function to build AutoRec | |
""" | |
self.input_R = tf.compat.v1.placeholder(dtype=tf.float32, | |
shape=[None, self.num_items], |
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
def Deep_AE_model(X, layers, activation, last_activation, dropout, regularizer_encode, | |
regularizer_decode, side_infor_size=0): | |
""" | |
Function to build the deep autoencoders for collaborative filtering | |
:param X: the given user-item interaction matrix | |
:param layers: list of layers (each element is the number of neurons per layer) | |
:param activation: choice of activation function for all dense layer except the last | |
:param last_activation: choice of activation function for the last dense layer | |
:param dropout: dropout rate | |
:param regularizer_encode: regularizer for the encoder |
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 CDAE(BaseModel): | |
""" | |
Collaborative Denoising Autoencoder model class | |
""" | |
def __init__(self, model_conf, num_users, num_items, device): | |
""" | |
:param model_conf: model configuration | |
:param num_users: number of users | |
:param num_items: number of items | |
:param device: choice of device |
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 MultVAE(BaseModel): | |
""" | |
Variational Autoencoder with Multninomial Likelihood model class | |
""" | |
def __init__(self, model_conf, num_users, num_items, device): | |
""" | |
:param model_conf: model configuration | |
:param num_users: number of users | |
:param num_items: number of items | |
:param device: choice of device |
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 SVAE(nn.Module): | |
""" | |
Function to build the SVAE model | |
""" | |
def __init__(self, hyper_params): | |
super(Model, self).__init__() | |
self.hyper_params = hyper_params | |
self.encoder = Encoder(hyper_params) | |
self.decoder = Decoder(hyper_params) |
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 ESAE(BaseModel): | |
""" | |
Embarrassingly Shallow Autoencoders model class | |
""" | |
def forward(self, rating_matrix): | |
""" | |
Forward pass | |
:param rating_matrix: rating matrix | |
""" | |
G = rating_matrix.transpose(0, 1) @ rating_matrix |
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
import torch | |
from layer import FeaturesEmbedding, MultiLayerPerceptron | |
class NeuralCollaborativeFiltering(torch.nn.Module): | |
""" | |
A Pytorch implementation of Neural Collaborative Filtering. | |
Reference: | |
X He, et al. Neural Collaborative Filtering, 2017. |
NewerOlder