我正在尝试为我自己的任务调整seq2seq模型,https://github.com/spro/practical-pytorch/blob/master/seq2seq-translation/seq2seq-translation.ipynb
在解码阶段我有两个张量
rnn_output: (1, 1, 256) # time_step x batch_size x hidden_dimension
encoder_inputs: (10, 1, 256) # seq_len x batch_size x hidden_dimension
它们应该是多重的,以获得形状的注意力分数(在softmax之前)
^{pr2}$最好的办法是什么?笔记本似乎使用了for循环,有没有比较好的通过矩阵乘法类的运算?在
使用^{} 的示例:
没有使用
pytorch
的经验,但是像这样的东西能起作用吗?在它把点积放在最后一个轴上,然后再加上几个空轴。在
用纯numpy可以实现类似的功能(
^{pr2}$pytorch 0.4
还没有...
符号)或使用
np.tensordot
但在这里您将得到输出形状:
(1, 1, 10, 1)
你可以通过挤压和重新膨胀来解决这个问题(几乎可以肯定,必须有更干净的方法来实现这一点)
相关问题 更多 >
编程相关推荐