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

FFM代码问题请教 #45

Open
WinDYLi-H opened this issue Aug 20, 2021 · 3 comments
Open

FFM代码问题请教 #45

WinDYLi-H opened this issue Aug 20, 2021 · 3 comments

Comments

@WinDYLi-H
Copy link

WinDYLi-H commented Aug 20, 2021

在求教二阶交叉信息的时候,embedding_lookup之后应该是一个batch,filed_num,field_num,k的矩阵,
后面做交叉之前为什么要做这一步的reduce_sum
latent_vector = tf.reduce_sum(tf.nn.embedding_lookup(self.v, inputs), axis=1)

我理解的代码应该是这样的:

latent_vector = tf.nn.embedding_lookup(self.v, inputs) # (batch_size, field_num, field_num, k)
for i in range(self.field_num):
    for j in range(i+1, self.field_num):
        second_order += tf.reduce_sum(latent_vector[:, i, j] * latent_vector[:, j, i], axis=1, keepdims=True)
@SaiLoong
Copy link

我也有这样的疑惑,我一开始以为是经优化过后的公式,但是好像推不出来,而且我测试了两种结果并不一致

@liupandatacs
Copy link

这个代码我理解是不同特征相同领域向量相加,然后再进行不同领域之间交叉,和公式上的不太一样呢

@TangJiakai
Copy link

在求教二阶交叉信息的时候,embedding_lookup之后应该是一个batch,filed_num,field_num,k的矩阵, 后面做交叉之前为什么要做这一步的reduce_sum latent_vector = tf.reduce_sum(tf.nn.embedding_lookup(self.v, inputs), axis=1)

我理解的代码应该是这样的:

latent_vector = tf.nn.embedding_lookup(self.v, inputs) # (batch_size, field_num, field_num, k)
for i in range(self.field_num):
    for j in range(i+1, self.field_num):
        second_order += tf.reduce_sum(latent_vector[:, i, j] * latent_vector[:, j, i], axis=1, keepdims=True)

我也是这里感觉不是很好理解,我看过其他代码实现:首先将每个feat映射到filed(但是这里作者应该是简化了,一个feat就当作是一个filed了),然后循环应该是按照feat走,而不是按照filed,实际取的时候需要注意到对方feat所在filed,然后对应取embedding。包括你写的和作者的循环都是以range(self.filed_num)走的,所以似乎都不太对。

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

4 participants