标签:range lob split 多个 combiner 1.5 numpy app ini
import tensorflow as tf
import numpy as np
sess = tf.InteractiveSession()
M = list('ABCD')
table = tf.contrib.lookup.index_table_from_tensor(
mapping=tf.constant(M), num_oov_buckets=1, default_value=-1)
tf.tables_initializer().run()
tf.global_variables_initializer().run()
# 包含多个ID
IDs = tf.Variable(["A|B|C", "C|D|A|B","C|A|A|B|E|E"] )
embedding_mat = tf.constant(np.arange(20, dtype=float).reshape((20,1)))
# 查找embedding变量,并聚合
hs = tf.string_split(IDs, '|')
sp_ID = tf.SparseTensor(hs.indices, table.lookup(hs.values),hs.dense_shape)
AB = tf.nn.embedding_lookup_sparse(embedding_mat, sp_ID, sp_weights=None, combiner='mean')
AC = tf.nn.embedding_lookup_sparse(embedding_mat, sp_ID, sp_weights=None, combiner='sum')
print(AB.eval() )
print()
print(AC.eval())
结果
[[ 1. ]
[ 1.5 ]
[ 1.83333333]]
[[ 3.]
[ 6.]
[ 11.]]
标签:range lob split 多个 combiner 1.5 numpy app ini
原文地址:http://www.cnblogs.com/bregman/p/7845160.html