code: def test_consistency(self):
      docs = [corpus[1], corpus[2]]
  
      # Test if `ntc` yields the default docs.
      model = tfidfmodel.TfidfModel(corpus, smartirs="nfc")
      transformed_docs = [model[docs[0]], model[docs[1]]]
  
      model = tfidfmodel.TfidfModel(corpus)
      expected_docs = [model[docs[0]], model[docs[1]]]
  
      self.assertTrue(
          np.allclose(transformed_docs[0], expected_docs[0])
      )
      self.assertTrue(
          np.allclose(transformed_docs[1], expected_docs[1])
      )
  
      # Testing all the variations of `wlocal`
      # tnn
      model = tfidfmodel.TfidfModel(corpus, smartirs="tnn")
      transformed_docs = [model[docs[0]], model[docs[1]]]
      expected_docs = docs[:]
  
      self.assertTrue(
          np.allclose(transformed_docs[0], expected_docs[0])
      )
      self.assertTrue(
          np.allclose(transformed_docs[1], expected_docs[1])
      )
  
      # nnn
      model = tfidfmodel.TfidfModel(corpus, smartirs="nnn")
      transformed_docs = [model[docs[0]], model[docs[1]]]
      expected_docs = docs[:]
  
      self.assertTrue(
          np.allclose(transformed_docs[0], expected_docs[0])
      )
      self.assertTrue(
          np.allclose(transformed_docs[1], expected_docs[1])
      )
  
      # lnn
      model = tfidfmodel.TfidfModel(corpus, smartirs="lnn")
      transformed_docs = [model[docs[0]], model[docs[1]]]
      expected_docs = [
          [(3, 1.0), (4, 1.0), (5, 1.0), (6, 1.0), (7, 1.0), (8, 1.0)],
          [(5, 2.0), (9, 1.0), (10, 1.0)],
      ]
  
      self.assertTrue(
          np.allclose(transformed_docs[0], expected_docs[0])
      )
      self.assertTrue(
          np.allclose(transformed_docs[1], expected_docs[1])
      )
  
      # dnn
      model = tfidfmodel.TfidfModel(corpus, smartirs="dnn")
      transformed_docs = [model[docs[0]], model[docs[1]]]
      expected_docs = [
          [(3, 1.0), (4, 1.0), (5, 1.0), (6, 1.0), (7, 1.0), (8, 1.0)],
          [(5, 2.0), (9, 1.0), (10, 1.0)],
      ]
  
      self.assertTrue(
          np.allclose(transformed_docs[0], expected_docs[0])
      )
      self.assertTrue(
          np.allclose(transformed_docs[1], expected_docs[1])
      )
  
      # ann
      model = tfidfmodel.TfidfModel(corpus, smartirs="ann")
      transformed_docs = [model[docs[0]], model[docs[1]]]
      expected_docs = [
          [(3, 1.0), (4, 1.0), (5, 1.0), (6, 1.0), (7, 1.0), (8, 1.0)],
          [(5, 1.0), (9, 0.75), (10, 0.75)],
      ]
  
      self.assertTrue(
          np.allclose(transformed_docs[0], expected_docs[0])
      )
      self.assertTrue(
          np.allclose(transformed_docs[1], expected_docs[1])
      )
  
      # bnn
      model = tfidfmodel.TfidfModel(corpus, smartirs="bnn")
      transformed_docs = [model[docs[0]], model[docs[1]]]
      expected_docs = [
          [(3, 1), (4, 1), (5, 1), (6, 1), (7, 1), (8, 1)],
          [(5, 1), (9, 1), (10, 1)],
      ]
  
      self.assertTrue(
          np.allclose(transformed_docs[0], expected_docs[0])
      )
      self.assertTrue(
          np.allclose(transformed_docs[1], expected_docs[1])
      )
  
      # Lnn
      model = tfidfmodel.TfidfModel(corpus, smartirs="Lnn")
      transformed_docs = [model[docs[0]], model[docs[1]]]
      expected_docs = [
          [(3, 1.0), (4, 1.0), (5, 1.0), (6, 1.0), (7, 1.0), (8, 1.0)],
          [(5, 1.4133901052), (9, 0.7066950526), (10, 0.7066950526)],
      ]
  
      # Testing all the variations of `glocal`
      # nxn
      model = tfidfmodel.TfidfModel(corpus, smartirs="nxn")
      transformed_docs = [model[docs[0]], model[docs[1]]]
      expected_docs = docs[:]
  
      self.assertTrue(
          np.allclose(transformed_docs[0], expected_docs[0])
      )
      self.assertTrue(
          np.allclose(transformed_docs[1], expected_docs[1])
      )
  
      # nfn
      model = tfidfmodel.TfidfModel(corpus, smartirs="nfn")
      transformed_docs = [model[docs[0]], model[docs[1]]]
      expected_docs = [
          [
              (3, 3.169925001442312),
              (4, 3.169925001442312),
              (5, 1.584962500721156),
              (6, 3.169925001442312),
              (7, 3.169925001442312),
              (8, 2.169925001442312),
          ],
          [
              (5, 3.169925001442312),
              (9, 3.169925001442312),
              (10, 3.169925001442312),
          ],
      ]
  
      self.assertTrue(
          np.allclose(transformed_docs[0], expected_docs[0])
      )
      self.assertTrue(
          np.allclose(transformed_docs[1], expected_docs[1])
      )
  
      # ntn
      model = tfidfmodel.TfidfModel(corpus, smartirs="ntn")
      transformed_docs = [model[docs[0]], model[docs[1]]]
      expected_docs = [
          [
              (3, 3.321928094887362),
              (4, 3.321928094887362),
              (5, 1.736965594166206),
              (6, 3.321928094887362),
              (7, 3.321928094887362),
              (8, 2.321928094887362),
          ],
          [
              (5, 3.473931188332412),
              (9, 3.321928094887362),
              (10, 3.321928094887362),
          ],
      ]
  
      self.assertTrue(
          np.allclose(transformed_docs[0], expected_docs[0])
      )
      self.assertTrue(
          np.allclose(transformed_docs[1], expected_docs[1])
      )
  
      # npn
      model = tfidfmodel.TfidfModel(corpus, smartirs="npn")
      transformed_docs = [model[docs[0]], model[docs[1]]]
      expected_docs = [
          [
              (3, 3.0),
              (4, 3.0),
              (5, 1.0),
              (6, 3.0),
              (7, 3.0),
              (8, 1.8073549220576042),
          ],
          [(5, 2.0), (9, 3.0), (10, 3.0)],
      ]
  
      self.assertTrue(
          np.allclose(transformed_docs[0], expected_docs[0])
      )
      self.assertTrue(
          np.allclose(transformed_docs[1], expected_docs[1])
      )
  
      # Testing all the variations of `normalize`
      # nnx
      model = tfidfmodel.TfidfModel(corpus, smartirs="nnx")
      transformed_docs = [model[docs[0]], model[docs[1]]]
      expected_docs = docs[:]
  
      self.assertTrue(
          np.allclose(transformed_docs[0], expected_docs[0])
      )
      self.assertTrue(
          np.allclose(transformed_docs[1], expected_docs[1])
      )
  
      # nnc
      model = tfidfmodel.TfidfModel(corpus, smartirs="nnc")
      transformed_docs = [model[docs[0]], model[docs[1]]]
      expected_docs = [
          [
              (3, 0.4082482905),
              (4, 0.4082482905),
              (5, 0.4082482905),
              (6, 0.4082482905),
              (7, 0.4082482905),
              (8, 0.4082482905),
          ],
          [
              (5, 0.81649658092772603),
              (9, 0.40824829046386302),
              (10, 0.40824829046386302),
          ],
      ]
  
      self.assertTrue(
          np.allclose(transformed_docs[0], expected_docs[0])
      )
      self.assertTrue(
          np.allclose(transformed_docs[1], expected_docs[1])
      )
  
      model = tfidfmodel.TfidfModel(
          corpus,
          wlocal=lambda x: x,
          wglobal=lambda x, y: x * x,
          smartirs="nnc",
      )
  
      transformed_docs = [model[docs[0]], model[docs[1]]]
  
      model = tfidfmodel.TfidfModel(
          corpus,
          wlocal=lambda x: x * x,
          wglobal=lambda x, y: x,
          smartirs="nnc",
      )
      expected_docs = [model[docs[0]], model[docs[1]]]
  
      self.assertTrue(
          np.allclose(transformed_docs[0], expected_docs[0])
      )
      self.assertTrue(
          np.allclose(transformed_docs[1], expected_docs[1])
      )
  
      # nnu
      slope = 0.2
      model = tfidfmodel.TfidfModel(corpus, smartirs="nnu", slope=slope)
      transformed_docs = [model[docs[0]], model[docs[1]]]
      average_unique_length = (
          1.0 * sum(len(set(text)) for text in texts) / len(texts)
      )
      vector_norms = [
          (1.0 - slope) * average_unique_length + slope * 6.0,
          (1.0 - slope) * average_unique_length + slope * 3.0,
      ]
      expected_docs = [
          [
              (termid, weight / vector_norms[0])
              for termid, weight in docs[0]
          ],
          [
              (termid, weight / vector_norms[1])
              for termid, weight in docs[1]
          ],
      ]
  
      self.assertTrue(
          np.allclose(transformed_docs[0], expected_docs[0])
      )
      self.assertTrue(
          np.allclose(transformed_docs[1], expected_docs[1])
      )
  
      # nnb
      slope = 0.2
      model = tfidfmodel.TfidfModel(
          dictionary=dictionary, smartirs="nnb", slope=slope
      )
      transformed_docs = [model[docs[0]], model[docs[1]]]
      average_character_length = sum(
          len(word) + 1.0 for text in texts for word in text
      ) / len(texts)
      vector_norms = [
          (1.0 - slope) * average_character_length + slope * 36.0,
          (1.0 - slope) * average_character_length + slope * 25.0,
      ]
      expected_docs = [
          [
              (termid, weight / vector_norms[0])
              for termid, weight in docs[0]
          ],
          [
              (termid, weight / vector_norms[1])
              for termid, weight in docs[1]
          ],
      ]
  
      self.assertTrue(
          np.allclose(transformed_docs[0], expected_docs[0])
      )
      self.assertTrue(
          np.allclose(transformed_docs[1], expected_docs[1])
      )
  
file_path: gensim/gensim/test/test_tfidfmodel.py
imports: import logging
  import unittest
  import numpy
  from gensim.corpora.mmcorpus import MmCorpus
  from gensim.models import tfidfmodel
  from gensim.test.utils import datapath, get_tmpfile, common_dictionary, common_corpus
  from gensim.corpora import Dictionary
label_desc: Use image node_id 6 for calling the TestTfidfModel obj's underlying member method code with example usage: obj.test_consistency() without return types