8000 Setting the tensor of the values out of `[0,1]` to `target` argument of `nn.CrossEntropyLoss()` with class probabilities works against the doc · Issue #134771 · pytorch/pytorch · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Setting the tensor of the values out of [0,1] to target argument of nn.CrossEntropyLoss() with class probabilities works against the doc #134771
@hyperkai

Description

@hyperkai

🐛 Describe the bug

The doc of nn.CrossEntropyLoss() says that target argument with class probabilities should be between [0, 1] as shown below:

Target: ... If containing class probabilities, same shape as the input and each value should be between [0,1].

But setting the tensor of the values out of [0,1] to target argument with class probabilities works against the doc above as shown below:

import torch

input = torch.tensor([[0.4, 0.8, 0.6], [0.3, 0.0, 0.5]])
target = torch.tensor([[6.2, -7.9, 3.4], [2.1, 8.6, -12.5]]) # Here

cel = nn.CrossEntropyLoss()

cel(input=input, target=target) # tensor(3.9178)

Versions

import torch

torch.__version__ # 2.4.0+cu121

cc @svekars @sekyondaMeta @AlannaBurke @brycebortree @tstatler

Metadata

Metadata

Assignees

Labels

docathon-h1-2025mediumLabel for medium docathon tasksmodule: docsRelated to our documentation, both in docs/ and docblocksmodule: lossProblem is related to loss functiontriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0