test_larcqy.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:factorix 作者: gbouchar 项目源码 文件源码
def reader(self, context=None, emb0=None):
        if emb0 is None:  # by default, can use the initial embedding
            emb0 = self.emb0
        if context is None:  # empty contexts are not read
            return emb0
        context_inputs, context_ouputs = context
        context_embs = tf.gather(emb0, context_inputs[:, :, 1])
        preds = tf.reshape(tf.matmul(
                tf.reshape(context_embs, (self.n_data * self.n_features, self.rank)),
                tf.reshape(emb0[0, :], [self.rank, 1])),
                (self.n_data, self.n_features))
        update_strength = tf.tile(tf.reshape(loss_quadratic_grad(preds, context_ouputs),
                                             (self.n_data, self.n_features, 1)), (1, 1, self.rank))
        embs_after_reading = tf.tile(tf.reshape(emb0[0, :], (1, self.rank)), (self.n_data, 1)) \
                             - tf.reduce_sum(context_embs * update_strength, 1) * self.step_size
        return embs_after_reading  # size of the output: (n_data, rank)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号