NFFM的原理与代码
2024-10-06 18:34:54
本篇深入分析郭大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
为什么没有把单项特征算进去?
最新文章
- 怎样学习Java
- poj 2251 Dungeon Master
- 绑定本地Service并与之通信-----之一
- 在eclipse中生成html注释文档
- What is Object Oriented Design? (OOD)
- 各种电子面单_Api接口
- 右下角显示提示窗口(New-Object,COM)
- Linux学习笔记22——线程属性(转)
- 禁止root远程登录 sshd问题:A protocol error occurred. Change of username or service not allowed
- DOM树节点和事件
- 初识WCF之使用配置文件部署WCF应用程序
- How do I copy files that need root access with scp
- 前端知识之Ajax
- 5行代码实现微信小程序图片上传与腾讯免费5G存储空间的使用
- vue2 学习笔记2
- qt5下载与安装,VS2017的环境配置
- Imageview 按比例适应屏幕大小
- ISO 8601: Delphi way to convert XML date and time to TDateTime and back (via: Stack Overflow)
- windows自带杀毒防火墙
- 命名实体识别(NER)