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

TensorFlow计算图

计算图的构建

ones = tf.ones_like(emb_inp_v2)
mask_a = tf.matrix_band_part(ones, 0, -1) # Upper triangular matrix of 0s and 1s
mask_b = tf.matrix_band_part(ones, 0, 0) # Diagonal matrix of 0s and 1s
mask = tf.cast(mask_a - mask_b, dtype=tf.bool) # Make a bool mask
'''
True - True = 0 and 0 = False
''' #DNN
dnn_input = tf.boolean_mask(emb_inp_v2, mask) # 把上三角减去对角线的部分取出来
dnn_input = tf.reshape(dnn_input,[tf.shape(emb_inp_v2)[0],hparams.feature_nums*(hparams.feature_nums-1)//2]) input_size=int(dnn_input.shape[-1])
for idx in range(len(hparams.hidden_size)):
glorot = np.sqrt(2.0 / (input_size + hparams.hidden_size[idx]))
W = tf.Variable(np.random.normal(loc=0, scale=glorot, size=(input_size, hparams.hidden_size[idx])), dtype=np.float32)
dnn_input=tf.tensordot(dnn_input,W,[[-1],[0]])
if hparams.norm is True:
dnn_input=self.batch_norm_layer(dnn_input,\
self.use_norm,'norm_'+str(idx))
dnn_input=tf.nn.relu(dnn_input)
input_size=hparams.hidden_size[idx] glorot = np.sqrt(2.0 / (hparams.hidden_size[-1] + 1))
W = tf.Variable(np.random.normal(loc=0, scale=glorot, size=(hparams.hidden_size[-1], 1)), dtype=np.float32)
b = tf.Variable(tf.constant(-3.5), dtype=np.float32)
w3=tf.tensordot(dnn_input,W,[[-1],[0]])+b

为什么没有把单项特征算进去?

NFFM的原理与代码的更多相关文章

  1. flume原理及代码实现

    转载标明出处:http://www.cnblogs.com/adealjason/p/6240122.html 最近想玩一下流计算,先看了flume的实现原理及源码 源码可以去apache 官网下载 ...

  2. Java Base64加密、解密原理Java代码

    Java Base64加密.解密原理Java代码 转自:http://blog.csdn.net/songylwq/article/details/7578905 Base64是什么: Base64是 ...

  3. Base64加密解密原理以及代码实现(VC++)

    Base64加密解密原理以及代码实现 转自:http://blog.csdn.net/jacky_dai/article/details/4698461 1. Base64使用A--Z,a--z,0- ...

  4. AC-BM算法原理与代码实现(模式匹配)

    AC-BM算法原理与代码实现(模式匹配) AC-BM算法将待匹配的字符串集合转换为一个类似于Aho-Corasick算法的树状有限状态自动机,但构建时不是基于字符串的后缀而是前缀.匹配 时,采取自后向 ...

  5. Java基础知识强化之集合框架笔记47:Set集合之TreeSet保证元素唯一性和比较器排序的原理及代码实现(比较器排序:Comparator)

    1. 比较器排序(定制排序) 前面我们说到的TreeSet的自然排序是根据集合元素的大小,TreeSet将它们以升序排列. 但是如果需要实现定制排序,比如实现降序排序,则要通过比较器排序(定制排序)实 ...

  6. PHP网站安装程序的原理及代码

    原文:PHP网站安装程序的原理及代码 原理: 其实PHP程序的安装原理无非就是将数据库结构和内容导入到相应的数据库中,从这个过程中重新配置连接数据库的参数和文件,为了保证不被别人恶意使用安装文件,当安 ...

  7. 免费的Lucene 原理与代码分析完整版下载

    Lucene是一个基于Java的高效的全文检索库.那么什么是全文检索,为什么需要全文检索?目前人们生活中出现的数据总的来说分为两类:结构化数据和非结构化数据.很容易理解,结构化数据是有固定格式和结构的 ...

  8. 机器学习之KNN原理与代码实现

    KNN原理与代码实现 本文系作者原创,转载请注明出处:https://www.cnblogs.com/further-further-further/p/9670187.html 1. KNN原理 K ...

  9. 机器学习之AdaBoost原理与代码实现

    AdaBoost原理与代码实现 本文系作者原创,转载请注明出处: https://www.cnblogs.com/further-further-further/p/9642899.html 基本思路 ...

随机推荐

  1. 事件处理程序EventUtil

    /**********事件处理程序***********EventUtil.js*浏览器兼容,<高三>13章 P354*2014-12-8************************* ...

  2. input type=color 设置颜色

    在设置背景色的时候,使用html5 type=color 标签,但是初始值一直都是黑色的,背景如果没有设置的时候,应该是白色,比如文本图元,所以需要设置一个初始的颜色值, 注意: value不实用,怎 ...

  3. 【Day3】5.Python中的lxml模块

    import lxml.etree as le with open('edu.html','r',encoding='utf-8') as f: html = f.read() html_x = le ...

  4. mount -t proc none /proc

    linux initrd里的init脚本中的第一句为: mount -t proc /proc /proc 作用是把proc这个虚拟文件系统挂载到/proc目录.这说明initrd需要用到/proc, ...

  5. Django—logging配置

    我写Django项目常用的logging配置. # Django的日志配置项 BASE_LOG_DIR = os.path.join(BASE_DIR, "log") LOGGIN ...

  6. Path variable [contentHash:8] not implemented in this context: styles.[contentHash:8].css

    webPack 升级到 4.3.0 导致 extract-text-webpack-plugin 无法使用  

  7. HDU4465 Candy

    Candy Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  8. CSS3 -- 边框圆角

    文章后有彩蛋哦 <!DOCTYPE html> <html lang="en"> <head> <meta charset="U ...

  9. np中的随机函数

      numpy.random.uniform介绍: 1. 函数原型:  numpy.random.uniform(low,high,size)  ==>也即其他函数是对该函数的进一步封装 功能: ...

  10. [Algorithm] Find The Vowels

    // --- Directions // Write a function that returns the number of vowels // used in a string. Vowels ...