Beispiel #1
0
    def build_model(self):
        attention = Attention()
        self.gru_net_ins = GRU()
        self.ggnn_model = gated_GNN()

        with tf.variable_scope('user_behavior_emb'):
            user_behavior_list_embedding = self.behavior_list_embedding_dense

        with tf.variable_scope('ggnn_encoding'):
            self.short_term_intent_temp = self.ggnn_model.generate_time_aware_emb(
                init_emb=user_behavior_list_embedding,
                adj_avg_time=self.adj_avg_time,
                now_batch_size=self.now_bacth_data_size,
                num_units=self.num_units,
                adj_in=self.adj_in,
                adj_out=self.adj_out,
                step=self.FLAGS.graph_step)
            # with tf.variable_scope('ShortTermIntentEncoder'):
            #     self.short_term_intent_temp = self.gru_net_ins.gru_net(hidden_units=self.num_units,
            #                                                            input_data=self.behavior_list_embedding_dense,
            #                                                            input_length=tf.add(self.seq_length, -1))
            user_history = self.short_term_intent_temp
            self.short_term_intent = gather_indexes(
                batch_size=self.now_bacth_data_size,
                seq_length=self.max_len,
                width=self.num_units,
                sequence_tensor=self.short_term_intent_temp,
                positions=self.mask_index - 1)
            self.short_term_intent = layer_norm(self.short_term_intent)

            short_term_intent4vallina = tf.expand_dims(self.short_term_intent,
                                                       1)

        with tf.variable_scope('NextItemDecoder'):
            hybird_preference = attention.vanilla_attention(
                user_history,
                short_term_intent4vallina,
                self.num_units,
                1,
                1,
                self.dropout_rate,
                is_training=True,
                reuse=False,
                key_length=self.seq_length,
                query_length=tf.ones_like(short_term_intent4vallina[:, 0, 0],
                                          dtype=tf.int32))
            self.predict_behavior_emb = tf.concat(
                [self.short_term_intent, hybird_preference], 1)
            self.predict_behavior_emb = layer_norm(self.predict_behavior_emb)
        self.output_concat()
    def build_model(self):
        attention = Attention()

        self.ggnn_model = gated_GNN()

        with tf.variable_scope('user_behavior_emb'):
            user_behavior_list_embedding = self.behavior_list_embedding_dense

        with tf.variable_scope('ggnn_encoding',reuse=tf.AUTO_REUSE):
            self.gnn_emb_vec = self.ggnn_model.generate_graph_emb(init_emb=user_behavior_list_embedding,
                                   now_batch_size=self.now_bacth_data_size,
                                   num_units=self.num_units,
                                   adj_in=self.adj_in,
                                   adj_out=self.adj_out,
                                   step=self.FLAGS.graph_step)

            self.short_term_intent = gather_indexes(batch_size=self.now_bacth_data_size,
                                                    seq_length=self.max_len,
                                                    width=self.num_units,
                                                    sequence_tensor=self.gnn_emb_vec,
                                                    positions=self.mask_index - 1) # batch_size, num_units


        with tf.variable_scope('self_attention',reuse=tf.AUTO_REUSE):
            self.att_emb_vec = attention.self_attention(enc = self.gnn_emb_vec,
                                                        num_units = self.num_units,
                                                        num_heads = self.num_heads,
                                                        num_blocks = self.num_blocks,
                                                        dropout_rate = self.dropout_rate,
                                                        is_training = True,
                                                        reuse = None,
                                                        key_length= self.seq_length,
                                                        query_length = self.seq_length)
            self.long_term_intent = gather_indexes(batch_size=self.now_bacth_data_size,
                                                seq_length=self.max_len,
                                                width=self.num_units,
                                                sequence_tensor=self.att_emb_vec,
                                                positions=self.mask_index  ) # batch_size, num_units
        with tf.variable_scope('sess_emb', reuse=tf.AUTO_REUSE):
            eps = tf.get_variable('eps',[1],dtype=tf.float32)

            self.predict_behavior_emb = eps*self.short_term_intent +(1-eps) * self.long_term_intent

        self.output()
Beispiel #3
0
    def build_model(self):
        self.gru_net_ins = GRU()
        self.ggnn_model = gated_GNN()
        with tf.variable_scope('user_behavior_emb'):
            user_behavior_list_embedding = self.behavior_list_embedding_dense

        with tf.variable_scope('ggnn_encoding'):
            gnn_emb = self.ggnn_model.generate_graph_emb(
                init_emb=user_behavior_list_embedding,
                now_batch_size=self.now_bacth_data_size,
                num_units=self.num_units,
                adj_in=self.adj_in,
                adj_out=self.adj_out,
                step=1)

        time_aware_attention = Time_Aware_Attention()
        with tf.variable_scope("UserHistoryEncoder"):
            user_history = time_aware_attention.self_attention(
                gnn_emb,
                self.num_units,
                self.num_heads,
                self.num_blocks,
                self.dropout_rate,
                is_training=True,
                reuse=False,
                key_length=self.seq_length,
                query_length=self.seq_length,
                t_querys=self.time_list,
                t_keys=self.time_list,
                t_keys_length=self.max_len,
                t_querys_length=self.max_len)
            long_term_prefernce = gather_indexes(
                batch_size=self.now_bacth_data_size,
                seq_length=self.max_len,
                width=self.FLAGS.num_units,
                sequence_tensor=user_history,
                positions=self.mask_index)
            self.predict_behavior_emb = long_term_prefernce
            self.predict_behavior_emb = layer_norm(self.predict_behavior_emb)
        self.output()
