博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
TensorFlow中 tf.nn.embedding_lookup
阅读量:4187 次
发布时间:2019-05-26

本文共 1462 字,大约阅读时间需要 4 分钟。

import tensorflow as tf  src_vocab_size = 10src_embed_size = 5source = [1,3]with tf.variable_scope("encoder"):    embedding_encoder = tf.get_variable(        "embedding_encoder", [src_vocab_size, src_embed_size], tf.float32)encoder_emb_inp = tf.nn.embedding_lookup(          embedding_encoder, source)init = tf.global_variables_initializer()with tf.Session() as sess:    sess.run(init)    emb_mat = sess.run(embedding_encoder)    for line in emb_mat:        print line    en_input = sess.run(encoder_emb_inp)    print    for line in en_input:        print line

输出结果:

[ 0.56113797  0.04369807  0.18308383 -0.48125005 -0.43450889][-0.6047132  -0.21060479  0.40796143 -0.40531671  0.55036896][ 0.31311834 -0.4060598   0.36560428  0.2722581  -0.02451819][ 0.18635517 -0.12266624 -0.39344144 -0.1277926  -0.45468265][ 0.30129766  0.56903845 -0.03529584 -0.33247966  0.45404953][-0.58887643  0.50933784 -0.19886917 -0.03041148 -0.44376266][ 0.35494697  0.25374722  0.41377074  0.06932443 -0.21179438][ 0.10084659 -0.60172981  0.49977249 -0.28413546 -0.33590576][-0.01577765  0.41795093  0.43442172  0.59790486  0.58752233][ 0.42998117 -0.0969131  -0.34563044  0.16796118  0.62855309][-0.6047132  -0.21060479  0.40796143 -0.40531671  0.55036896][ 0.18635517 -0.12266624 -0.39344144 -0.1277926  -0.45468265]

1、对于one-hot的编码embedding操作

2、embedding_lookup即去矩阵中的某一行,同时其不是简单的查表,id对应的向量是可以训练,即其实一个全连接
3、在分类模型中用id类的特征,注意希望模型能够记住信息,但是id的维度太高,同一个商品数量也不大,因此可以用iterm embedding来代替id

转载地址:http://oldoi.baihongyu.com/

你可能感兴趣的文章
DDR3基本概念4 - 预充电和刷新,以及Lattice DDR3 SDRAM controller实战注意事项
查看>>
DDR3基本概念5 - DDR仿真中出现的Memory overflow错误的处理
查看>>
DDR3基本概念6 - Write leveling(写入均衡)
查看>>
DDR3基本概念7 - 写操作,以及Lattice DDR3 SDRAM controller实战
查看>>
verilog 基础原理1 - Testbench的initial中的时间节点的判断
查看>>
Cadence IUS 之三:代码覆盖率分析
查看>>
Lattice FPGA 使用指南3 - 如何用第三方仿真工具跑后仿及波形分析
查看>>
Cadence IUS 之四:生成verdi的fsdb波形时的问题分析
查看>>
Lattice FPGA 使用指南4 - 全局复位网络GSR的使用
查看>>
DDR3基本概念8 - 如何理解RTT和VTT
查看>>
DDR3基本概念9 - 8n pre-fetch architecture的含义
查看>>
DDR3基本概念10 - DDR MT/S的理解
查看>>
git命令缩写配置
查看>>
makefile常见问题
查看>>
ncverilog编译时Unrecognized system task or function: $fsdbDumpfile问题的解决方法
查看>>
window10配置环境不起作用
查看>>
在官网下载maven历史版本
查看>>
tomcat之启动类BootStrap
查看>>
tomcat处理请求的流程
查看>>
Spring之lazy-init
查看>>