class_docstr: Online Non-Negative Matrix Factorization.
  
  `Renbo Zhao et al :"Online Nonnegative Matrix Factorization with Outliers" <https://arxiv.org/abs/1604.02634>`_
class_docstr_tok: ["Online","Non-Negative","Matrix","Factorization",".","`","Renbo","Zhao","et","al",":","''","Online","Nonnegative","Matrix","Factorization","with","Outliers","''","<","https",":","\/\/arxiv.org\/abs\/1604.02634",">","`","_"]
docstr: Get the topics sorted by sparsity.
  
  Parameters
  ----------
  num_topics : int, optional
      Number of topics to be returned. Unlike LSA, there is no natural ordering between the topics in NMF.
      The returned topics subset of all topics is therefore arbitrary and may change between two NMF
      training runs.
  num_words : int, optional
      Number of words to be presented for each topic. These will be the most relevant words (assigned the highest
      probability for each topic).
  log : bool, optional
      Whether the result is also logged, besides being returned.
  formatted : bool, optional
      Whether the topic representations should be formatted as strings. If False, they are returned as
      2 tuples of (word, probability).
  normalize: bool or None, optional
      Whether to normalize the result. Allows for estimation of perplexity, coherence, e.t.c.
  
  Returns
  -------
  list of {str, tuple of (str, float)}
      a list of topics, each represented either as a string (when `formatted` == True) or word-probability
      pairs.
docstr_tok: ["Get","the","topics","sorted","by","sparsity",".","Parameters","--","--","--","--","--","num_topics",":","int",",","optional","Number","of","topics","to","be","returned",".","Unlike","LSA",",","there","is","no","natural","ordering","between","the","topics","in","NMF",".","The","returned","topics","subset","of","all","topics","is","therefore","arbitrary","and","may","change","between","two","NMF","training","runs",".","num_words",":","int",",","optional","Number","of","words","to","be","presented","for","each","topic",".","These","will","be","the","most","relevant","words","(","assigned","the","highest","probability","for","each","topic",")",".","log",":","bool",",","optional","Whether","the","result","is","also","logged",",","besides","being","returned",".","formatted",":","bool",",","optional","Whether","the","topic","representations","should","be","formatted","as","strings",".","If","False",",","they","are","returned","as","2","tuples","of","(","word",",","probability",")",".","normalize",":","bool","or","None",",","optional","Whether","to","normalize","the","result",".","Allows","for","estimation","of","perplexity",",","coherence",",","e.t.c",".","Returns","--","--","--","-","list","of","{","str",",","tuple","of","(","str",",","float",")","}","a","list","of","topics",",","each","represented","either","as","a","string","(","when","`","formatted","`","==","True",")","or","word-probability","pairs","."]
code: def show_topics(
      self,
      num_topics=10,
      num_words=10,
      log=False,
      formatted=True,
      normalize=None,
  ):
      """Get the topics sorted by sparsity.
  
      Parameters
      ----------
      num_topics : int, optional
          Number of topics to be returned. Unlike LSA, there is no natural ordering between the topics in NMF.
          The returned topics subset of all topics is therefore arbitrary and may change between two NMF
          training runs.
      num_words : int, optional
          Number of words to be presented for each topic. These will be the most relevant words (assigned the highest
          probability for each topic).
      log : bool, optional
          Whether the result is also logged, besides being returned.
      formatted : bool, optional
          Whether the topic representations should be formatted as strings. If False, they are returned as
          2 tuples of (word, probability).
      normalize: bool or None, optional
          Whether to normalize the result. Allows for estimation of perplexity, coherence, e.t.c.
  
      Returns
      -------
      list of {str, tuple of (str, float)}
          a list of topics, each represented either as a string (when `formatted` == True) or word-probability
          pairs.
  
      """
      if normalize is None:
          normalize = self.normalize
  
      # Compute fraction of zero elements in each column
  
      sparsity = np.zeros(self._W.shape[1])
  
      for row in self._W:
          sparsity += row == 0
  
      sparsity /= self._W.shape[0]
  
      if num_topics < 0 or num_topics >= self.num_topics:
          num_topics = self.num_topics
          chosen_topics = range(num_topics)
      else:
          num_topics = min(num_topics, self.num_topics)
  
          sorted_topics = list(matutils.argsort(sparsity))
          chosen_topics = (
              sorted_topics[: num_topics // 2]
              + sorted_topics[-num_topics // 2 :]
          )
  
      shown = []
  
      topics = self.get_topics(normalize=normalize)
  
      for i in chosen_topics:
          topic = topics[i]
          bestn = matutils.argsort(
              topic, num_words, reverse=True
          ).ravel()
          topic = [(self.id2word[id], topic[id]) for id in bestn]
          if formatted:
              topic = " + ".join(
                  ['%.3f*"%s"' % (v, k) for k, v in topic]
              )
  
          shown.append((i, topic))
          if log:
              logger.info("topic #%i (%.3f): %s", i, sparsity[i], topic)
  
      return shown
  
imports: import collections.abc
  import logging
  import numpy
  import scipy.sparse
  from scipy.stats import halfnorm
  from gensim import interfaces
  from gensim import matutils
  from gensim import utils
  from gensim.interfaces import TransformedCorpus
  from gensim.models import basemodel, CoherenceModel
  from gensim.models.nmf_pgd import solve_h
label_desc: Use image node_id 4 for calling the Nmf obj's underlying member method code with example usage: obj.show_topics(num_topics, num_words, log, formatted, normalize) and returns: shown