python - 如何使嵌入矩阵中的某些特定行等于零
问题描述
我想创建一个嵌入矩阵来嵌入我的数据。但是在我的数据中,我使用 0 作为填充。因此,我想让 0 的嵌入采用特定的常数值,即零向量。我怎样才能做到这一点?
import tensorflow as tf
tf.reset_default_graph()
check_vector=tf.constant([1,2,3,4,5,0,0,0,0, dtype=tf.int32)
embedding_matrix=tf.get_variables("emb",[20,30]
embedding_result=tf.gather(check_vector,embedding_result)
with tf.Session() as sess:
sess.run(tf.gather(embedding_matrix, check_vector))
解决方案
推荐阅读
- php - Laravel 将一组数据保存在单独的行中
- python - 枚举列表中的 Python for 循环用于无限
- typescript - 如何使用打字稿中的字符串访问自定义界面的对象属性
- r - 是否有一种简单的方法可以对 R 中的向量中的元素执行算术运算?
- c# - 使用 UnityWebRequest 和 php 获取上传文件的链接
- python - 如何跟踪通过 ansible 调用的长时间运行的 python 脚本的日志
- php - 如何检查 WooCommerce 产品类型是否不可变?
- .net - 我应该如何在 heroku 上托管 abp.io Blazor 项目?
- node.js - 在 jest 和 nest.js 节点中生成 E2e 测试报告
- css - 将图像与文本垂直对齐