在注意力是你所需要的,作者实现了位置嵌入(它添加了关于单词在序列中的位置的信息).为此,他们使用正弦嵌入:
PE(pos,2i) = sin(pos/10000**(2*i/hidden_units))
PE(pos,2i+1) = cos(pos/10000**(2*i/hidden_units))
Run Code Online (Sandbox Code Playgroud)
pos是位置,我是维度.它必须导致形状[max_length,embedding_size]的嵌入矩阵,即,给定序列中的位置,它返回PE [position,:]的张量.
我找到了Kyubyong的实现,但我并不完全理解它.
我尝试通过以下方式实现它:
hidden_units = 100 # Dimension of embedding
vocab_size = 10 # Maximum sentence length
# Matrix of [[1, ..., 99], [1, ..., 99], ...]
i = np.tile(np.expand_dims(range(hidden_units), 0), [vocab_size, 1])
# Matrix of [[1, ..., 1], [2, ..., 2], ...]
pos = np.tile(np.expand_dims(range(vocab_size), 1), [1, hidden_units])
# Apply the intermediate funcitons
pos = np.multiply(pos, 1/10000.0)
i = np.multiply(i, 2.0/hidden_units)
matrix = np.power(pos, i)
# Apply …Run Code Online (Sandbox Code Playgroud) Google Docs API 提到了如何获取带有建议的文档(跟踪更改),但没有提及如何向文档添加建议。
如何使用 Google Docs API 或 Apps 脚本在文档中插入编辑建议?