code: def cross_entropy_logits(output, target, weights=None):
      """Computes cross entropy with logits
  
      Args:
          output (Tensor): The output of the last layer of the network, before softmax.
          target (Tensor): The ground truth label.
          weights (Tensor, optional): The weight of each sample. Defaults to None.
  
      Examples:
          See DANN, WDGRL, and MMD trainers in kale.pipeline.domain_adapter
      """
  
      class_output = F.log_softmax(output, dim=1)
      max_class = class_output.max(1)
      y_hat = max_class[1]  # get the index of the max log-probability
      correct = y_hat.eq(target.view(target.size(0)).type_as(y_hat))
      if weights is None:
          loss = nn.NLLLoss()(
              class_output, target.type_as(y_hat).view(target.size(0))
          )
      else:
          losses = nn.NLLLoss(reduction="none")(
              class_output, target.type_as(y_hat).view(target.size(0))
          )
          loss = torch.sum(weights * losses) / torch.sum(weights)
      return loss, correct
  
file_path: pykale/kale/predict/losses.py
imports: import torch
  import torch.nn
  from torch.autograd import grad
  from torch.nn import functional
label_desc: Use image node_id 1 for calling a global function with example usage: cross_entropy_logits(output, target, weights) and returns: loss,  correct