code: def _scores_by_top_k(top_k: int, scores: np.ndarray) -> np.ndarray:
      """Returns top_k scores or raises ValueError if invalid value for top_k."""
      if scores.shape[-1] < top_k:
          raise ValueError(
              "not enough attributions were provided to perform the requested "
              "calcuations for top k. The requested value for k is {}, but the "
              "values are {}\n\nThis may be caused by a metric configuration error "
              "or an error in the pipeline.".format(top_k, scores)
          )
  
      indices = np.argpartition(scores, -top_k)[-top_k:]
      indices = indices[np.argsort(-scores[indices])]
      return scores[indices]
  
imports: import functools
  from typing import Any, Dict, Iterable, List, Optional, Union
  import apache_beam
  import numpy
  from tensorflow_model_analysis import constants
  from tensorflow_model_analysis.metrics import example_count
  from tensorflow_model_analysis.metrics import metric_specs
  from tensorflow_model_analysis.metrics import metric_types
  from tensorflow_model_analysis.metrics import metric_util
  from tensorflow_model_analysis.proto import config_pb2
  from tensorflow_model_analysis.utils import util
label_desc: Use image node_id 6 for calling a global function with example usage: _scores_by_top_k(top_k, scores) and returns: scores