code: def compute_intent_slot_metrics(
      frame_pairs: Sequence[FramePredictionPair],
      tree_based: bool,
      overall_metrics: bool = True,
  ) -> IntentSlotMetrics:
      """
      Given a list of predicted and gold intent frames, computes precision, recall and F1
      metrics for intents and slots, either in tree-based or bracket-based manner.
  
      The following assumptions are taken on intent frames:
      1. The root node is an intent,
      2. Children of intents are always slots, and children of slots are always intents.
  
      For tree-based metrics, a node (an intent or slot) in the predicted frame is
      considered a true positive only if the subtree rooted at this node has an exact copy
      in the gold frame, otherwise it is considered a false positive. A false negative is
      a node in the gold frame that does not have an exact subtree match in the predicted
      frame.
  
      For bracket-based metrics, a node in the predicted frame is considered a true
      positive if there is a node in the gold frame having the same label and span (but
      not necessarily the same children). The definitions of false positives and false
      negatives are similar to the above.
  
      Args:
          frame_pairs: List of predicted and gold intent frames.
          tree_based: Whether to compute tree-based metrics (if True) or bracket-based
              metrics (if False).
          overall_metrics: Whether to compute overall (merging intents and slots) metrics
              or not. Defaults to True.
  
      Returns:
          IntentSlotMetrics, containing precision/recall/F1 metrics for intents and slots.
      """
      intents_pairs: List[NodesPredictionPair] = []
      slots_pairs: List[NodesPredictionPair] = []
      for predicted_frame, expected_frame in frame_pairs:
          predicted = _get_intents_and_slots(
              predicted_frame, tree_based=tree_based
          )
          expected = _get_intents_and_slots(
              expected_frame, tree_based=tree_based
          )
          intents_pairs.append(
              NodesPredictionPair(predicted.intents, expected.intents)
          )
          slots_pairs.append(
              NodesPredictionPair(predicted.slots, expected.slots)
          )
      intent_confusions, intent_metrics = compute_prf1_metrics(
          intents_pairs
      )
      slot_confusions, slot_metrics = compute_prf1_metrics(slots_pairs)
  
      return IntentSlotMetrics(
          intent_metrics=intent_metrics,
          slot_metrics=slot_metrics,
          overall_metrics=(
              intent_confusions.confusions + slot_confusions.confusions
          ).compute_metrics()
          if overall_metrics
          else None,
      )
  
imports: from collections import Counter, defaultdict
  from copy import deepcopy
  from typing import AbstractSet, Any, Callable, Counter, Dict, List, NamedTuple, Optional, Sequence, Tuple
  from pytext.data.data_structures.annotation import INVALID_TREE_INTENT
  from pytext.data.data_structures.node import Node, Span
  from .None import AllConfusions, Confusions, PerLabelConfusions, PRF1Metrics, PRF1Scores, safe_division
label_desc: Use image node_id 5 for calling a global function with example usage: compute_intent_slot_metrics(frame_pairs, tree_based, overall_metrics) and returns: IntentSlotMetrics