首页 > 解决方案 > 如何使嵌入矩阵中的某些特定行等于零

问题描述

我想创建一个嵌入矩阵来嵌入我的数据。但是在我的数据中,我使用 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))

标签: pythontensorflow

解决方案


推荐阅读