code: def build_model(
      config: Union[str, Path, dict],
      mode: str = "infer",
      load_trained: bool = False,
      install: bool = False,
      download: bool = False,
  ) -> Chainer:
      """Build and return the model described in corresponding configuration file."""
      config = parse_config(config)
  
      if install:
          install_from_config(config)
      if download:
          deep_download(config)
  
      import_packages(config.get("metadata", {}).get("imports", []))
  
      model_config = config["chainer"]
  
      model = Chainer(
          model_config["in"],
          model_config["out"],
          model_config.get("in_y"),
      )
  
      for component_config in model_config["pipe"]:
          if load_trained and (
              "fit_on" in component_config or "in_y" in component_config
          ):
              try:
                  component_config["load_path"] = component_config[
                      "save_path"
                  ]
              except KeyError:
                  log.warning(
                      'No "save_path" parameter for the {} component, so "load_path" will not be renewed'.format(
                          component_config.get(
                              "class_name",
                              component_config.get("ref", "UNKNOWN"),
                          )
                      )
                  )
  
          component = from_params(component_config, mode=mode)
  
          if "id" in component_config:
              model._components_dict[component_config["id"]] = component
  
          if "in" in component_config:
              c_in = component_config["in"]
              c_out = component_config["out"]
              in_y = component_config.get("in_y", None)
              main = component_config.get("main", False)
              model.append(component, c_in, c_out, in_y, main)
  
      return model
  
file_path: DeepPavlov/deeppavlov/core/commands/infer.py
imports: import json
  import sys
  from itertools import islice
  from logging import getLogger
  from pathlib import Path
  from typing import Optional, Union
  from deeppavlov.core.commands.utils import import_packages, parse_config
  from deeppavlov.core.common.chainer import Chainer
  from deeppavlov.core.common.params import from_params
  from deeppavlov.core.data.utils import jsonify_data
  from deeppavlov.download import deep_download
  from deeppavlov.utils.pip_wrapper import install_from_config
label_desc: Use image node_id 1 for calling a global function with example usage: build_model(config, mode, load_trained, install, download) and returns: model