code: def _tag_to_use(
      relevant_tags: List[Text], relevant_confidences: List[float]
  ) -> Tuple[Text, float]:
      """Decide what tag to use according to the following metric:
  
      Calculate the average confidence per tag.
      Calculate the percentage of tokens assigned to a tag within the entity per tag.
      The harmonic mean of those two metrics is the score for the tag.
      The tag with the highest score is taken as the tag for the entity.
  
      Args:
          relevant_tags: The tags of the entity.
          relevant_confidences: The confidence values.
  
      Returns:
          The tag to use. The score of that tag.
      """
      # Calculate the average confidence per tag.
      avg_confidence_per_tag = _avg_confidence_per_tag(
          relevant_tags, relevant_confidences
      )
      # Calculate the percentage of tokens assigned to a tag per tag.
      tag_counts = Counter(relevant_tags)
      token_percentage_per_tag: Dict[Text, float] = {}
      for tag, count in tag_counts.items():
          token_percentage_per_tag[tag] = round(
              count / len(relevant_tags), 2
          )
  
      # Calculate the harmonic mean between the two metrics per tag.
      score_per_tag = {}
      for tag, token_percentage in token_percentage_per_tag.items():
          avg_confidence = avg_confidence_per_tag[tag]
          score_per_tag[tag] = (
              2
              * (avg_confidence * token_percentage)
              / (avg_confidence + token_percentage)
          )
  
      # Take the tag with the highest score as the tag for the entity
      tag, score = max(
          score_per_tag.items(), key=operator.itemgetter(1)
      )
  
      return tag, score
  
imports: import logging
  import operator
  from collections import defaultdict, Counter
  from typing import List, Tuple, Text, Optional, Dict, Any, TYPE_CHECKING
  from rasa.nlu.constants import TOKENS_NAMES, BILOU_ENTITIES, BILOU_ENTITIES_GROUP, BILOU_ENTITIES_ROLE
  from rasa.shared.nlu.constants import TEXT, ENTITIES, ENTITY_ATTRIBUTE_START, ENTITY_ATTRIBUTE_END, ENTITY_ATTRIBUTE_TYPE, ENTITY_ATTRIBUTE_GROUP, ENTITY_ATTRIBUTE_ROLE, NO_ENTITY_TAG
label_desc: Use image node_id 12 for calling a global function with example usage: _tag_to_use(relevant_tags, relevant_confidences) and returns: tag,  score