Pytorch avoid softmax with nllloss
`NLLoss` requires as input log-probabilities and therefore it is not compatible with the outputs of a `Softmax` layer which produces probabilities. Consider using a `LogSoftmax`instead, or the `CrossEntropyLoss` with logits.
def pytorch_avoid_softmax_with_nllloss_rule_noncompliant():
    import math
    import torch
    import torch.nn as nn
    # Noncompliant: `softmax` output is used directly with `NLLLoss`.
    m = nn.functional.softmax(dim=1)
    loss = nn.NLLLoss()
    input = torch.randn(3, 5, requires_grad=True)
    target = torch.tensor([1, 0, 4])
    output = loss(m(input), target)
def pytorch_avoid_softmax_with_nllloss_rule_compliant():
    import math
    import torch
    import torch.nn as nn
    # Compliant: `LogSoftmax` is used with `NLLLoss`.
    m = nn.LogSoftmax(dim=1)
    loss = nn.NLLLoss()
    input = torch.randn(3, 5, requires_grad=True)
    target = torch.tensor([1, 0, 4])
    output = loss(m(input), target)