code: def test_index_ignored(Loss):
      x = torch.randn(20, 6, dtype=torch.float64, requires_grad=True)
      _, y = torch.max(torch.randn_like(x), dim=1)
  
      loss_ignore = Loss(reduction="sum", ignore_index=y[0])
      loss_noignore = Loss(
          reduction="sum", ignore_index=IGNORE_INDEX_TOKEN_ID
      )
  
      # Note: since these are sparse losses, it is possible that an element makes no contribution to the loss.
      assert loss_ignore(x, y) <= loss_noignore(x, y)
  
file_path: ludwig/tests/ludwig/utils/entmax/test_losses.py
imports: from functools import partial
  import pytest
  import torch
  from torch.autograd import gradcheck
  from ludwig.constants import IGNORE_INDEX_TOKEN_ID
  from ludwig.utils.entmax.losses import Entmax15Loss, EntmaxBisectLoss, SparsemaxBisectLoss, SparsemaxLoss
label_desc: Use image node_id 3 for calling a global function with example usage: test_index_ignored(Loss) without return types