code: def init(
      model: Model[InT, OutT],
      X: Optional[InT] = None,
      Y: Optional[OutT] = None,
  ) -> None:
      if X is None and Y is None:
          for layer in model.layers:
              layer.initialize()
          if model.layers[0].has_dim("nI"):
              model.set_dim("nI", model.layers[0].get_dim("nI"))
          if model.layers[-1].has_dim("nO"):
              model.set_dim("nO", model.layers[-1].get_dim("nO"))
  
      # Try to set nO on each layer, where available.
      # Shape inference is tricky, especially for the output. The policy is:
      # if a layer has an unset nO, we use the final Y (if provided). For other
      # layers, Y=None.
      curr_input = X
      for layer in model.layers:
          if layer.has_dim("nO") is None:
              layer.initialize(X=curr_input, Y=Y)
          else:
              layer.initialize(X=curr_input)
          if curr_input is not None:
              curr_input = layer.predict(curr_input)
  
      if model.layers[0].has_dim("nI"):
          model.set_dim("nI", model.layers[0].get_dim("nI"))
      if model.has_dim("nO") is None:
          try:
              nO = get_width(curr_input)  # type: ignore[arg-type]
              model.set_dim("nO", nO)
          except ValueError:
              if model.layers[-1].has_dim("nO"):
                  nO = model.layers[-1].get_dim("nO")
                  model.set_dim("nO", nO)
  
file_path: thinc/thinc/layers/chain.py
imports: from typing import Any, Callable, Dict, List, Optional, Tuple, TypeVar, cast
  from ..config import registry
  from ..model import Model
  from ..types import XY_YZ_OutT
  from ..util import get_width
label_desc: Use image node_id 4 for calling a global function with example usage: init(model, X, Y) without return types