code: def _get_ranks_for_sequence(
      logits: np.ndarray, labels: np.ndarray
  ) -> List[float]:
      """Returns ranks for a sequence.
  
      Args:
        logits: Logits of a single sequence, dim = (num_tokens, vocab_size).
        labels: Target labels of a single sequence, dim = (num_tokens, 1).
  
      Returns:
        An array of ranks for tokens in the sequence, dim = (num_tokens, 1).
      """
      sequence_ranks = []
      for logit, label in zip(logits, labels.astype(int)):
          rank = stats.rankdata(-logit, method="min")[label] - 1.0
          sequence_ranks.append(rank)
  
      return sequence_ranks
  
imports: import dataclasses
  from typing import Iterator, List, Optional, Tuple
  import numpy
  from scipy import stats
  import tensorflow
  from tensorflow_privacy.privacy.privacy_tests.membership_inference_attack import membership_inference_attack
  from tensorflow_privacy.privacy.privacy_tests.membership_inference_attack.data_structures import AttackInputData
  from tensorflow_privacy.privacy.privacy_tests.membership_inference_attack.data_structures import AttackResults
  from tensorflow_privacy.privacy.privacy_tests.membership_inference_attack.data_structures import AttackType
  from tensorflow_privacy.privacy.privacy_tests.membership_inference_attack.data_structures import PrivacyReportMetadata
label_desc: Use image node_id 4 for calling a global function with example usage: _get_ranks_for_sequence(logits, labels) and returns: sequence_ranks