class_docstr: Pipeline component for named entity linking.
  
  DOCS: https://spacy.io/api/entitylinker
docstr: Apply the pipeline's model to a batch of docs, without modifying them.
  Returns the KB IDs for each entity in each doc, including NIL if there is
  no prediction.
  
  docs (Iterable[Doc]): The documents to predict.
  RETURNS (List[str]): The models prediction for each document.
  
  DOCS: https://spacy.io/api/entitylinker#predict
docstr_tok: ["Apply","the","pipeline","'s","model","to","a","batch","of","docs",",","without","modifying","them",".","Returns","the","KB","IDs","for","each","entity","in","each","doc",",","including","NIL","if","there","is","no","prediction",".","docs","(","Iterable","[","Doc","]",")",":","The","documents","to","predict",".","RETURNS","(","List","[","str","]",")",":","The","models","prediction","for","each","document",".","DOCS",":","https",":","\/\/spacy.io\/api\/entitylinker","#","predict"]
code: def predict(self, docs: Iterable[Doc]) -> List[str]:
      """Apply the pipeline's model to a batch of docs, without modifying them.
      Returns the KB IDs for each entity in each doc, including NIL if there is
      no prediction.
  
      docs (Iterable[Doc]): The documents to predict.
      RETURNS (List[str]): The models prediction for each document.
  
      DOCS: https://spacy.io/api/entitylinker#predict
      """
      self.validate_kb()
      entity_count = 0
      final_kb_ids: List[str] = []
      if not docs:
          return final_kb_ids
      if isinstance(docs, Doc):
          docs = [docs]
      for i, doc in enumerate(docs):
          sentences = [s for s in doc.sents]
          if len(doc) > 0:
              # Looping through each entity (TODO: rewrite)
              for ent in doc.ents:
                  sent = ent.sent
                  sent_index = sentences.index(sent)
                  assert sent_index >= 0
                  # get n_neighbour sentences, clipped to the length of the document
                  start_sentence = max(0, sent_index - self.n_sents)
                  end_sentence = min(
                      len(sentences) - 1, sent_index + self.n_sents
                  )
                  start_token = sentences[start_sentence].start
                  end_token = sentences[end_sentence].end
                  sent_doc = doc[start_token:end_token].as_doc()
                  # currently, the context is the same for each entity in a sentence (should be refined)
                  xp = self.model.ops.xp
                  if self.incl_context:
                      sentence_encoding = self.model.predict(
                          [sent_doc]
                      )[0]
                      sentence_encoding_t = sentence_encoding.T
                      sentence_norm = xp.linalg.norm(
                          sentence_encoding_t
                      )
                  entity_count += 1
                  if ent.label_ in self.labels_discard:
                      # ignoring this entity - setting to NIL
                      final_kb_ids.append(self.NIL)
                  else:
                      candidates = list(
                          self.get_candidates(self.kb, ent)
                      )
                      if not candidates:
                          # no prediction possible for this entity - setting to NIL
                          final_kb_ids.append(self.NIL)
                      elif len(candidates) == 1:
                          # shortcut for efficiency reasons: take the 1 candidate
                          final_kb_ids.append(candidates[0].entity_)
                      else:
                          random.shuffle(candidates)
                          # set all prior probabilities to 0 if incl_prior=False
                          prior_probs = xp.asarray(
                              [c.prior_prob for c in candidates]
                          )
                          if not self.incl_prior:
                              prior_probs = xp.asarray(
                                  [0.0 for _ in candidates]
                              )
                          scores = prior_probs
                          # add in similarity from the context
                          if self.incl_context:
                              entity_encodings = xp.asarray(
                                  [c.entity_vector for c in candidates]
                              )
                              entity_norm = xp.linalg.norm(
                                  entity_encodings, axis=1
                              )
                              if len(entity_encodings) != len(
                                  prior_probs
                              ):
                                  raise RuntimeError(
                                      Errors.E147.format(
                                          method="predict",
                                          msg="vectors not of equal length",
                                      )
                                  )
                              # cosine similarity
                              sims = xp.dot(
                                  entity_encodings, sentence_encoding_t
                              ) / (sentence_norm * entity_norm)
                              if sims.shape != prior_probs.shape:
                                  raise ValueError(Errors.E161)
                              scores = (
                                  prior_probs
                                  + sims
                                  - (prior_probs * sims)
                              )
                          best_index = scores.argmax().item()
                          best_candidate = candidates[best_index]
                          final_kb_ids.append(best_candidate.entity_)
      if not (len(final_kb_ids) == entity_count):
          err = Errors.E147.format(
              method="predict",
              msg="result variables not of equal length",
          )
          raise RuntimeError(err)
      return final_kb_ids
  
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 7 for calling the EntityLinker_v1 obj's underlying member method code with example usage: obj.predict(docs) and returns: final_kb_ids, final_kb_ids