TensorFlow中张量增加纬度和词向量查找一些操作

版权声明: https://blog.csdn.net/qq_35203425/article/details/79948908

TensorFlow中embedding_lookup操作

import tensorflow as tf

a=tf.Variable(tf.random_normal([2,4]),tf.float32)
b=tf.Variable(tf.random_normal([2,3]),tf.float32)
c=tf.Variable(tf.random_normal([2,3]),tf.float32)

em=tf.nn.embedding_lookup(a,[[0,1],[0,1]])
p1=tf.nn.embedding_lookup(b,[[0,1],[0,1]])
d=tf.expand_dims(tf.concat([em,p1],-1),-1)


with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())

    print('a\n',sess.run(a))

    print('em\n',sess.run(em))
    print('p1\n', sess.run(p1))
    print('d\n',sess.run(d))




阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页