code: def rank_and_mask(
      confidences: np.ndarray,
      ranking_length: int = 0,
      renormalize: bool = False,
  ) -> Tuple[np.ndarray, np.ndarray]:
      """Computes a ranking of the given confidences.
  
      First, it computes a list containing the indices that would sort all the given
      confidences in decreasing order.
      If a `ranking_length` is specified, then only the indices for the `ranking_length`
      largest confidences will be returned and all other confidences (i.e. whose indices
      we do not return) will be masked by setting them to 0.
      Moreover, if `renormalize` is set to `True`, then the confidences will
      additionally be renormalised by dividing them by their sum.
  
      We assume that the given confidences sum up to 1 and, if the
      `ranking_length` is 0 or larger than the given number of confidences,
      we set the `ranking_length` to the number of confidences.
      Hence, in this case the confidences won't be modified.
  
      Args:
          confidences: a 1-d array of confidences that are non-negative and sum up to 1
          ranking_length: the size of the ranking to be computed. If set to 0 or
              something larger than the number of given confidences, then this is set
              to the exact number of given confidences.
          renormalize: determines whether the masked confidences should be renormalised.
          return_indices:
      Returns:
          indices of the top `ranking_length` confidences and an array of the same
          shape as the given confidences that contains the possibly masked and
          renormalized confidence values
      """
      indices = confidences.argsort()[::-1]
      confidences = confidences.copy()
  
      if 0 < ranking_length < len(confidences):
          confidences[indices[ranking_length:]] = 0
  
          if renormalize and np.sum(confidences) > 0:
              confidences = confidences / np.sum(confidences)
  
          indices = indices[:ranking_length]
  
      return indices, confidences
  
imports: from pathlib import Path
  import numpy
  from typing import Optional, Text, Dict, Any, Union, List, Tuple, TYPE_CHECKING
  import rasa.shared.utils.common
  import rasa.shared.utils.io
  import rasa.nlu.utils.bilou_utils
  from rasa.shared.constants import NEXT_MAJOR_VERSION_FOR_DEPRECATIONS
  from rasa.nlu.constants import NUMBER_OF_SUB_TOKENS
  import rasa.utils.io
  from rasa.utils.tensorflow.constants import LOSS_TYPE, RANKING_LENGTH, RENORMALIZE_CONFIDENCES, SIMILARITY_TYPE, EVAL_NUM_EXAMPLES, EVAL_NUM_EPOCHS, EPOCHS, SOFTMAX, MARGIN, AUTO, INNER, COSINE, SEQUENCE, CROSS_ENTROPY, CONSTRAIN_SIMILARITIES, MODEL_CONFIDENCE, TOLERANCE, CHECKPOINT_MODEL
  from rasa.utils.tensorflow.callback import RasaTrainingLogger, RasaModelCheckpoint
  from rasa.utils.tensorflow.data_generator import RasaBatchDataGenerator
  from rasa.utils.tensorflow.model_data import RasaModelData
  from rasa.shared.nlu.constants import SPLIT_ENTITIES_BY_COMMA
  from rasa.shared.exceptions import InvalidConfigException
label_desc: Use image node_id 1 for calling a global function with example usage: rank_and_mask(confidences, ranking_length, renormalize) and returns: indices,  confidences