class_docstr: Objects of this class realize the transformation between word-document co-occurrence matrix (int)
  into a locally/globally weighted TF-IDF matrix (positive floats).
  
  Examples
  --------
  .. sourcecode:: pycon
  
      >>> import gensim.downloader as api
      >>> from gensim.models import TfidfModel
      >>> from gensim.corpora import Dictionary
      >>>
      >>> dataset = api.load("text8")
      >>> dct = Dictionary(dataset)  # fit dictionary
      >>> corpus = [dct.doc2bow(line) for line in dataset]  # convert corpus to BoW format
      >>>
      >>> model = TfidfModel(corpus)  # fit model
      >>> vector = model[corpus[0]]  # apply model to the first corpus document
class_docstr_tok: ["Objects","of","this","class","realize","the","transformation","between","word-document","co-occurrence","matrix","(","int",")","into","a","locally\/globally","weighted","TF-IDF","matrix","(","positive","floats",")",".","Examples","--","--","--","--","..","sourcecode",":",":","pycon",">",">",">","import","gensim.downloader","as","api",">",">",">","from","gensim.models","import","TfidfModel",">",">",">","from","gensim.corpora","import","Dictionary",">",">",">",">",">",">","dataset","=","api.load","(","``","text8","''",")",">",">",">","dct","=","Dictionary","(","dataset",")","#","fit","dictionary",">",">",">","corpus","=","[","dct.doc2bow","(","line",")","for","line","in","dataset","]","#","convert","corpus","to","BoW","format",">",">",">",">",">",">","model","=","TfidfModel","(","corpus",")","#","fit","model",">",">",">","vector","=","model","[","corpus","[","0","]","]","#","apply","model","to","the","first","corpus","document"]
docstr: Compute inverse document weights, which will be used to modify term frequencies for documents.
  
  Parameters
  ----------
  corpus : iterable of iterable of (int, int)
      Input corpus.
docstr_tok: ["Compute","inverse","document","weights",",","which","will","be","used","to","modify","term","frequencies","for","documents",".","Parameters","--","--","--","--","--","corpus",":","iterable","of","iterable","of","(","int",",","int",")","Input","corpus","."]
code: def initialize(self, corpus):
      """Compute inverse document weights, which will be used to modify term frequencies for documents.
  
      Parameters
      ----------
      corpus : iterable of iterable of (int, int)
          Input corpus.
  
      """
      logger.info("collecting document frequencies")
      dfs = {}
      numnnz, docno = 0, -1
  
      for docno, bow in enumerate(corpus):
          if docno % 10000 == 0:
              logger.info("PROGRESS: processing document #%i", docno)
          numnnz += len(bow)
          for termid, _ in bow:
              dfs[termid] = dfs.get(termid, 0) + 1
      # keep some stats about the training corpus
      self.num_docs = docno + 1
      self.num_nnz = numnnz
      self.cfs = None
      self.dfs = dfs
      self.term_lengths = None
      # and finally compute the idf weights
      self.idfs = precompute_idfs(self.wglobal, self.dfs, self.num_docs)
      self.add_lifecycle_event(
          "initialize",
          msg=(
              f"calculated IDF weights for {self.num_docs} documents and {max(dfs.keys()) + 1 if dfs else 0}"
              f" features ({self.num_nnz} matrix non-zeros)"
          ),
      )
  
file_path: gensim/gensim/models/tfidfmodel.py
imports: import logging
  from functools import partial
  import re
  import numpy
  from gensim import interfaces, matutils, utils
  from gensim.utils import deprecated
label_desc: Use image node_id 4 for calling the TfidfModel obj's underlying member method code with example usage: obj.initialize(corpus) without return types