code: def _get_intents_and_slots(
      frame: Node, tree_based: bool
  ) -> IntentsAndSlots:
      intents: Counter[Node] = counter()
      slots: Counter[Node] = counter()
  
      def process_node(node: Node, is_intent: bool) -> None:
          for child in node.children:
              process_node(child, not is_intent)
          if not tree_based:
              node = type(node)(
                  node.label, deepcopy(node.span), text=node.text
              )
          if is_intent:
              intents[node] += 1
          else:
              slots[node] += 1
  
      process_node(frame, True)
      return IntentsAndSlots(intents=intents, slots=slots)
  
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 2 for calling a global function with example usage: _get_intents_and_slots(frame, tree_based) and returns: IntentsAndSlots