コード例 #1
0
 def _create_inference(self):
     with tf.name_scope("inference"):
         
         # user component
         U_pre_Encoder = tf.matmul(self.input_R_U, self.UV) + self.Ub1  # input to the hidden layer
         self.U_Encoder = tool.activation_function(self.g_act,U_pre_Encoder)  # output of the hidden layer
         U_pre_Decoder = tf.matmul(self.U_Encoder, self.UW) + self.Ub2  # input to the output layer
         self.U_Decoder = tool.activation_function(self.f_act,U_pre_Decoder)  # output of the output layer
 
         # item component
         I_pre_mul = tf.transpose(tf.matmul(self.I_factor_vector, tf.transpose(self.input_OH_I)))
         I_pre_Encoder = tf.matmul(tf.transpose(self.input_R_I), self.IV) + self.Ib1  # input to the hidden layer
         self.I_Encoder = tool.activation_function(self.g_act,I_pre_Encoder * I_pre_mul)  # output of the hidden layer
         I_pre_Decoder = tf.matmul(self.I_Encoder, self.IW) + self.Ib2  # input to the output layer
         self.I_Decoder = tool.activation_function(self.f_act,I_pre_Decoder)  # output of the output layer
 
         # final output
         self.Decoder = ((tf.transpose(tf.gather_nd(tf.transpose(self.U_Decoder), self.col_idx)))
                         + tf.gather_nd(tf.transpose(self.I_Decoder), self.row_idx)) / 2.0
 
         pos_data = tf.gather_nd(self.Decoder, self.input_P_cor)
         neg_data = tf.gather_nd(self.Decoder, self.input_N_cor)
         
         self.pre_cost1 = tf.maximum(neg_data - pos_data + self.margin,
                                tf.zeros(tf.shape(neg_data)[0]))
コード例 #2
0
ファイル: DAE.py プロジェクト: skriser/NeuRec
    def _create_inference(self):
        with tf.name_scope("inference"):
            corrupted_input = tf.multiply(self.input_R, self.mask_corruption)
            encoder_op = tool.activation_function(self.h_act, \
                                                  tf.matmul(corrupted_input, self.weights['encoder']) + self.biases[
                                                      'encoder'])

            self.decoder_op = tf.matmul(encoder_op, self.weights['decoder']) + self.biases['decoder']
            self.output = tool.activation_function(self.g_act, self.decoder_op)
コード例 #3
0
 def _create_inference(self):
     with tf.name_scope("inference"):
         
         self.user_latent = tf.nn.embedding_lookup(self.V, self.user_input)
         
         corrupted_input = tf.multiply(self.input_R, self.mask_corruption)
         encoder_op = tool.activation_function(self.h_act,
                                               tf.matmul(corrupted_input, self.weights['encoder'])
                                               + self.biases['encoder'] + self.user_latent)
           
         self.decoder_op = tf.matmul(encoder_op, self.weights['decoder'])+self.biases['decoder']
         self.output = tool.activation_function(self.g_act, self.decoder_op)
コード例 #4
0
    def _create_inference(self):
        with tf.name_scope("inference"):
            A_hat = np.dot(self.U, self.U.T) + np.dot(
                np.dot(self.U, self.lamda), self.U.T)
            # A_hat += np.dot(np.dot(self.U, self.lamda_2), self.U.T)
            A_hat = A_hat.astype(np.float32)

            embeddings = tf.concat(
                [self.user_embeddings, self.item_embeddings], axis=0)
            all_embeddings = [embeddings]
            for k in range(0, self.num_layers):

                embeddings = tf.matmul(A_hat, embeddings)

                # filters = self.filters[k]#tf.squeeze(tf.gather(self.filters, k))
                embeddings = tool.activation_function(
                    self.activation, (tf.matmul(embeddings, self.filters[k])))
                all_embeddings += [embeddings]
            all_embeddings = tf.concat(all_embeddings, 1)
            self.user_new_embeddings, self.item_new_embeddings = tf.split(
                all_embeddings, [self.num_users, self.num_items], 0)
            self.u_embeddings = tf.nn.embedding_lookup(
                self.user_new_embeddings, self.input_user)
            self.pos_i_embeddings = tf.nn.embedding_lookup(
                self.item_new_embeddings, self.input_item_pos)
            self.neg_j_embeddings = tf.nn.embedding_lookup(
                self.item_new_embeddings, self.input_item_neg)
コード例 #5
0
ファイル: MultiVAE.py プロジェクト: zzg2008/NeuRec
    def p_graph(self, z):
        self.h = z

        for i, (w, b) in enumerate(zip(self.weights_p, self.biases_p)):
            self.h = tf.matmul(self.h, w) + b

            if i != len(self.weights_p) - 1:
                self.h = tool.activation_function(self.act, self.h)
        return self.h
コード例 #6
0
ファイル: MultiDAE.py プロジェクト: zjfng1733/NeuRec-1
    def _create_inference(self):
        with tf.name_scope("inference"):
            # construct forward graph
            self.h = tf.nn.l2_normalize(self.input_ph, 1)
            self.h = tf.nn.dropout(self.h, self.keep_prob_ph)

            for i, (w, b) in enumerate(zip(self.weights, self.biases)):
                self.h = tf.matmul(self.h, w) + b

                if i != len(self.weights) - 1:
                    self.h = tool.activation_function(self.act, self.h)

            self.log_softmax_var = tf.nn.log_softmax(self.h)
コード例 #7
0
ファイル: MultiVAE.py プロジェクト: zjfng1733/NeuRec-1
    def q_graph(self):
        mu_q, std_q, KL = None, None, None
        
        h = tf.nn.l2_normalize(self.input_ph, 1)
        h = tf.nn.dropout(h, self.keep_prob_ph)
        
        for i, (w, b) in enumerate(zip(self.weights_q, self.biases_q)):
            h = tf.matmul(h, w) + b
            
            if i != len(self.weights_q) - 1:
                h = tool.activation_function(self.act, h)
            else:
                mu_q = h[:, :self.q_dims[-1]]
                logvar_q = h[:, self.q_dims[-1]:]  # log sigmod^2  batch x 200

                std_q = tf.exp(0.5 * logvar_q)  # sigmod batch x 200
                KL = tf.reduce_mean(tf.reduce_sum(0.5 * (-logvar_q + tf.exp(logvar_q) + tf.pow(mu_q,2) - 1), axis=1))
        return mu_q, std_q, KL