code: def get_margin_for_input(
      margin_config: Optional[JsonDict] = None,
      inp: Optional[JsonDict] = None,
  ) -> float:
      """Returns the margin value given a margin config and input example."""
      # When no margin config provided, then the margin of 0 indicates that the
      # class with the highest score is the predicted class.
      if not margin_config:
          return 0
  
      # Check each facet in the margin config to see if the input matches the
      # facet. If so, then use the margin value for that facet from the config.
      for margin_entry in margin_config.values():
          facet_info = (
              margin_entry["facetData"]["facets"]
              if "facetData" in margin_entry
              else {}
          )
          match = True
          if inp:
              for feat, facet_info in facet_info.items():
                  value = facet_info["val"]
                  if isinstance(
                      inp[feat], numbers.Number
                  ) and not isinstance(inp[feat], bool):
                      # If the facet is a numeric range string, extract the min and max
                      # and check the value against that range.
                      min_val = value[0]
                      max_val = value[1]
                      if not (
                          inp[feat] >= min_val and inp[feat] < max_val
                      ):
                          match = False
                          break
                  # If the facet is a standard value, check the feature value for
                  # equality to it.
                  elif inp[feat] != value:
                      match = False
                      break
          if match:
              return margin_entry["margin"]
      return 0
  
file_path: lit/lit_nlp/components/classification_results.py
imports: from collections.abc import Sequence
  import numbers
  from typing import cast, Optional
  from lit_nlp.api import components
  from lit_nlp.api import dataset
  from lit_nlp.api import dtypes
  from lit_nlp.api import model
  from lit_nlp.api import types
  from lit_nlp.lib import utils
  import numpy
label_desc: Use image node_id 1 for calling a global function with example usage: get_margin_for_input(margin_config, inp) and returns: int, int, margin_entry