在Pytorch中实施不可能的培训损失

发布于 2025-02-04 04:45:39 字数 751 浏览 4 评论 0原文

我正在尝试实施本研究论文中提出的不可能的训练损失:。此损失是负模型损失(NLLLOSS)的更新版本。

这种损失的主要思想是,它在培训过程中避免了不需要的令牌。

这是我的代码:

def NLLLoss(logs, targets, c, alpha=0.1):
    out = torch.zeros_like(targets, dtype=torch.float)
    for i in range(len(targets)):
        # out[i] = logs[i][targets[i]] # The original implementation
        out[i] = alpha * (1 - logs[i][c[i]]) * logs[i][targets[i]]
    return -out.sum()/len(out)

注释的行是原始的NLLLOSS实现。这个代码很好,但是我想知道,此实现正确吗?

I am trying to implement the Unlikelihood Training loss that was proposed in this research paper: NEURAL TEXT DEGENERATION WITH UNLIKELIHOOD TRAINING. This loss is an updated version of the negative log-likelihood loss (NLLLOSS).

The main idea of this loss is that it avoids unwanted tokens during the training process.
enter image description here

This is my code:

def NLLLoss(logs, targets, c, alpha=0.1):
    out = torch.zeros_like(targets, dtype=torch.float)
    for i in range(len(targets)):
        # out[i] = logs[i][targets[i]] # The original implementation
        out[i] = alpha * (1 - logs[i][c[i]]) * logs[i][targets[i]]
    return -out.sum()/len(out)

The commented line is the original NLLLoss implementation. This code well, but I was wondering, is this implementation correct?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

゛清羽墨安 2025-02-11 04:45:40

不,log(1 -x)不等于1- log(x)。
我认为需求是

No, log(1-x) does not equal 1 - log(x).
I think what need is here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文