code: def evaluate(
      model: str,
      data_path: Path,
      output: Optional[Path] = None,
      use_gpu: int = -1,
      gold_preproc: bool = False,
      displacy_path: Optional[Path] = None,
      displacy_limit: int = 25,
      silent: bool = True,
      spans_key: str = "sc",
      per_component: bool = False,
  ) -> Dict[str, Any]:
      msg = Printer(no_print=silent, pretty=not silent)
      fix_random_seed()
      setup_gpu(use_gpu, silent=silent)
      data_path = util.ensure_path(data_path)
      output_path = util.ensure_path(output)
      displacy_path = util.ensure_path(displacy_path)
      if not data_path.exists():
          msg.fail("Evaluation data not found", data_path, exits=1)
      if displacy_path and not displacy_path.exists():
          msg.fail(
              "Visualization output directory not found",
              displacy_path,
              exits=1,
          )
      corpus = Corpus(data_path, gold_preproc=gold_preproc)
      nlp = util.load_model(model)
      dev_dataset = list(corpus(nlp))
      scores = nlp.evaluate(dev_dataset, per_component=per_component)
      if per_component:
          data = scores
          if output is None:
              msg.warn(
                  "The per-component option is enabled but there is no output JSON file provided to save the scores to."
              )
          else:
              msg.info(
                  "Per-component scores will be saved to output JSON file."
              )
      else:
          metrics = {
              "TOK": "token_acc",
              "TAG": "tag_acc",
              "POS": "pos_acc",
              "MORPH": "morph_acc",
              "LEMMA": "lemma_acc",
              "UAS": "dep_uas",
              "LAS": "dep_las",
              "NER P": "ents_p",
              "NER R": "ents_r",
              "NER F": "ents_f",
              "TEXTCAT": "cats_score",
              "SENT P": "sents_p",
              "SENT R": "sents_r",
              "SENT F": "sents_f",
              "SPAN P": f"spans_{spans_key}_p",
              "SPAN R": f"spans_{spans_key}_r",
              "SPAN F": f"spans_{spans_key}_f",
              "SPEED": "speed",
          }
          results = {}
          data = {}
          for metric, key in metrics.items():
              if key in scores:
                  if key == "cats_score":
                      metric = (
                          metric
                          + " ("
                          + scores.get("cats_score_desc", "unk")
                          + ")"
                      )
                  if isinstance(scores[key], (int, float)):
                      if key == "speed":
                          results[metric] = f"{scores[key]:.0f}"
                      else:
                          results[metric] = f"{scores[key]*100:.2f}"
                  else:
                      results[metric] = "-"
                  data[re.sub(r"[\s/]", "_", key.lower())] = scores[key]
  
          msg.table(results, title="Results")
          data = handle_scores_per_type(
              scores, data, spans_key=spans_key, silent=silent
          )
  
      if displacy_path:
          factory_names = [
              nlp.get_pipe_meta(pipe).factory for pipe in nlp.pipe_names
          ]
          docs = list(
              nlp.pipe(
                  ex.reference.text
                  for ex in dev_dataset[:displacy_limit]
              )
          )
          render_deps = "parser" in factory_names
          render_ents = "ner" in factory_names
          render_spans = "spancat" in factory_names
  
          render_parses(
              docs,
              displacy_path,
              model_name=model,
              limit=displacy_limit,
              deps=render_deps,
              ents=render_ents,
              spans=render_spans,
          )
          msg.good(
              f"Generated {displacy_limit} parses as HTML",
              displacy_path,
          )
  
      if output_path is not None:
          srsly.write_json(output_path, data)
          msg.good(f"Saved results to {output_path}")
      return data
  
file_path: spacy/spacy/cli/evaluate.py
imports: import re
  from pathlib import Path
  from typing import Any, Dict, List, Optional, Union
  import srsly
  from thinc.api import fix_random_seed
  from wasabi import Printer
  from ..None import displacy, util
  from ..scorer import Scorer
  from ..tokens import Doc
  from ..training import Corpus
  from ._util import Arg, Opt, app, benchmark_cli, import_code, setup_gpu
label_desc: Use image node_id 2 for calling a global function with example usage: evaluate(model, data_path, output, use_gpu, gold_preproc, displacy_path, displacy_limit, silent, spans_key, per_component) and returns: data