code: def get_traverse_shallow_structure(traverse_fn, structure):
      """Generates a shallow structure from a `traverse_fn` and `structure`.
  
      `traverse_fn` must accept any possible subtree of `structure` and return
      a depth=1 structure containing `True` or `False` values, describing which
      of the top-level subtrees may be traversed.  It may also
      return scalar `True` or `False` 'traversal is OK / not OK for all subtrees.'
  
      Examples are available in the unit tests (nest_test.py).
  
      Args:
        traverse_fn: Function taking a substructure and returning either a scalar
          `bool` (whether to traverse that substructure or not) or a depth=1 shallow
          structure of the same type, describing which parts of the substructure to
          traverse.
        structure: The structure to traverse.
  
      Returns:
        A shallow structure containing python bools, which can be passed to
        `map_up_to` and `flatten_up_to`.
  
      Raises:
        TypeError: if `traverse_fn` returns a sequence for a non-sequence input,
          or a structure with depth higher than 1 for a sequence input,
          or if any leaf values in the returned structure or scalar are not type
          `bool`.
      """
  
      def outer_traverse_fn(subtree):
          res = traverse_fn(subtree)
          if is_nested(res):
  
              def inner_traverse_fn(do_traverse, subtree):
                  if do_traverse:
                      return dm_tree.traverse(
                          outer_traverse_fn, subtree
                      )
                  else:
                      return _FALSE_SENTINEL
  
              return dm_tree.map_structure_up_to(
                  res, inner_traverse_fn, res, subtree
              )
          else:
              return None if res else _FALSE_SENTINEL
  
      return map_structure(
          lambda x: False if x is _FALSE_SENTINEL else True,
          dm_tree.traverse(outer_traverse_fn, structure),
      )
  
imports: import collections
  from collections import abc
  import types
  import tree
label_desc: Use image node_id 7 for calling a global function with example usage: get_traverse_shallow_structure(traverse_fn, structure) and returns: map_structure, dm_tree, unknown, dm_tree, _FALSE_SENTINEL