之前一直在思考怎么实现FM,后来在看DeepFM的时候,被一句话点醒,如下。
DeepFM论文中有这么一句话:
the latent feature vectors (V ) in FM now server as network weights which
are learned and used to compress the input field vectors to the
embedding vectors.
就是说,FM层的隐向量现在其实就是将高维稀疏输入向量x(one-hot编码)转换为低维密集的嵌入向量的embedding矩阵。
下面这个是FM论文中的给出的计算方法,代码也是根据这个公式实现的。
首先input的形状是(batch_size, max_len, embedding_size)
第 i i i行就代表 v i x i v_ix_i vixi( x i x_i xi就是你输入的one-hot,第 i i i个维度上是1,其余是0, v i v_i v