Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

你好,请问关于损失函数部分,kge的损失和论文里公式13第二部分怎么对应? #14

Open
songzeceng opened this issue Oct 16, 2019 · 2 comments

Comments

@songzeceng
Copy link

论文里公式13第二部分主要这样的:Ir - EtRE
代码里似乎对应(因为论文里kge损失的权重λ2和代码里kge_weight的默认值都是0.01)

        self.kge_loss = 0
        for hop in range(self.n_hop):
            h_expanded = tf.expand_dims(self.h_emb_list[hop], axis=2)
            t_expanded = tf.expand_dims(self.t_emb_list[hop], axis=3)
            hRt = tf.squeeze(tf.matmul(tf.matmul(h_expanded, self.r_emb_list[hop]), t_expanded))
            self.kge_loss += tf.reduce_mean(tf.sigmoid(hRt))
        self.kge_loss = -self.kge_weight * self.kge_loss

代码里应该就是h * r * t,然后我有以下几个疑问:
1、公式里Ir怎么对应,是0矩阵么?否则我不明白kge_loss为何是要在kge_weight和kge_loss相乘结果的基础上,再乘个-1。但是Ir的定义是

Ir is the slice of the indicator tensor I in KG for relation r

也就是Ir是关系r在知识图谱里用I切的片,这里I张量是怎么定义的呢?

2、公式里参数用的是λ2/2,但是代码里却是kge_weight,这里是代码手误么?

希望大佬能在百忙之中尽快解答,谢谢。

@hwwang55
Copy link
Owner

你好!

  1. 代码和论文里的loss不完全一样,论文里的loss是想让hRt的值和真实值R接近,也就是当(h, r, t)为真时,hRt要接近1,否则接近0。代码里的loss是当(h, r, t)为真时,让hRt尽量大,而对(h, r, t)为假时没有要求(也就是没有负采样)。没有负采样是为了实现上的方便;正样本上的loss,两者没有本质区别,都是想提高hRt的值;
  2. kge_weight就是\lambda_2/2。

@Niyx52094
Copy link

我看论文也发现了,还好找到了这里~感谢解答!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants