docstr: The constructor for DocumentTFIDFEmbeddings.
  
  Args:
      train_dataset: the train dataset which will be used to construct a vectorizer
      vectorizer: a precalculated vectorizer. If provided, requires the train_dataset to be an empty list.
      vectorizer_params: parameters given to Scikit-learn's TfidfVectorizer constructor
docstr_tok: ["The","constructor","for","DocumentTFIDFEmbeddings",".","Args",":","train_dataset",":","the","train","dataset","which","will","be","used","to","construct","a","vectorizer","vectorizer",":","a","precalculated","vectorizer",".","If","provided",",","requires","the","train_dataset","to","be","an","empty","list",".","vectorizer_params",":","parameters","given","to","Scikit-learn","'s","TfidfVectorizer","constructor"]
code: def __init__(
      self,
      train_dataset: List[Sentence],
      vectorizer: Optional[TfidfVectorizer] = None,
      **vectorizer_params,
  ) -> None:
      """The constructor for DocumentTFIDFEmbeddings.
  
      Args:
          train_dataset: the train dataset which will be used to construct a vectorizer
          vectorizer: a precalculated vectorizer. If provided, requires the train_dataset to be an empty list.
          vectorizer_params: parameters given to Scikit-learn's TfidfVectorizer constructor
      """
      super().__init__()
  
      import numpy as np
  
      if vectorizer is not None:
          self.vectorizer = vectorizer
          if len(train_dataset) > 0:
              raise ValueError(
                  "Cannot initialize document tfidf embeddings with a vectorizer and with a dataset"
              )
      else:
          self.vectorizer = TfidfVectorizer(
              dtype=np.float32, **vectorizer_params
          )
          self.vectorizer.fit(
              [s.to_original_text() for s in train_dataset]
          )
  
      self.__embedding_length: int = len(self.vectorizer.vocabulary_)
  
      self.to(flair.device)
  
      self.name: str = "document_tfidf"
      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 DocumentTFIDFEmbeddings object from inherited base classes: DocumentEmbeddings with example: obj = DocumentTFIDFEmbeddings(train_dataset, vectorizer)