zyang1580 / PDA

This is an implementation for our SIGIR 2021 paper "Causal Intervention for Leveraging Popularity Bias inRecommendation" based on tensorflow..
96 stars 30 forks source link

Question on function create_bpr_loss_two_brach #13

Closed lizhenstat closed 1 year ago

lizhenstat commented 1 year ago

Hi, thanks for your great work and sharing of the code. I have one question about the implemented BPRMF model. In the following implementation, I did not understand which paper the function create_bpr_loss_two_brach is in reference to?

def create_bpr_loss_two_brach(self, users, pos_items, neg_items): # TODO???
    pos_scores = tf.reduce_sum(tf.multiply(users, pos_items), axis=1)   #users, pos_items, neg_items have the same shape
    neg_scores = tf.reduce_sum(tf.multiply(users, neg_items), axis=1)
    # item stop
    pos_scores = tf.nn.elu(pos_scores) + 1
    neg_scores = tf.nn.elu(neg_scores) + 1
    # pos_items_stop = tf.stop_gradient(pos_items)
    # neg_items_stop = tf.stop_gradient(neg_items)
    pos_items_stop = pos_items
    neg_items_stop = neg_items

    self.pos_item_scores = tf.matmul(pos_items_stop,self.w)
    self.neg_item_scores = tf.matmul(neg_items_stop,self.w)
    ps_sigmoid = tf.nn.sigmoid(self.pos_item_scores)
    ns_sigmoid = tf.nn.sigmoid(self.neg_item_scores)

    # first branch
    pos_scores = pos_scores* ps_sigmoid
    neg_scores = neg_scores* ns_sigmoid
    maxi = tf.log(tf.nn.sigmoid(pos_scores - neg_scores)+1e-10)
    self.rubi_ratings = (tf.nn.elu(self.batch_ratings) + 1  - self.rubi_c) * tf.squeeze(ps_sigmoid)
    # self.shape1 = tf.shape(self.batch_ratings)
    # self.shape2 = tf.shape(tf.squeeze(ps_sigmoid))
    # self.rubi_ratings = (self.batch_ratings-self.rubi_c) * tf.squeeze(tf.nn.sigmoid(self.pos_item_scores))
    self.direct_minus_ratings = self.batch_ratings-self.rubi_c*tf.squeeze(tf.nn.sigmoid(self.pos_item_scores))
    self.mf_loss_ori_bce = tf.negative(tf.reduce_mean(maxi))

    # second branch
    # maxi_item = tf.log(tf.nn.sigmoid(self.pos_item_scores - self.neg_item_scores))
    # self.mf_loss_item_bce = tf.negative(tf.reduce_mean(maxi_item))
    self.mf_loss_item_bce = tf.reduce_mean(tf.negative(tf.log(ps_sigmoid + 1e-10))+tf.negative(tf.log(1-ns_sigmoid+1e-10)))
    # unify
    mf_loss = self.mf_loss_ori_bce + self.alpha*self.mf_loss_item_bce
    # regular
    regularizer = tf.nn.l2_loss(users) + tf.nn.l2_loss(pos_items) + tf.nn.l2_loss(neg_items)
    regularizer = regularizer/self.batch_size

    reg_loss = self.decay * regularizer
    return mf_loss, reg_loss

and what is the meaning of the "rubi_c" variable?

self.rubi_c = tf.Variable(tf.zeros([1]), name = 'rubi_c') # [TODO]???

and I am also confused about the untrainable variable "user_rand_embedding" meaning

weights['user_rand_embedding'] = tf.Variable(initializer([self.n_users, self.emb_dim]), name = 'user_rand_embedding', trainable = False) # [TODO] ???
weights['item_rand_embedding'] = tf.Variable(initializer([self.n_items, self.emb_dim]), name = 'item_rand_embedding', trainable = False)

Can you tell me the paper this implementation is in reference with? Thanks for your time and any help would be appreciated.

zyang1580 commented 1 year ago

Thank you for your interest in our work. The terms "create_bpr_loss_two_brach" and "rubi_c" have not been utilized and are unrelated to this paper. These pieces of code are redundant and have not been cleaned up (based on Tianxin Wei's code). Only the computation graph related to the objects of the "sess.run()" is actually used.