Tensorflow 中 Embedding 層為什麼要用矩陣乘來實現?

時間 2021-06-09 17:51:11

1樓:一棵有思想的韭菜

我的猜想是這樣的:

用one-hot-matrix 乘 embedding-matrix來選擇,對與GPU來說是非常高效的,如果用CPU就會慢很多,但是如果這個實現用的是你說的index定址,這就實打實的是線性時間來,有GPU也無法加速。

2樓:Chan Yu

引用一下官方1.14版本的文件。

tf.nn.embedding_lookupThis function is used to perform parallel lookups on the list of tensors in params.

It is a generalization of tf.gather

, where params is interpreted as a partitioning of a large embedding tensor. params may be a PartitionedVariable as returned by using tf.compat.

v1.get_variable()

with a partitioner.

可以看到是通過gather的思路獲取結果的。

不太清楚題主說的矩陣乘是哪個版本或者其他api?

TensorFlow中padding的SAME和VALID兩種方式有何異同?

毛路安 TensorFlow 版本 2.1.0 Anaconda 2019.10 在TensorFlow2.1.0版本中,padding的same卷積後尺寸是否不變由步長strides是否大於1決定。對於轉置卷積和卷積,padding的 same 與 valid 中,輸入高寬 i 輸出高寬 o 步長...

TensorFlow中的onehot有什麼作用,為什麼要使用onehot向量呢?

鄭文勳 考慮多類情況。非onehot,標籤是類似0 1 2 3.n這樣。而onehot標籤則是顧名思義,乙個長度為n的陣列,只有乙個元素是1.0,其他元素是0.0。例如在n為4的情況下,標籤2對應的onehot標籤就是 0.0 0.0 1.0 0.0 使用onehot的直接原因是現在多分類cnn網路...

tensorflow裡面name scope, variable scope等如何理解?

已登出 不逼逼,貼原始碼和注釋 還不懂你打死我 coding utf 8 import osimport sysimport time import reimport math import numpy asnp import pandas aspd import tensorflow astf p...