docstr: Instantiates an RNN that works upon some token embeddings.
  
  Args:
      embeddings: a list of token embeddings
      hidden_size: the number of hidden states in the rnn
      rnn_layers: the number of layers for the rnn
      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.
      bidirectional: boolean value, indicating whether to use a bidirectional rnn or not
      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
      rnn_type: 'GRU' or 'LSTM'
      fine_tune: if True, allow to finetune the embeddings.
docstr_tok: ["Instantiates","an","RNN","that","works","upon","some","token","embeddings",".","Args",":","embeddings",":","a","list","of","token","embeddings","hidden_size",":","the","number","of","hidden","states","in","the","rnn","rnn_layers",":","the","number","of","layers","for","the","rnn","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",".","bidirectional",":","boolean","value",",","indicating","whether","to","use","a","bidirectional","rnn","or","not","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","rnn_type",":","'GRU","'","or","'LSTM'","fine_tune",":","if","True",",","allow","to","finetune","the","embeddings","."]
code: def __init__(
      self,
      embeddings: List[TokenEmbeddings],
      hidden_size=128,
      rnn_layers=1,
      reproject_words: bool = True,
      reproject_words_dimension: Optional[int] = None,
      bidirectional: bool = False,
      dropout: float = 0.5,
      word_dropout: float = 0.0,
      locked_dropout: float = 0.0,
      rnn_type: str = "GRU",
      fine_tune: bool = True,
  ) -> None:
      """Instantiates an RNN that works upon some token embeddings.
  
      Args:
          embeddings: a list of token embeddings
          hidden_size: the number of hidden states in the rnn
          rnn_layers: the number of layers for the rnn
          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.
          bidirectional: boolean value, indicating whether to use a bidirectional rnn or not
          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
          rnn_type: 'GRU' or 'LSTM'
          fine_tune: if True, allow to finetune the embeddings.
      """
      super().__init__()
  
      self.embeddings: StackedEmbeddings = StackedEmbeddings(
          embeddings=embeddings
      )
  
      self.rnn_type = rnn_type
  
      self.reproject_words = reproject_words
      self.bidirectional = bidirectional
  
      self.length_of_all_token_embeddings: int = (
          self.embeddings.embedding_length
      )
  
      self.static_embeddings = not fine_tune
  
      self.__embedding_length: int = hidden_size
      if self.bidirectional:
          self.__embedding_length *= 4
  
      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
  
      self.word_reprojection_map = torch.nn.Linear(
          self.length_of_all_token_embeddings, self.embeddings_dimension
      )
  
      # bidirectional RNN on top of embedding layer
      if rnn_type == "LSTM":
          self.rnn: RNNBase = torch.nn.LSTM(
              self.embeddings_dimension,
              hidden_size,
              num_layers=rnn_layers,
              bidirectional=self.bidirectional,
              batch_first=True,
          )
      else:
          self.rnn = torch.nn.GRU(
              self.embeddings_dimension,
              hidden_size,
              num_layers=rnn_layers,
              bidirectional=self.bidirectional,
              batch_first=True,
          )
  
      self.name = "document_" + self.rnn._get_name()
  
      # 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
      )
  
      torch.nn.init.xavier_uniform_(self.word_reprojection_map.weight)
  
      self.to(flair.device)
  
      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 DocumentRNNEmbeddings object from inherited base classes: DocumentEmbeddings with example: obj = DocumentRNNEmbeddings(embeddings, hidden_size, rnn_layers, reproject_words, reproject_words_dimension, bidirectional, dropout, word_dropout, locked_dropout, rnn_type, fine_tune)