• 场感知因子分解机器的原理与代码


    本篇深入分析郭大ffm的代码

    TensorFlow计算图

    传入数据的计算图

    self.label = tf.placeholder(shape=(None), dtype=tf.float32)
    self.features=tf.placeholder(shape=(None,hparams.feature_nums), dtype=tf.int32)
    

    计算图的参数

    self.emb_v1=tf.get_variable(shape=[hparams.hash_ids,1],
                                        initializer=initializer,name='emb_v1')
    self.emb_v2=tf.get_variable(shape=[hparams.hash_ids,hparams.feature_nums,hparams.k],
                                        initializer=initializer,name='emb_v2') # fm中是二维的,这里是三维的
    

    计算图的构建

    # models/ffm.py build_graph()
    #lr
    emb_inp_v1=tf.gather(self.emb_v1, self.features) # shape = [batch_size, attr_nums, 1]
            w1=tf.reduce_sum(emb_inp_v1,[-1,-2])
            
    # 交叉项
    # self.features shape = [batch_size, attr_nums]
    emb_inp_v2=tf.gather(self.emb_v2, self.features) # shape = [batch_size, attr_nums, attr_nums, k] # 每个attr从属于一个场
    emb_inp_v2=tf.reduce_sum(emb_inp_v2*tf.transpose(emb_inp_v2,[0,2,1,3]),-1) # shape=[batch_size, attr_nums, attr_nums]
    temp=[]
    for i in range(hparams.feature_nums):
        if i!=0:
            temp.append(emb_inp_v2[:,i,:i]) # 取下三角
    w2=tf.reduce_sum(tf.concat(temp,-1),-1) # 所有下三角的元素concat成一个列表
    
  • 相关阅读:
    Java之泛型练习
    集合框架-Map练习-记录字母出现的次数
    集合框架Map之entrySet方法的使用
    集合框架Map之KeySet方法的使用
    Java集合框架之LinkedList-----用LinkedList模拟队列和堆栈
    springboot2.0+mycat实验读写分离
    mysql主从复制
    mycat读写分离
    kafka初探
    redis-List类型
  • 原文地址:https://www.cnblogs.com/ZeroTensor/p/11307187.html
Copyright © 2020-2023  润新知