code: def _clean_kwargs(
      loss_name: str,
      kwargs: Optional[Dict[str, Any]],
      init_method: Callable,
      ignore_params: Optional[Set[str]] = None,
  ) -> Dict[str, Any]:
      """
      Cleans kwargs for the given loss function. Warn if there are unused kwargs.
  
      Args:
          loss_name: name of the loss function
          kwargs: kwargs to clean
          init_method: LossClass.__init__ method
          ignore_params: set of argument names for init_method to ignore
  
      Returns:
          only used kwargs for the given `init_method`
      """
      if not kwargs:
          return {}
      init_params = set(
          inspect.signature(init_method).parameters.keys()
      ) - {"self"}
      if ignore_params is not None:
          init_params -= ignore_params
      unused_kwargs = dict()
      used_kwargs = dict()
      for key, value in kwargs.items():
          if key not in init_params:
              unused_kwargs[key] = value
          else:
              used_kwargs[key] = value
      if len(unused_kwargs) > 0:
          _warn_unused_additional_kwargs(loss_name, unused_kwargs)
      return used_kwargs
  
imports: import inspect
  import operator
  from dataclasses import dataclass
  from typing import Any, Callable, Dict, List, Optional, Set
  import torch
  from omegaconf import DictConfig, OmegaConf
  from nemo.collections.asr.losses.rnnt_pytorch import MultiblankRNNTLossPytorch, RNNTLossPytorch, TDTLossPytorch
  from nemo.core.classes import Loss, typecheck
  from nemo.core.neural_types import LabelsType, LengthsType, LogprobsType, LossType, NeuralType
  from nemo.core.utils import numba_utils
  from nemo.core.utils.k2_utils import K2_INSTALLATION_MESSAGE
  from nemo.core.utils.numba_utils import NUMBA_INSTALLATION_MESSAGE
  from nemo.utils import logging, logging_mode, model_utils
label_desc: Use image node_id 2 for calling a global function with example usage: _clean_kwargs(loss_name, kwargs, init_method, ignore_params) and returns: used_kwargs, dict