class_docstr: Entity Linking Model.
  
  The model expects text/sentences with annotated entity mentions and predicts entities to these mentions.
  To this end a word embedding is used to embed the sentences and the embedding of the entity mention goes through a linear layer to get the actual class label.
  The model is able to predict '<unk>' for entity mentions that the model can not confidently match to any of the known labels.
docstr: Initializes an EntityLinker.
  
  Args:
      embeddings: embeddings used to embed the tokens of the sentences.
      label_dictionary: dictionary that gives ids to all classes. Should contain <unk>.
      pooling_operation: either `average`, `first`, `last` or `first_last`. Specifies the way of how text
          representations of entity mentions (with more than one token) are handled. E.g. `average` means that as
          text representation we take the average of the embeddings of the token in the mention.
          `first_last` concatenates the embedding of the first and the embedding of the last token.
      label_type: name of the label you use.
      candidates: If provided, use a :class:`CandidateGenerator` for prediction candidates.
      **classifierargs: The arguments propagated to :meth:`flair.nn.DefaultClassifier.__init__`
docstr_tok: ["Initializes","an","EntityLinker",".","Args",":","embeddings",":","embeddings","used","to","embed","the","tokens","of","the","sentences",".","label_dictionary",":","dictionary","that","gives","ids","to","all","classes",".","Should","contain","<","unk",">",".","pooling_operation",":","either","`","average","`",",","`","first","`",",","`","last","`","or","`","first_last","`",".","Specifies","the","way","of","how","text","representations","of","entity","mentions","(","with","more","than","one","token",")","are","handled",".","E.g",".","`","average","`","means","that","as","text","representation","we","take","the","average","of","the","embeddings","of","the","token","in","the","mention",".","`","first_last","`","concatenates","the","embedding","of","the","first","and","the","embedding","of","the","last","token",".","label_type",":","name","of","the","label","you","use",".","candidates",":","If","provided",",","use","a",":","class",":","`","CandidateGenerator","`","for","prediction","candidates",".","*","*","classifierargs",":","The","arguments","propagated","to",":","meth",":","`","flair.nn.DefaultClassifier.__init__","`"]
code: def __init__(
      self,
      embeddings: flair.embeddings.TokenEmbeddings,
      label_dictionary: Dictionary,
      pooling_operation: str = "first_last",
      label_type: str = "nel",
      candidates: Optional[CandidateGenerator] = None,
      **classifierargs,
  ) -> None:
      """Initializes an EntityLinker.
  
      Args:
          embeddings: embeddings used to embed the tokens of the sentences.
          label_dictionary: dictionary that gives ids to all classes. Should contain <unk>.
          pooling_operation: either `average`, `first`, `last` or `first_last`. Specifies the way of how text
              representations of entity mentions (with more than one token) are handled. E.g. `average` means that as
              text representation we take the average of the embeddings of the token in the mention.
              `first_last` concatenates the embedding of the first and the embedding of the last token.
          label_type: name of the label you use.
          candidates: If provided, use a :class:`CandidateGenerator` for prediction candidates.
          **classifierargs: The arguments propagated to :meth:`flair.nn.DefaultClassifier.__init__`
      """
      super().__init__(
          embeddings=embeddings,
          label_dictionary=label_dictionary,
          final_embedding_size=embeddings.embedding_length * 2
          if pooling_operation == "first_last"
          else embeddings.embedding_length,
          **classifierargs,
      )
  
      self.pooling_operation = pooling_operation
      self._label_type = label_type
  
      cases: Dict[str, Callable[[Span, List[str]], torch.Tensor]] = {
          "average": self.emb_mean,
          "first": self.emb_first,
          "last": self.emb_last,
          "first_last": self.emb_firstAndLast,
      }
  
      if pooling_operation not in cases:
          raise KeyError(
              'pooling_operation has to be one of "average", "first", "last" or "first_last"'
          )
  
      self.aggregated_embedding = cases[pooling_operation]
  
      self.candidates = candidates
  
      self.to(flair.device)
  
imports: import logging
  import re
  from functools import lru_cache
  from pathlib import Path
  from typing import Any, Callable, Dict, List, Optional, Set, Union
  from unicodedata import category
  import torch
  import flair.embeddings
  import flair.nn
  from flair.data import Dictionary, Sentence, Span
  from flair.file_utils import cached_path
label_desc: Use image node_id 1 to create a new SpanClassifier object from inherited base classes: flair.nn.DefaultClassifier with example: obj = SpanClassifier(embeddings, label_dictionary, pooling_operation, label_type, candidates)