如何在pytorch注意模块中为Query制作非方形权重矩阵?

问题描述

这个问题的续集。 Why W_q matrix in torch.nn.MultiheadAttention is quadratic

在注意力模块中,我希望 Query 的权重投影矩阵是 非方 矩阵 (m-by-n for which m ≠ n) 。就像 Jay Alammar 所解释的那样。 http://jalammar.github.io/illustrated-transformer/

查看附加图片

enter image description here

但是,pytorch 实现似乎只有一个带有 embed_dim x embed_dim 的方阵。 https://pytorch.org/docs/stable/_modules/torch/nn/modules/activation.html#MultiheadAttention

https://pytorch.org/docs/stable/generated/torch.nn.MultiheadAttention.html?highlight=attention#torch.nn.MultiheadAttention

无论如何在pytorch中设置embed_dim1 x embed_dim2?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)