code: def issues_from_scores(
      sentence_scores: np.ndarray,
      *,
      token_scores: Optional[list] = None,
      threshold: float = 0.1,
  ) -> Union[list, np.ndarray]:
      """
      Converts scores output by `~cleanlab.token_classification.rank.get_label_quality_scores`
      to a list of issues of similar format as output by :py:func:`token_classification.filter.find_label_issues <cleanlab.token_classification.filter.find_label_issues>`.
  
      Issues are sorted by label quality score, from most to least severe.
  
      Only considers as issues those tokens with label quality score lower than `threshold`,
      so this parameter determines the number of issues that are returned.
      This method is intended for converting the most severely mislabeled examples to a format compatible with
      ``summary`` methods like :py:func:`token_classification.summary.display_issues <cleanlab.token_classification.summary.display_issues>`.
      This method does not estimate the number of label errors since the `threshold` is arbitrary,
      for that instead use :py:func:`token_classification.filter.find_label_issues <cleanlab.token_classification.filter.find_label_issues>`,
      which estimates the label errors via Confident Learning rather than score thresholding.
  
      Parameters
      ----------
      sentence_scores:
          Array of shape `(N, )` of overall sentence scores, where `N` is the number of sentences in the dataset.
  
          Same format as the `sentence_scores` returned by `~cleanlab.token_classification.rank.get_label_quality_scores`.
  
      token_scores:
          Optional list such that `token_scores[i]` contains the individual token scores for the `i`-th sentence.
  
          Same format as the `token_scores` returned by `~cleanlab.token_classification.rank.get_label_quality_scores`.
  
      threshold:
          Tokens (or sentences, if `token_scores` is not provided) with quality scores above the `threshold` are not
          included in the result.
  
      Returns
      ---------
      issues:
          List of label issues identified by comparing quality scores to threshold, such that each element is a tuple ``(i, j)``, which
          indicates that the `j`-th token of the `i`-th sentence has a label issue.
  
          These tuples are ordered in `issues` list based on the token label quality score.
  
          Use :py:func:`token_classification.summary.display_issues <cleanlab.token_classification.summary.display_issues>`
          to view these issues within the original sentences.
  
          If `token_scores` is not provided, returns array of integer indices (rather than tuples) of the sentences whose label quality score
          falls below the `threshold` (also sorted by overall label quality score of each sentence).
  
      Examples
      --------
      >>> import numpy as np
      >>> from cleanlab.token_classification.rank import issues_from_scores
      >>> sentence_scores = np.array([0.1, 0.3, 0.6, 0.2, 0.05, 0.9, 0.8, 0.0125, 0.5, 0.6])
      >>> issues_from_scores(sentence_scores)
      array([7, 4])
  
      Changing the score threshold
  
      >>> issues_from_scores(sentence_scores, threshold=0.5)
      array([7, 4, 0, 3, 1])
  
      Providing token scores along with sentence scores finds issues at the token level
  
      >>> token_scores = [
      ...     [0.9, 0.6],
      ...     [0.0, 0.8, 0.8],
      ...     [0.8, 0.8],
      ...     [0.1, 0.02, 0.3, 0.4],
      ...     [0.1, 0.2, 0.03, 0.4],
      ...     [0.1, 0.2, 0.3, 0.04],
      ...     [0.1, 0.2, 0.4],
      ...     [0.3, 0.4],
      ...     [0.08, 0.2, 0.5, 0.4],
      ...     [0.1, 0.2, 0.3, 0.4],
      ... ]
      >>> issues_from_scores(sentence_scores, token_scores=token_scores)
      [(1, 0), (3, 1), (4, 2), (5, 3), (8, 0)]
      """
      if token_scores:
          issues_with_scores = []
          for sentence_index, scores in enumerate(token_scores):
              for token_index, score in enumerate(scores):
                  if score < threshold:
                      issues_with_scores.append(
                          (sentence_index, token_index, score)
                      )
  
          issues_with_scores = sorted(
              issues_with_scores, key=lambda x: x[2]
          )
          issues = [(i, j) for i, j, _ in issues_with_scores]
          return issues
  
      else:
          ranking = np.argsort(sentence_scores)
          cutoff = 0
          while sentence_scores[
              ranking[cutoff]
          ] < threshold and cutoff < len(ranking):
              cutoff += 1
          return ranking[:cutoff]
  
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 2 for calling a global function with example usage: issues_from_scores(sentence_scores) and returns: issues, ranking