python - Transformer 的输入和输出分别是什么?
问题描述
我在这里对变压器的谷歌实施有疑问。
在
train_step(input, tar)
函数中:inp
维度是一个 256*40 的张量,转换器返回一个 256*39*8089 的张量。每一行是inp
一个句子吗?我希望 Transformer 能够获取一批句子(一个 batch_size 的 2D 矩阵,其中每一行都是一个单词)并立即计算注意力权重和输出,然后将它们传递给解码器(参见此处。)。但是,我看不到在代码中实现了这一点。在
train_step(input, tar)
函数中:“预测”是一个 256*39*8089 张量。是[批量大小,句子中的最大单词数,目标词汇量]?当这种格式与 [256 * 39] 的 ```tar_real`` 不同时,loss_function 如何计算损失?In
def evaluate(inp_sentence)
:为什么在每次迭代中它都会向 Transformer 发送整个编码器输入?我期望的是编码器计算注意力权重并输出一次,然后在 for 循环中我们发送注意力的输出和到目前为止的预测。
谢谢
解决方案
推荐阅读
- wolkenkit - 没有 Docker 的 wolkenkit
- android - 是否可以将 LAN 连接到 Android 模拟器
- typescript - 如何创建一个可能只包含特定类和该类的子类的字典变量
- xamarin.forms - 在 21 之前的版本中,什么相当于 Android.Widget.ListView.NestedScrollingEnabled?
- android - 如何在android中合并音频和视频
- android - 如何在一次下载多个文件时添加百分比进度条
- java - 在 Codeception 中添加自定义请求标头
- python-3.x - Pytorch - 这是使用 pytorch.data.Dataset 加载大数据集并对其进行线性回归训练的正确方法吗
- c# - 尝试创建抽象层以支持多个第三方作为文档管理系统
- r - 如何使用 felm() 指定工具变量模型?