【发布时间】:2020-12-22 11:44:24
【问题描述】:
我的输入张量看起来像:
torch.Size([8, 23])
// where,
// 8 -> batch size
// 23 -> words in each of them
我的输出张量看起来像:
torch.Size([8, 23, 103])
// where,
// 8 -> batch size
// 23 -> words predictions
// 103 -> vocab size.
我想为这个任务计算稀疏交叉熵损失,但我不能,因为 PyTorch 只计算损失单个元素。我如何编码才能工作?感谢您的帮助。
【问题讨论】:
-
您能解释一下您期望的结果吗?您是否正在寻找
torch.nn.BCEWithLogitsLoss? -
我正在训练一个编码器-解码器网络,因此输出中的每个位置都有 103 个(词汇大小)位置可供选择。但是由于在 Pytorch 中我只能计算一个单词的损失,我应该如何计算总损失。我正在使用变压器网络。
标签: nlp pytorch huggingface-transformers