docstr: Instantiates a CNN that works upon some token embeddings.
  
  Args:
      embeddings: a list of token embeddings
      kernels: list of (number of kernels, kernel size)
      reproject_words: boolean value, indicating whether to reproject the token embeddings in a separate linear layer before putting them into the rnn or not
      reproject_words_dimension: output dimension of reprojecting token embeddings. If None the same output dimension as before will be taken.
      dropout: the dropout value to be used
      word_dropout: the word dropout value to be used, if 0.0 word dropout is not used
      locked_dropout: the locked dropout value to be used, if 0.0 locked dropout is not used
      fine_tune: if True, allow to finetune the embeddings.
docstr_tok: ["Instantiates","a","CNN","that","works","upon","some","token","embeddings",".","Args",":","embeddings",":","a","list","of","token","embeddings","kernels",":","list","of","(","number","of","kernels",",","kernel","size",")","reproject_words",":","boolean","value",",","indicating","whether","to","reproject","the","token","embeddings","in","a","separate","linear","layer","before","putting","them","into","the","rnn","or","not","reproject_words_dimension",":","output","dimension","of","reprojecting","token","embeddings",".","If","None","the","same","output","dimension","as","before","will","be","taken",".","dropout",":","the","dropout","value","to","be","used","word_dropout",":","the","word","dropout","value","to","be","used",",","if","0.0","word","dropout","is","not","used","locked_dropout",":","the","locked","dropout","value","to","be","used",",","if","0.0","locked","dropout","is","not","used","fine_tune",":","if","True",",","allow","to","finetune","the","embeddings","."]
code: def __init__(
      self,
      embeddings: List[TokenEmbeddings],
      kernels=((100, 3), (100, 4), (100, 5)),
      reproject_words: bool = True,
      reproject_words_dimension: Optional[int] = None,
      dropout: float = 0.5,
      word_dropout: float = 0.0,
      locked_dropout: float = 0.0,
      fine_tune: bool = True,
  ) -> None:
      """Instantiates a CNN that works upon some token embeddings.
  
      Args:
          embeddings: a list of token embeddings
          kernels: list of (number of kernels, kernel size)
          reproject_words: boolean value, indicating whether to reproject the token embeddings in a separate linear layer before putting them into the rnn or not
          reproject_words_dimension: output dimension of reprojecting token embeddings. If None the same output dimension as before will be taken.
          dropout: the dropout value to be used
          word_dropout: the word dropout value to be used, if 0.0 word dropout is not used
          locked_dropout: the locked dropout value to be used, if 0.0 locked dropout is not used
          fine_tune: if True, allow to finetune the embeddings.
      """
      super().__init__()
  
      self.embeddings: StackedEmbeddings = StackedEmbeddings(
          embeddings=embeddings
      )
      self.length_of_all_token_embeddings: int = (
          self.embeddings.embedding_length
      )
  
      self.kernels = kernels
      self.reproject_words = reproject_words
  
      self.static_embeddings = not fine_tune
  
      self.embeddings_dimension: int = (
          self.length_of_all_token_embeddings
      )
      if self.reproject_words and reproject_words_dimension is not None:
          self.embeddings_dimension = reproject_words_dimension
  
      if self.reproject_words:
          self.word_reprojection_map: Optional[
              torch.nn.Linear
          ] = torch.nn.Linear(
              self.length_of_all_token_embeddings,
              self.embeddings_dimension,
          )
          torch.nn.init.xavier_uniform_(
              self.word_reprojection_map.weight
          )
      else:
          self.word_reprojection_map = None
  
      # CNN
      self.__embedding_length: int = sum(
          [kernel_num for kernel_num, kernel_size in self.kernels]
      )
      self.convs = torch.nn.ModuleList(
          [
              torch.nn.Conv1d(
                  self.embeddings_dimension, kernel_num, kernel_size
              )
              for kernel_num, kernel_size in self.kernels
          ]
      )
      self.pool = torch.nn.AdaptiveMaxPool1d(1)
  
      self.name = "document_cnn"
  
      # dropouts
      self.dropout = (
          torch.nn.Dropout(dropout) if dropout > 0.0 else None
      )
      self.locked_dropout = (
          LockedDropout(locked_dropout)
          if locked_dropout > 0.0
          else None
      )
      self.word_dropout = (
          WordDropout(word_dropout) if word_dropout > 0.0 else None
      )
  
      self.to(flair.device)
      self.min_sequence_length = max(
          kernel_size for _, kernel_size in self.kernels
      )
      self.eval()
  
imports: import logging
  from typing import Any, Dict, List, Optional, Union, cast
  import torch
  from sklearn.feature_extraction.text import TfidfVectorizer
  from torch.nn import RNNBase
  from torch.nn.utils.rnn import pack_padded_sequence, pad_packed_sequence
  import flair
  from flair.data import Sentence
  from flair.embeddings.base import DocumentEmbeddings, load_embeddings, register_embeddings
  from flair.embeddings.token import FlairEmbeddings, StackedEmbeddings, TokenEmbeddings
  from flair.embeddings.transformer import TransformerEmbeddings, TransformerOnnxDocumentEmbeddings
  from flair.nn import LockedDropout, WordDropout
label_desc: Use image node_id 1 to create a new DocumentCNNEmbeddings object from inherited base classes: DocumentEmbeddings with example: obj = DocumentCNNEmbeddings(embeddings, kernels, reproject_words, reproject_words_dimension, dropout, word_dropout, locked_dropout, fine_tune)