Skip to content

Express the Calculation of Quadratic Term in Matrix Form #4

Description

@gtbai

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions