code: def get_label_quality_scores(
      labels: list,
      pred_probs: list,
      *,
      tokens: Optional[list] = None,
      token_score_method: str = "self_confidence",
      sentence_score_method: str = "min",
      sentence_score_kwargs: dict = {},
  ) -> Tuple[np.ndarray, list]:
      """
      Returns overall quality scores for the labels in each sentence, as well as for the individual tokens' labels in a token classification dataset.
  
      Each score is between 0 and 1.
  
      Lower scores indicate token labels that are less likely to be correct, or sentences that are more likely to contain a mislabeled token.
  
      Parameters
      ----------
      labels:
          Nested list of given labels for all tokens, such that `labels[i]` is a list of labels, one for each token in the `i`-th sentence.
  
          For a dataset with K classes, each label must be in 0, 1, ..., K-1.
  
      pred_probs:
          List of np arrays, such that `pred_probs[i]` has shape ``(T, K)`` if the `i`-th sentence contains T tokens.
  
          Each row of `pred_probs[i]` corresponds to a token `t` in the `i`-th sentence,
          and contains model-predicted probabilities that `t` belongs to each of the K possible classes.
  
          Columns of each `pred_probs[i]` should be ordered such that the probabilities correspond to class 0, 1, ..., K-1.
  
      tokens:
          Nested list such that `tokens[i]` is a list of tokens (strings/words) that comprise the `i`-th sentence.
  
          These strings are used to annotated the returned `token_scores` object, see its documentation for more information.
  
      sentence_score_method: {"min", "softmin"}, default="min"
          Method to aggregate individual token label quality scores into a single score for the sentence.
  
          - `min`: sentence score = minimum of token scores in the sentence
          - `softmin`: sentence score = ``<s, softmax(1-s, t)>``, where `s` denotes the token label scores of the sentence, and ``<a, b> == np.dot(a, b)``.
            Here parameter `t` controls the softmax temperature, such that the score converges toward `min` as ``t -> 0``.
            Unlike `min`, `softmin` is affected by the scores of all tokens in the sentence.
  
      token_score_method: {"self_confidence", "normalized_margin", "confidence_weighted_entropy"}, default="self_confidence"
          Label quality scoring method for each token.
  
          See :py:func:`cleanlab.rank.get_label_quality_scores <cleanlab.rank.get_label_quality_scores>` documentation for more info.
  
      sentence_score_kwargs:
          Optional keyword arguments for `sentence_score_method` function (for advanced users only).
  
          See `~cleanlab.token_classification.rank._softmin_sentence_score` for more info about keyword arguments supported for that scoring method.
  
      Returns
      -------
      sentence_scores:
          Array of shape ``(N, )`` of scores between 0 and 1, one per sentence in the dataset.
  
          Lower scores indicate sentences more likely to contain a label issue.
  
      token_scores:
          List of ``pd.Series``, such that `token_info[i]` contains the
          label quality scores for individual tokens in the `i`-th sentence.
  
          If `tokens` strings were provided, they are used as index for each ``Series``.
  
      Examples
      --------
      >>> import numpy as np
      >>> from cleanlab.token_classification.rank import get_label_quality_scores
      >>> labels = [[0, 0, 1], [0, 1]]
      >>> pred_probs = [
      ...     np.array([[0.9, 0.1], [0.7, 0.3], [0.05, 0.95]]),
      ...     np.array([[0.8, 0.2], [0.8, 0.2]]),
      ... ]
      >>> sentence_scores, token_scores = get_label_quality_scores(labels, pred_probs)
      >>> sentence_scores
      array([0.7, 0.2])
      >>> token_scores
      [0    0.90
      1    0.70
      2    0.95
      dtype: float64, 0    0.8
      1    0.2
      dtype: float64]
      """
      methods = ["min", "softmin"]
      assert (
          sentence_score_method in methods
      ), "Select from the following methods:\n%s" % "\n".join(methods)
  
      labels_flatten = np.array([l for label in labels for l in label])
      pred_probs_flatten = np.array(
          [p for pred_prob in pred_probs for p in pred_prob]
      )
  
      sentence_length = [len(label) for label in labels]
  
      def nested_list(x, sentence_length):
          i = iter(x)
          return [
              [next(i) for _ in range(length)]
              for length in sentence_length
          ]
  
      token_scores = main_get_label_quality_scores(
          labels=labels_flatten,
          pred_probs=pred_probs_flatten,
          method=token_score_method,
      )
      scores_nl = nested_list(token_scores, sentence_length)
  
      if sentence_score_method == "min":
          sentence_scores = np.array(list(map(np.min, scores_nl)))
      else:
          assert sentence_score_method == "softmin"
          temperature = sentence_score_kwargs.get("temperature", 0.05)
          sentence_scores = _softmin_sentence_score(
              scores_nl, temperature=temperature
          )
  
      if tokens:
          token_info = [
              pd.Series(scores, index=token)
              for scores, token in zip(scores_nl, tokens)
          ]
      else:
          token_info = [pd.Series(scores) for scores in scores_nl]
      return sentence_scores, token_info
  
file_path: cleanlab/cleanlab/token_classification/rank.py
imports: import pandas
  import numpy
  from typing import List, Optional, Union, Tuple
  from cleanlab.rank import get_label_quality_scores
  from cleanlab.internal.numerics import softmax
label_desc: Use image node_id 1 for calling a global function with example usage: get_label_quality_scores(labels, pred_probs) and returns: sentence_scores,  token_info, unknown