class_docstr: Builds a sparse term similarity matrix using a term similarity index.
  
  Examples
  --------
  >>> from gensim.test.utils import common_texts as corpus, datapath
  >>> from gensim.corpora import Dictionary
  >>> from gensim.models import Word2Vec
  >>> from gensim.similarities import SoftCosineSimilarity, SparseTermSimilarityMatrix, WordEmbeddingSimilarityIndex
  >>> from gensim.similarities.index import AnnoyIndexer
  >>>
  >>> model_corpus_file = datapath('lee_background.cor')
  >>> model = Word2Vec(corpus_file=model_corpus_file, vector_size=20, min_count=1)  # train word-vectors
  >>>
  >>> dictionary = Dictionary(corpus)
  >>> tfidf = TfidfModel(dictionary=dictionary)
  >>> words = [word for word, count in dictionary.most_common()]
  >>> word_vectors = model.wv.vectors_for_all(words, allow_inference=False)  # produce vectors for words in corpus
  >>>
  >>> indexer = AnnoyIndexer(word_vectors, num_trees=2)  # use Annoy for faster word similarity lookups
  >>> termsim_index = WordEmbeddingSimilarityIndex(word_vectors, kwargs={'indexer': indexer})
  >>> similarity_matrix = SparseTermSimilarityMatrix(termsim_index, dictionary, tfidf)  # compute word similarities
  >>>
  >>> tfidf_corpus = tfidf[[dictionary.doc2bow(document) for document in common_texts]]
  >>> docsim_index = SoftCosineSimilarity(tfidf_corpus, similarity_matrix, num_best=10)  # index tfidf_corpus
  >>>
  >>> query = 'graph trees computer'.split()  # make a query
  >>> sims = docsim_index[dictionary.doc2bow(query)]  # find the ten closest documents from tfidf_corpus
  
  Check out `the Gallery <https://radimrehurek.com/gensim/auto_examples/tutorials/run_scm.html>`_
  for more examples.
  
  Parameters
  ----------
  source : :class:`~gensim.similarities.termsim.TermSimilarityIndex` or :class:`scipy.sparse.spmatrix`
      The source of the term similarity. Either a term similarity index that will be used for
      building the term similarity matrix, or an existing sparse term similarity matrix that will
      be encapsulated and stored in the matrix attribute. When a matrix is specified as the
      source, any other parameters will be ignored.
  dictionary : :class:`~gensim.corpora.dictionary.Dictionary` or None, optional
      A dictionary that specifies a mapping between terms and the indices of rows and columns
      of the resulting term similarity matrix. The dictionary may only be None when source is
      a :class:`scipy.sparse.spmatrix`.
  tfidf : :class:`gensim.models.tfidfmodel.TfidfModel` or None, optional
      A model that specifies the relative importance of the terms in the dictionary. The columns
      of the term similarity matrix will be build in a decreasing order of importance of
      terms, or in the order of term identifiers if None.
  symmetric : bool, optional
      Whether the symmetry of the term similarity matrix will be enforced. Symmetry is a necessary
      precondition for positive definiteness, which is necessary if you later wish to derive a
      unique change-of-basis matrix from the term similarity matrix using Cholesky factorization.
      Setting symmetric to False will significantly reduce memory usage during matrix construction.
  dominant: bool, optional
      Whether the strict column diagonal dominance of the term similarity matrix will be enforced.
      Strict diagonal dominance and symmetry are sufficient preconditions for positive
      definiteness, which is necessary if you later wish to derive a change-of-basis matrix from
      the term similarity matrix using Cholesky factorization.
  nonzero_limit : int or None, optional
      The maximum number of non-zero elements outside the diagonal in a single column of the
      sparse term similarity matrix. If None, then no limit will be imposed.
  dtype : numpy.dtype, optional
      The data type of the sparse term similarity matrix.
  
  Attributes
  ----------
  matrix : :class:`scipy.sparse.csc_matrix`
      The encapsulated sparse term similarity matrix.
  
  Raises
  ------
  ValueError
      If `dictionary` is empty.
  
  See Also
  --------
  :class:`~gensim.similarities.docsim.SoftCosineSimilarity`
      A document similarity index using the soft cosine similarity over the term similarity matrix.
  :class:`~gensim.similarities.termsim.LevenshteinSimilarityIndex`
      A term similarity index that computes Levenshtein similarities between terms.
  :class:`~gensim.similarities.termsim.WordEmbeddingSimilarityIndex`
      A term similarity index that computes cosine similarities between word embeddings.
code: def __init__(
      self,
      source,
      dictionary=None,
      tfidf=None,
      symmetric=True,
      dominant=False,
      nonzero_limit=100,
      dtype=np.float32,
  ):
      if not sparse.issparse(source):
          index = source
          args = (
              index,
              dictionary,
              tfidf,
              symmetric,
              dominant,
              nonzero_limit,
              dtype,
          )
          source = _create_source(*args)
          assert sparse.issparse(source)
  
      self.matrix = source.tocsc()
  
imports: from array import array
  from itertools import chain
  import logging
  from math import sqrt
  import numpy
  from scipy import sparse
  from gensim.matutils import corpus2csc
  from gensim.utils import SaveLoad, is_corpus
label_desc: Use image node_id 1 to create a new SparseTermSimilarityMatrix object from inherited base classes: SaveLoad with example: obj = SparseTermSimilarityMatrix(source, dictionary, tfidf, symmetric, dominant, nonzero_limit, dtype)