code: def _to_metadata(
      d: Dict[str, Any]
  ) -> Union[ParameterMetadata, Dict[str, Any]]:
      is_nested = False
      for k, v in list(d.items()):
          if isinstance(v, dict):
              d[k] = _to_metadata(v)
              is_nested = True
  
      if is_nested:
          return d
  
      return ParameterMetadata.from_dict(d)
  
imports: import os
  from typing import Any, Dict, Union
  import yaml
  from ludwig.schema.metadata.parameter_metadata import ParameterMetadata
label_desc: Use image node_id 1 for calling a global function with example usage: _to_metadata(d) and returns: ParameterMetadata, d