tf.nn.embedding_lookup TensorFlow embedding_lookup 函数最简单实例

tf.nn.embedding_lookup TensorFlow embedding_lookup 函数最简单实例

#!/usr/bin/env python
# -*- coding: utf-8 -*-


import tensorflow as tf

import numpy as np

params=np.random.normal(loc=0.0,scale=1.0,size=[10,10])

ids=[1,2,3]

with tf.Session() as sess:
	print(sess.run(tf.nn.embedding_lookup(params,ids)))

输出:

[[ 1.7063815  -0.01654651 -0.64545987 -0.34758673  0.48317762  0.61799378
   0.23066604  1.70424801 -0.96460893  1.46270563]
 [ 0.54778326 -0.43954697 -0.3599735  -0.90806082 -0.73178132 -0.87372115
  -0.36002708  0.18508744 -0.01786275  0.87135015]
 [ 0.07694426 -1.55872459 -0.63802347 -1.5762184  -0.65273981 -1.62801055
   0.08332559  1.03982988 -0.96005845  0.17954909]]

posted on 2017-08-06 09:14  TensorFlowNews  阅读(983)  评论(0编辑  收藏  举报

TensorFlow

TensorFlow

磐创AI

TensorFlow 教程从入门到精通

TensorFlow 安装教程

Keras 从入门到精通

粒子群优化算法

聊天机器人

自然语言处理

TensorFlow

TensorFlow