code: def replace_innermost(
      ntuple,
      return_unused=False,
      nested_lookup_fn=get_nested_objs,
      **kw,
  ):
      """Replace (nested) fields in a `namedtuple`.
  
      For each attribute-value update specified, this function only replaces the
      first matching attribute found. Nested objects are traversed depth-first in
      post-order, with level-wise order determined by the list ordering returned
      from `nested_lookup_fn`.
  
      Args:
        ntuple: A `namedtuple` to replace (nested) fields in.
        return_unused: If `True`, return the `dict` of attribute-value pairs in
         `**kw` that were not found and updated in `ntuple`.
        nested_lookup_fn: A single-argument callable that returns a list of
          (attribute name, nested object) pairs. Defaults to `get_nested_objs`.
        **kw: The attribute-value pairs to update.
  
      Returns:
        updated: A copy of `ntuple` with (nested) fields updated.
        unused: If `return_unused` is `True`, the dictionary of attribute-value
          pairs in `**kw` that were not found and updated in `ntuple`.
  
      Raises:
        ValueError: if `returne_unused=False` and attributes in `**kw` are not found
          in `ntuple`.
      """
      nested_updates = {}
      for fieldname, nested in nested_lookup_fn(ntuple):
          updated, kw = replace_innermost(
              nested,
              return_unused=True,
              nested_lookup_fn=nested_lookup_fn,
              **kw,
          )
          nested_updates[fieldname] = updated
      kw.update(nested_updates)
      if not return_unused:
          return ntuple._replace(**kw)
      outer_updates = {
          attr: kw[attr] for attr in ntuple._fields if attr in kw
      }
      extra = {
          attr: val
          for attr, val in kw.items()
          if attr not in outer_updates
      }
      return ntuple._replace(**outer_updates), extra
  
file_path: probability/tensorflow_probability/python/internal/unnest.py
imports: import collections
label_desc: Use image node_id 5 for calling a global function with example usage: replace_innermost(ntuple, return_unused, nested_lookup_fn) and returns: ntuple,  extra, ntuple