code: def chain(
      layer1: Model[InT, MidT],
      layer2: Model[MidT, Any],
      *layers: Model[Any, Any],
  ) -> Model[InT, XY_YZ_OutT]:
      """Compose two models `f` and `g` such that they become layers of a single
      feed-forward model that computes `g(f(x))`.
      Also supports chaining more than 2 layers.
      Note that the type checking for additional layers is carried out by the Thinc Mypy plugin.
      """
      all_layers: List[Model[Any, Any]] = [layer1, layer2]
      all_layers.extend(layers)
      dims: Dict[str, Optional[int]] = {"nO": None}
      # set input dimension only if first layer has one - should be "False" otherwise
      if all_layers[0].has_dim("nI") is True:
          dims["nI"] = all_layers[0].get_dim("nI")
      if all_layers[0].has_dim("nI") is None:
          dims["nI"] = None
      # set output dimension according to last layer
      if all_layers[-1].has_dim("nO") is True:
          dims["nO"] = all_layers[-1].get_dim("nO")
  
      model: Model[InT, XY_YZ_OutT] = Model(
          ">>".join(layer.name for layer in all_layers),
          forward,
          init=init,
          dims=dims,
          layers=all_layers,
      )
      return model
  
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 2 for calling a global function with example usage: chain(layer1, layer2) and returns: model