Skip to content

Instantly share code, notes, and snippets.

View khanhnamle1994's full-sized avatar
🎯
Focusing

James Le khanhnamle1994

🎯
Focusing
View GitHub Profile
@khanhnamle1994
khanhnamle1994 / main.py
Last active January 26, 2024 22:14
FCN - Full Code
#--------------------------
# USER-SPECIFIED DATA
#--------------------------
# Tune these parameters
num_classes = 2
image_shape = (160, 576)
EPOCHS = 40
BATCH_SIZE = 16
@khanhnamle1994
khanhnamle1994 / CDAE.py
Created June 16, 2020 13:45
CDAE model architecture
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
@khanhnamle1994
khanhnamle1994 / MultVAE.py
Created June 16, 2020 13:41
MultVAE model architecture
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
@khanhnamle1994
khanhnamle1994 / nade.py
Created August 15, 2020 23:38
Neural Autoregressive Distribution Estimator for Collaborative Filtering architecture
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
@khanhnamle1994
khanhnamle1994 / Explainable-RBM.py
Created July 31, 2020 15:51
Explainable RBM model architecture
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
@khanhnamle1994
khanhnamle1994 / RBM.py
Created July 31, 2020 15:44
RBM model architecture
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
from tensorflow.contrib.tensorboard.plugins import projector
logdir = 'fashionMNIST-logs'
# Creating the embedding variable with all the images defined above under X_test
embedding_var = tf.Variable(X_test, name='fmnist_embedding')
# Format: tensorflow/contrib/tensorboard/plugins/projector/projector_config.proto
config = projector.ProjectorConfig()
@khanhnamle1994
khanhnamle1994 / AutoRec.py
Created June 16, 2020 13:51
AutoRec model architecture
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],
@khanhnamle1994
khanhnamle1994 / DeepRec.py
Created June 16, 2020 13:47
DeepRec model architecture
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
@khanhnamle1994
khanhnamle1994 / SVAE.py
Created June 16, 2020 13:34
SVAE model architecture
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)