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

Express the Calculation of Quadratic Term in Matrix Form #4

Open
gtbai opened this issue Apr 23, 2018 · 0 comments
Open

Express the Calculation of Quadratic Term in Matrix Form #4

gtbai opened this issue Apr 23, 2018 · 0 comments
Labels
enhancement New feature or request

Comments

@gtbai
Copy link
Owner

gtbai commented Apr 23, 2018

In line 88-95 of new-FFM.py, when calculating the quadratic term, for now we are using a nested loop, which is super inefficient:

# calculate quadratic term
            self.quad_term = tf.get_variable(name='quad_term', shape=[self.batch_size], dtype=tf.float32)
            for f1 in xrange(0, feature_num - 1):
                for f2 in xrange(f1 + 1, feature_num):
                    W1 = self.quad_weight[f1, self.feature2field[f2]]
                    W2 = self.quad_weight[f2, self.feature2field[f1]]
                    tf.assign_add(self.quad_term, tf.scalar_mul(tf.tensordot(W1, W2, 1), tf.multiply(self.feature_value[:, f1], self.feature_value[:, f2])))

Need to figure out a way to express this in matrix form.

@gtbai gtbai added the enhancement New feature or request label Apr 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant