從張量列表中查找給定 ids 的嵌入。
用法
tf.nn.embedding_lookup(
params, ids, max_norm=None, name=None
)參數
-
params表示完整嵌入張量的單個張量,或除第一個維度外所有相同形狀的張量列表,表示遵循"div" 分區策略的分片嵌入張量。 -
ids類型為int32或int64的Tensor包含要在params中查找的 ID。 -
max_norm如果不是None,則每個嵌入在其 l2-norm 大於此值時被剪裁。 -
name操作的名稱(可選)。
返回
-
A
Tensor與中的張量具有相同的類型params.例如,如果
params是一個 5x2 矩陣:[[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]]或矩陣列表:
params[0]:[[1, 2], [3, 4]] params[1]:[[5, 6], [7, 8]] params[2]:[[9, 10]]ids是:[0, 3, 4]輸出將是一個 3x2 矩陣:
[[1, 2], [7, 8], [9, 10]]
拋出
-
ValueError如果params為空。
此函數用於對 params 中的張量列表執行並行查找。它是 tf.gather 的泛化,其中 params 被解釋為大嵌入張量的分區。
如果 len(params) > 1 ,則 ids 的每個元素 id 根據 "div" 分區策略在 params 的元素之間進行分區,這意味著我們以連續的方式將 id 分配給分區。例如,13 個 id 被分成 5 個分區:[[0, 1, 2], [3, 4, 5], [6, 7, 8], [9, 10], [11, 12]]。
如果 id 空間不均分分區數,那麽前(max_id + 1) % len(params) 個分區中的每一個都會被分配一個多一個 id。
查找的結果被連接成一個密集的張量。返回的張量具有形狀 shape(ids) + shape(params)[1:] 。
相關用法
- Python tf.nn.embedding_lookup_sparse用法及代碼示例
- Python tf.nn.experimental.stateless_dropout用法及代碼示例
- Python tf.nn.erosion2d用法及代碼示例
- Python tf.nn.elu用法及代碼示例
- Python tf.nn.RNNCellResidualWrapper.set_weights用法及代碼示例
- Python tf.nn.dropout用法及代碼示例
- Python tf.nn.gelu用法及代碼示例
- Python tf.nn.RNNCellDeviceWrapper.set_weights用法及代碼示例
- Python tf.nn.RNNCellDeviceWrapper.get_weights用法及代碼示例
- Python tf.nn.local_response_normalization用法及代碼示例
- Python tf.nn.scale_regularization_loss用法及代碼示例
- Python tf.nn.RNNCellResidualWrapper.add_loss用法及代碼示例
- Python tf.nn.max_pool用法及代碼示例
- Python tf.nn.RNNCellDropoutWrapper.set_weights用法及代碼示例
- Python tf.nn.l2_loss用法及代碼示例
- Python tf.nn.log_softmax用法及代碼示例
- Python tf.nn.weighted_cross_entropy_with_logits用法及代碼示例
- Python tf.nn.ctc_greedy_decoder用法及代碼示例
- Python tf.nn.dilation2d用法及代碼示例
- Python tf.nn.RNNCellResidualWrapper.get_weights用法及代碼示例
注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.nn.embedding_lookup。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
