您的位置:首页 > 其它

tf.nn.embedding_lookup()的使用

2017-05-27 15:04 190 查看

tf.nn.embedding_lookup(params, ids, partition_strategy=’mod’, name=None, validate_indices=True, max_norm=None)

首先通过一下一个简单的例子来了解一下tf.nn.embedding_lookup()的用法

a = tf.constant([[1,2,3],[4,5,6],[7,8,9],[10,11,12]])
>>>a.eval()
Out[51]:
array([[ 1,  2,  3],
[ 4,  5,  6],
[ 7,  8,  9],
[10, 11, 12]], dtype=int32)

tf.nn.embedding_lookup(a,[0,1]).eval()
>>>Out[52]:
array([[1, 2, 3],
[4, 5, 6]], dtype=int32)

tf.nn.embedding_lookup(a,[[0,1],[1,2]]).eval()
>>>Out[53]:
array([[[1, 2, 3],
[4, 5, 6]],
[[4, 5, 6],
[7, 8, 9]]], dtype=int32)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
[/code]

参数说明:

params: 表示完整的嵌入张量,或者除了第一维度之外具有相同形状的P个张量的列表,表示经分割的嵌入张量。

ids: 一个类型为int32或int64的Tensor,包含要在params中查找的id

partition_strategy: 指定分区策略的字符串,如果len(params)> 1,则相关。当前支持“div”和“mod”。 默认为“mod”

name: 操作名称(可选)

validate_indices: 是否验证收集索引

max_norm: 如果不是None,嵌入值将被l2归一化为max_norm的值

(function () {('pre.prettyprint code').each(function () {
var lines = (this).text().split(′\n′).length;varnumbering = $('').addClass('pre-numbering').hide();
(this).addClass(′has−numbering′).parent().append(numbering);
for (i = 1; i
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: