zoukankan      html  css  js  c++  java
  • 场感知因子分解机器的原理与代码

    本篇深入分析郭大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-二维码
    Java-properties
    Java-JSON
    Java-动态代理
    Java-XML
    Java-IO
    Java-File类
    Java-Http
    测试工作小工具~总结&下载连接
    Jenkins持续集成环境搭建
  • 原文地址:https://www.cnblogs.com/ZeroTensor/p/11307187.html
Copyright © 2011-2022 走看看