class_docstr: Compute soft cosine similarity against a corpus of documents by storing the index matrix in memory.
  
  Examples
  --------
  .. sourcecode:: pycon
  
      >>> from gensim.test.utils import common_texts
      >>> from gensim.corpora import Dictionary
      >>> from gensim.models import Word2Vec
      >>> from gensim.similarities import SoftCosineSimilarity, SparseTermSimilarityMatrix
      >>> from gensim.similarities import WordEmbeddingSimilarityIndex
      >>>
      >>> model = Word2Vec(common_texts, vector_size=20, min_count=1)  # train word-vectors
      >>> termsim_index = WordEmbeddingSimilarityIndex(model.wv)
      >>> dictionary = Dictionary(common_texts)
      >>> bow_corpus = [dictionary.doc2bow(document) for document in common_texts]
      >>> similarity_matrix = SparseTermSimilarityMatrix(termsim_index, dictionary)  # construct similarity matrix
      >>> docsim_index = SoftCosineSimilarity(bow_corpus, similarity_matrix, num_best=10)
      >>>
      >>> query = 'graph trees computer'.split()  # make a query
      >>> sims = docsim_index[dictionary.doc2bow(query)]  # calculate similarity of query to each doc from bow_corpus
  
  Check out `the Gallery <https://radimrehurek.com/gensim/auto_examples/tutorials/run_scm.html>`__
  for more examples.
class_docstr_tok: ["Compute","soft","cosine","similarity","against","a","corpus","of","documents","by","storing","the","index","matrix","in","memory",".","Examples","--","--","--","--","..","sourcecode",":",":","pycon",">",">",">","from","gensim.test.utils","import","common_texts",">",">",">","from","gensim.corpora","import","Dictionary",">",">",">","from","gensim.models","import","Word2Vec",">",">",">","from","gensim.similarities","import","SoftCosineSimilarity",",","SparseTermSimilarityMatrix",">",">",">","from","gensim.similarities","import","WordEmbeddingSimilarityIndex",">",">",">",">",">",">","model","=","Word2Vec","(","common_texts",",","vector_size=20",",","min_count=1",")","#","train","word-vectors",">",">",">","termsim_index","=","WordEmbeddingSimilarityIndex","(","model.wv",")",">",">",">","dictionary","=","Dictionary","(","common_texts",")",">",">",">","bow_corpus","=","[","dictionary.doc2bow","(","document",")","for","document","in","common_texts","]",">",">",">","similarity_matrix","=","SparseTermSimilarityMatrix","(","termsim_index",",","dictionary",")","#","construct","similarity","matrix",">",">",">","docsim_index","=","SoftCosineSimilarity","(","bow_corpus",",","similarity_matrix",",","num_best=10",")",">",">",">",">",">",">","query","=","'graph","trees","computer'.split","(",")","#","make","a","query",">",">",">","sims","=","docsim_index","[","dictionary.doc2bow","(","query",")","]","#","calculate","similarity","of","query","to","each","doc","from","bow_corpus","Check","out","`","the","Gallery","<","https",":","\/\/radimrehurek.com\/gensim\/auto_examples\/tutorials\/run_scm.html",">","`","__","for","more","examples","."]
docstr: Parameters
  ----------
  corpus: iterable of list of (int, float)
      A list of documents in the BoW format.
  similarity_matrix : :class:`gensim.similarities.SparseTermSimilarityMatrix`
      A term similarity matrix.
  num_best : int, optional
      The number of results to retrieve for a query, if None - return similarities with all elements from corpus.
  chunksize: int, optional
      Size of one corpus chunk.
  normalized : tuple of {True, False, 'maintain', None}, optional
      A deprecated alias for `(normalize_queries, normalize_documents)`. If None, use
      `normalize_queries` and `normalize_documents`. Default is None.
  normalize_queries : {True, False, 'maintain'}, optional
      Whether the query vector in the inner product will be L2-normalized (True; corresponds
      to the soft cosine similarity measure; default), maintain their L2-norm during change of
      basis ('maintain'; corresponds to queryexpansion with partial membership), or kept as-is
      (False;  corresponds to query expansion).
  normalize_documents : {True, False, 'maintain'}, optional
      Whether the document vector in the inner product will be L2-normalized (True; corresponds
      to the soft cosine similarity measure; default), maintain their L2-norm during change of
      basis ('maintain'; corresponds to queryexpansion with partial membership), or kept as-is
      (False;  corresponds to query expansion).
  
  See Also
  --------
  :class:`~gensim.similarities.termsim.SparseTermSimilarityMatrix`
      A sparse term similarity matrix built using a term similarity index.
  :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,
      corpus,
      similarity_matrix,
      num_best=None,
      chunksize=256,
      normalized=None,
      normalize_queries=True,
      normalize_documents=True,
  ):
      """
  
      Parameters
      ----------
      corpus: iterable of list of (int, float)
          A list of documents in the BoW format.
      similarity_matrix : :class:`gensim.similarities.SparseTermSimilarityMatrix`
          A term similarity matrix.
      num_best : int, optional
          The number of results to retrieve for a query, if None - return similarities with all elements from corpus.
      chunksize: int, optional
          Size of one corpus chunk.
      normalized : tuple of {True, False, 'maintain', None}, optional
          A deprecated alias for `(normalize_queries, normalize_documents)`. If None, use
          `normalize_queries` and `normalize_documents`. Default is None.
      normalize_queries : {True, False, 'maintain'}, optional
          Whether the query vector in the inner product will be L2-normalized (True; corresponds
          to the soft cosine similarity measure; default), maintain their L2-norm during change of
          basis ('maintain'; corresponds to queryexpansion with partial membership), or kept as-is
          (False;  corresponds to query expansion).
      normalize_documents : {True, False, 'maintain'}, optional
          Whether the document vector in the inner product will be L2-normalized (True; corresponds
          to the soft cosine similarity measure; default), maintain their L2-norm during change of
          basis ('maintain'; corresponds to queryexpansion with partial membership), or kept as-is
          (False;  corresponds to query expansion).
  
      See Also
      --------
      :class:`~gensim.similarities.termsim.SparseTermSimilarityMatrix`
          A sparse term similarity matrix built using a term similarity index.
      :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.
  
      """
      self.similarity_matrix = similarity_matrix
  
      self.corpus = list(corpus)
      self.num_best = num_best
      self.chunksize = chunksize
      if normalized is not None:
          warnings.warn(
              "Parameter normalized will be removed in 5.0.0, use normalize_queries and normalize_documents instead",
              category=DeprecationWarning,
          )
          self.normalized = normalized
      else:
          self.normalized = (normalize_queries, normalize_documents)
  
      # Normalization of features is undesirable, since soft cosine similarity requires special
      # normalization using the similarity matrix. Therefore, we would just be normalizing twice,
      # increasing the numerical error.
      self.normalize = False
  
      # index is simply an array from 0 to size of corpus.
      self.index = numpy.arange(len(corpus))
  
imports: import logging
  import itertools
  import os
  import heapq
  import warnings
  import numpy
  import scipy.sparse
  from gensim import interfaces, utils, matutils
label_desc: Use image node_id 1 to create a new SoftCosineSimilarity object from inherited base classes: interfaces with example: obj = SoftCosineSimilarity(corpus, similarity_matrix, num_best, chunksize, normalized, normalize_queries, normalize_documents)