code: def coerce_structure(shallow_tree, input_tree):
      """Coerces the containers in `input_tree` to exactly match `shallow_tree`.
  
      This method largely parallels the behavior of `nest.assert_shallow_structure`,
      but allows `namedtuples` to be interpreted as either sequences or mappings.
      It returns a structure with the container-classes found in `shallow_tree`
      and the contents of `input_tree`, such that `shallow_tree` and `input_tree`
      may be used safely in downstream calls to `nest.map_structure_up_to`.
  
      Note: this method does not currently support `expand_composites`.
  
      Example Usage:
      ```python
  
      ab = collections.namedtuple('AB', 'a b')(0, 1)
      ba = collections.namedtuple('BA', 'b a')(2, 3)
  
      coerce_structure(ab, ba)
      # -> AB(a=3, b=2)
      ```
  
      Args:
        shallow_tree: A (shallow) structure to be populated.
        input_tree: A (parallel) structure of values.
      Returns:
        A structure with containers from shallow_tree and values from input_tree.
      Raises:
        ValueError: When nested sub-structures have differing lengths.
        ValueError: When nested sub-structures have different keys.
        TypeError: When `shallow_tree` is deeper than `input_tree`
        TypeError: When nested sub-structures are incompatible (e.g., list vs dict).
      """
      try:
          return _coerce_structure(shallow_tree, input_tree)
      except (ValueError, TypeError) as e:
          str1 = str(nest.map_structure(lambda _: _DOT, shallow_tree))
          str2 = str(nest.map_structure(lambda _: _DOT, input_tree))
          raise type(e)(
              (
                  "{}\n"
                  "Entire first structure:\n{}\n"
                  "Entire second structure:\n{}"
              ).format(e, str1, str2)
          )
  
imports: import collections
  import numpy
  import tensorflow.compat.v2
  from tensorflow_probability.python.internal import prefer_static
  from tensorflow_probability.python.internal import tensor_util
  from tensorflow.python.util import nest
label_desc: Use image node_id 15 for calling a global function with example usage: coerce_structure(shallow_tree, input_tree) and returns: _coerce_structure