class_docstr: Objects of this abstract class realize the transformation between word-document co-occurrence
  matrix (int) into a BM25 matrix (positive floats). Concrete subclasses of this abstract class
  implement different BM25 scoring functions.
class_docstr_tok: ["Objects","of","this","abstract","class","realize","the","transformation","between","word-document","co-occurrence","matrix","(","int",")","into","a","BM25","matrix","(","positive","floats",")",".","Concrete","subclasses","of","this","abstract","class","implement","different","BM25","scoring","functions","."]
docstr: Pre-compute the average length of a document and inverse term document frequencies,
  which will be used to weight term frequencies for the documents.
  
  Parameters
  ----------
  corpus : iterable of iterable of (int, int) or None, optional
      An input corpus, which will be used to compute the average length of a document and
      inverse term document frequencies. If None, then `dictionary` will be used to compute
      the statistics. If both `corpus` and `dictionary` are None, the statistics will be left
      unintialized. Default is None.
  dictionary : :class:`~gensim.corpora.Dictionary`
      An input dictionary, which will be used to compute the average length of a document and
      inverse term document frequencies.  If None, then `corpus` will be used to compute the
      statistics. If both `corpus` and `dictionary` are None, the statistics will be left
      unintialized. Default is None.
  
  Attributes
  ----------
  avgdl : float
      The average length of a document.
  idfs : dict of (int, float)
      A mapping from term ids to inverse term document frequencies.
docstr_tok: ["Pre-compute","the","average","length","of","a","document","and","inverse","term","document","frequencies",",","which","will","be","used","to","weight","term","frequencies","for","the","documents",".","Parameters","--","--","--","--","--","corpus",":","iterable","of","iterable","of","(","int",",","int",")","or","None",",","optional","An","input","corpus",",","which","will","be","used","to","compute","the","average","length","of","a","document","and","inverse","term","document","frequencies",".","If","None",",","then","`","dictionary","`","will","be","used","to","compute","the","statistics",".","If","both","`","corpus","`","and","`","dictionary","`","are","None",",","the","statistics","will","be","left","unintialized",".","Default","is","None",".","dictionary",":",":","class",":","`","~gensim.corpora.Dictionary","`","An","input","dictionary",",","which","will","be","used","to","compute","the","average","length","of","a","document","and","inverse","term","document","frequencies",".","If","None",",","then","`","corpus","`","will","be","used","to","compute","the","statistics",".","If","both","`","corpus","`","and","`","dictionary","`","are","None",",","the","statistics","will","be","left","unintialized",".","Default","is","None",".","Attributes","--","--","--","--","--","avgdl",":","float","The","average","length","of","a","document",".","idfs",":","dict","of","(","int",",","float",")","A","mapping","from","term","ids","to","inverse","term","document","frequencies","."]
code: def __init__(self, corpus=None, dictionary=None):
      r"""Pre-compute the average length of a document and inverse term document frequencies,
      which will be used to weight term frequencies for the documents.
  
      Parameters
      ----------
      corpus : iterable of iterable of (int, int) or None, optional
          An input corpus, which will be used to compute the average length of a document and
          inverse term document frequencies. If None, then `dictionary` will be used to compute
          the statistics. If both `corpus` and `dictionary` are None, the statistics will be left
          unintialized. Default is None.
      dictionary : :class:`~gensim.corpora.Dictionary`
          An input dictionary, which will be used to compute the average length of a document and
          inverse term document frequencies.  If None, then `corpus` will be used to compute the
          statistics. If both `corpus` and `dictionary` are None, the statistics will be left
          unintialized. Default is None.
  
      Attributes
      ----------
      avgdl : float
          The average length of a document.
      idfs : dict of (int, float)
          A mapping from term ids to inverse term document frequencies.
  
      """
      self.avgdl, self.idfs = None, None
      if dictionary:
          if corpus:
              logger.warning(
                  "constructor received both corpus and dictionary; ignoring the corpus"
              )
          num_tokens = sum(dictionary.cfs.values())
          self.avgdl = num_tokens / dictionary.num_docs
          self.idfs = self.precompute_idfs(
              dictionary.dfs, dictionary.num_docs
          )
      elif corpus:
          dfs = defaultdict(lambda: 0)
          num_tokens = 0
          num_docs = 0
          for bow in corpus:
              num_tokens += len(bow)
              for term_id in set(term_id for term_id, _ in bow):
                  dfs[term_id] += 1
              num_docs += 1
          self.avgdl = num_tokens / num_docs
          self.idfs = self.precompute_idfs(dfs, num_docs)
      else:
          pass
  
imports: from abc import ABCMeta, abstractmethod
  from collections import defaultdict
  import logging
  import math
  from gensim import interfaces, utils
  import numpy
label_desc: Use image node_id 1 to create a new BM25ABC object from inherited base classes: interfaces with example: obj = BM25ABC(corpus, dictionary)