codecamp

TensorFlow函数教程:tf.nn.embedding_lookup

tf.nn.embedding_lookup函数

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

定义在:tensorflow/python/ops/embedding_ops.py.

请参阅指南:神经网络>Embeddings(嵌套)

在 embedding 张量列表中查找 ids.

此函数用于在 params 的张量列表中执行并行查找.它是tf.gather的概括,其中params解释为大型 embedding 张量的分区.params 可以是使用带分区的 tf.get_variable() 返回的 PartitionedVariable .

如果 len(params) > 1,ids 的每个元素 id 根据 partition_strategy 在 params 元素之间被分区.在所有策略中,如果 id 空间不均匀地划分分区数,则前(max_id + 1)% len(params)个分区中的每个分区将再分配一个id.

如果 partition_strategy 是 "mod",我们将每个 id 分配给分区 p = id % len(params).例如,13个 id 分为5个分区:[[0, 5, 10], [1, 6, 11], [2, 7, 12], [3, 8], [4, 9]]

如果 partition_strategy 是 "div",我们以连续的方式将 id 分配给分区.在这种情况下,13 个 id 分为5个分区:[[0, 1, 2], [3, 4, 5], [6, 7, 8], [9, 10], [11, 12]]

查询的结果被连接成一个密集的张量.返回的张量的 shape 为 shape(ids) + shape(params)[1:].

参数:

  • params:表示完整的 embedding 张量的单张量,或除了第一维之外全部具有相同 shape 的 P 张量列表,表示切分的 embedding 张量.或者,一个 PartitionedVariable,通过沿维度0进行分区创建.对于给定的 partition_strategy,每个元素的大小必须适当.
  • ids:一个 int32 或 int64 类型的 Tensor,包含要在 params 中查找的 id.
  • partition_strategy:指定切分策略的字符串,在 len(params) > 1 的情况下使用.目前支持两种切分方式:"div"和"mod",默认是"mod".
  • name:操作的名称(可选).
  • validate_indices:已弃用.如果将此操作分配给 CPU,则 indices 中的值始终被验证为在范围内.如果分配给 GPU,则超出范围的 indices 会导致安全的但未指定的行为,这可能包括引发错误.
  • max_norm:如果提供该参数,embedding 值将被 L2-normalize 为 max_norm 的值.

返回:

该函数与 params 中的张量具有相同类型的 Tensor.

可能引发的异常:

  • ValueError:如果 params 是空的.
TensorFlow函数教程:tf.nn.elu
TensorFlow函数教程:tf.nn.embedding_lookup_sparse
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

TensorFlow 函数介绍

TensorFlow 函数模块:tf

TensorFlow的image模块

TensorFlow使用之tf.io

TensorFlow使用之tf.keras

TensorFlow函数教程:tf.keras.applications

TensorFlow函数教程:tf.keras.backend

TensorFlow使用之tf.metrics

TensorFlow使用之tf.nn

TensorFlow使用之tf.python_io

TensorFlow 功能函数

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }