code: def check_feature_names(
      vec, ivec, always_signed, corpus, alternate_sign
  ):
      feature_names = ivec.get_feature_names(
          always_signed=always_signed
      )
      seen_words = set()
      counts = Counter(corpus)
      for idx, collisions in enumerate(feature_names):
          words_in_collision = []
          for ic, collision in enumerate(collisions):
              sign = collision["sign"]
              c = collision["name"]
              if ic == 0 and not always_signed:
                  # Most frequent term is always not inverted.
                  assert sign == 1, collisions
              seen_words.add(c)
              words_in_collision.append(c)
              if not always_signed and ivec.column_signs_[idx] < 0:
                  sign *= -1
              # Term hashes to correct value with correct sign.
              expected = np.zeros(vec.n_features)
              expected[idx] = sign
              transormed = vec.transform([c]).toarray()
              assert np.allclose(transormed, expected), (
                  transormed,
                  expected,
              )
          for prev_w, w in zip(
              words_in_collision, words_in_collision[1:]
          ):
              # Terms are ordered by frequency.
              assert counts[prev_w] > counts[w]
  
      if not alternate_sign:
          assert np.array_equal(
              ivec.column_signs_, np.ones(len(feature_names))
          )
      assert seen_words == set(corpus)
  
file_path: eli5/tests/test_sklearn_unhashing.py
imports: from itertools import repeat
  from collections import Counter
  import pytest
  import numpy
  from sklearn.feature_extraction.text import HashingVectorizer
  from eli5.sklearn.unhashing import InvertableHashingVectorizer
  from eli5.sklearn.utils import sklearn_version
label_desc: Use image node_id 2 for calling a global function with example usage: check_feature_names(vec, ivec, always_signed, corpus, alternate_sign) without return types