class_docstr: Pipeline component for named entity linking.
  
  DOCS: https://spacy.io/api/entitylinker
docstr: Learn from a batch of documents and gold-standard information,
  updating the pipe's model. Delegates to predict and get_loss.
  
  examples (Iterable[Example]): A batch of Example objects.
  drop (float): The dropout rate.
  sgd (thinc.api.Optimizer): The optimizer.
  losses (Dict[str, float]): Optional record of the loss during training.
      Updated using the component name as the key.
  RETURNS (Dict[str, float]): The updated losses dictionary.
  
  DOCS: https://spacy.io/api/entitylinker#update
docstr_tok: ["Learn","from","a","batch","of","documents","and","gold-standard","information",",","updating","the","pipe","'s","model",".","Delegates","to","predict","and","get_loss",".","examples","(","Iterable","[","Example","]",")",":","A","batch","of","Example","objects",".","drop","(","float",")",":","The","dropout","rate",".","sgd","(","thinc.api.Optimizer",")",":","The","optimizer",".","losses","(","Dict","[","str",",","float","]",")",":","Optional","record","of","the","loss","during","training",".","Updated","using","the","component","name","as","the","key",".","RETURNS","(","Dict","[","str",",","float","]",")",":","The","updated","losses","dictionary",".","DOCS",":","https",":","\/\/spacy.io\/api\/entitylinker","#","update"]
code: def update(
      self,
      examples: Iterable[Example],
      *,
      drop: float = 0.0,
      sgd: Optional[Optimizer] = None,
      losses: Optional[Dict[str, float]] = None,
  ) -> Dict[str, float]:
      """Learn from a batch of documents and gold-standard information,
      updating the pipe's model. Delegates to predict and get_loss.
  
      examples (Iterable[Example]): A batch of Example objects.
      drop (float): The dropout rate.
      sgd (thinc.api.Optimizer): The optimizer.
      losses (Dict[str, float]): Optional record of the loss during training.
          Updated using the component name as the key.
      RETURNS (Dict[str, float]): The updated losses dictionary.
  
      DOCS: https://spacy.io/api/entitylinker#update
      """
      self.validate_kb()
      if losses is None:
          losses = {}
      losses.setdefault(self.name, 0.0)
      if not examples:
          return losses
      validate_examples(examples, "EntityLinker_v1.update")
      sentence_docs = []
      for eg in examples:
          sentences = [s for s in eg.reference.sents]
          kb_ids = eg.get_aligned("ENT_KB_ID", as_string=True)
          for ent in eg.reference.ents:
              # KB ID of the first token is the same as the whole span
              kb_id = kb_ids[ent.start]
              if kb_id:
                  try:
                      # find the sentence in the list of sentences.
                      sent_index = sentences.index(ent.sent)
                  except AttributeError:
                      # Catch the exception when ent.sent is None and provide a user-friendly warning
                      raise RuntimeError(Errors.E030) from None
                  # get n previous sentences, if there are any
                  start_sentence = max(0, sent_index - self.n_sents)
                  # get n posterior sentences, or as many < n as there are
                  end_sentence = min(
                      len(sentences) - 1, sent_index + self.n_sents
                  )
                  # get token positions
                  start_token = sentences[start_sentence].start
                  end_token = sentences[end_sentence].end
                  # append that span as a doc to training
                  sent_doc = eg.predicted[
                      start_token:end_token
                  ].as_doc()
                  sentence_docs.append(sent_doc)
      set_dropout_rate(self.model, drop)
      if not sentence_docs:
          warnings.warn(Warnings.W093.format(name="Entity Linker"))
          return losses
      sentence_encodings, bp_context = self.model.begin_update(
          sentence_docs
      )
      loss, d_scores = self.get_loss(
          sentence_encodings=sentence_encodings, examples=examples
      )
      bp_context(d_scores)
      if sgd is not None:
          self.finish_update(sgd)
      losses[self.name] += loss
      return losses
  
imports: import random
  import warnings
  from itertools import islice
  from pathlib import Path
  from typing import Any, Callable, Dict, Iterable, List, Optional, Union
  import srsly
  from thinc.api import CosineDistance, Model, Optimizer, set_dropout_rate
  from thinc.types import Floats2d
  from ...None import util
  from ...errors import Errors, Warnings
  from ...kb import Candidate, KnowledgeBase
  from ...language import Language
  from ...ml import empty_kb
  from ...scorer import Scorer
  from ...tokens import Doc, Span
  from ...training import Example, validate_examples, validate_get_examples
  from ...util import SimpleFrozenList
  from ...vocab import Vocab
  from ..pipe import deserialize_config
  from ..trainable_pipe import TrainablePipe
label_desc: Use image node_id 5 for calling the EntityLinker_v1 obj's underlying member method code with example usage: obj.update(examples) and returns: losses, losses, losses