Beispiel #4
0
    def build_model(self):

        self.gru_net_ins = GraphRNN()
        self.gated_gnn_model = gated_GNN()

        with tf.variable_scope('user_behavior_emb'):
            user_behavior_list_embedding = self.behavior_list_embedding_dense

        for i in range(2):
            with tf.variable_scope('neighbor_emb_' + str(i),
                                   reuse=tf.AUTO_REUSE):
                structure_emb = self.gated_gnn_model.generate_graph_emb(
                    init_emb=user_behavior_list_embedding,
                    now_batch_size=self.now_bacth_data_size,
                    num_units=self.num_units,
                    adj_in=self.adj_in,
                    adj_out=self.adj_out,
                    step=self.FLAGS.graph_step
                )  # batch_size, max_len, num_units * 2

            with tf.variable_scope('ShortTermIntentEncoder_' + str(i),
                                   reuse=tf.AUTO_REUSE):

                grnn_inputs = tf.concat(
                    [user_behavior_list_embedding, structure_emb], axis=2)

                user_behavior_list_embedding = self.gru_net_ins.simple_grnn_net(
                    hidden_units=self.num_units,
                    input_data=grnn_inputs,
                    input_length=tf.add(self.seq_length, -1))
        self.short_term_intent = gather_indexes(
            batch_size=self.now_bacth_data_size,
            seq_length=self.max_len,
            width=self.num_units,
            sequence_tensor=user_behavior_list_embedding,
            positions=self.mask_index - 1)
        self.short_term_intent = self.short_term_intent

        self.predict_behavior_emb = layer_norm(self.short_term_intent)
        self.output()
Beispiel #5
0
    def build_model(self):

        self.gru_net_ins = GraphRNN()
        self.gated_gnn_model = gated_GNN()

        with tf.variable_scope('user_behavior_emb'):
            user_behavior_list_embedding = self.behavior_list_embedding_dense

        with tf.variable_scope('neighbor_emb',reuse=tf.AUTO_REUSE):
            structure_emb = self.gated_gnn_model.generate_adj_emb(init_emb=user_behavior_list_embedding,
                                                                  now_batch_size=self.now_bacth_data_size,
                                                                  num_units=self.num_units,
                                                                  adj_in=self.adj_in,
                                                                  adj_out=self.adj_out,

                                                                  ) # batch_size, max_len, num_units * 2

        with tf.variable_scope('ShortTermIntentEncoder'):

            # in_emb, out_emb = array_ops.split(value=structure_emb, num_or_size_splits=2, axis=2)
            #
            # structure_emb = in_emb+out_emb
            structure_emb = tf.layers.dense(structure_emb,units = self.num_units)

            grnn_inputs = tf.concat([user_behavior_list_embedding,structure_emb],axis=2)

            self.short_term_intent_temp = self.gru_net_ins.simple_grnn_net(hidden_units=self.num_units,
                                                                   input_data=grnn_inputs,
                                                                   input_length=tf.add(self.seq_length, -1))
            self.short_term_intent = gather_indexes(batch_size=self.now_bacth_data_size,
                                                    seq_length=self.max_len,
                                                    width=self.num_units,
                                                    sequence_tensor=self.short_term_intent_temp,
                                                    positions=self.mask_index - 1)
            self.short_term_intent = self.short_term_intent

            self.predict_behavior_emb = layer_norm(self.short_term_intent)
        self.output()
Beispiel #6
0
    def build_model(self):
        self.gru_net_ins = GRU()
        self.ggnn_model = gated_GNN()
        with tf.variable_scope('user_behavior_emb'):
            user_behavior_list_embedding = self.behavior_list_embedding_dense

        with tf.variable_scope('ggnn_encoding'):
            gnn_emb = self.ggnn_model.generate_graph_emb(
                init_emb=user_behavior_list_embedding,
                now_batch_size=self.now_bacth_data_size,
                num_units=self.num_units,
                adj_in=self.adj_in,
                adj_out=self.adj_out,
                step=1)

        with tf.variable_scope('ShortTermIntentEncoder'):
            timenext_list = self.timelast_list[:, 1:]
            zeros = tf.zeros(shape=(self.now_bacth_data_size, 1))
            timenext_list = tf.concat([timenext_list, zeros], axis=1)
            self.time_aware_gru_net_input = tf.concat([
                gnn_emb,
                tf.expand_dims(self.timelast_list, 2),
                tf.expand_dims(timenext_list, 2)
            ], 2)
            self.short_term_intent_temp = self.gru_net_ins.time_aware_gru_net(
                hidden_units=self.num_units,
                input_data=self.time_aware_gru_net_input,
                input_length=tf.add(self.seq_length, -1),
                type='new')
            self.short_term_intent = gather_indexes(
                batch_size=self.now_bacth_data_size,
                seq_length=self.max_len,
                width=self.num_units,
                sequence_tensor=self.short_term_intent_temp,
                positions=self.mask_index - 1)

            self.predict_behavior_emb = layer_norm(self.short_term_intent)
        self.output()