class_docstr: Create topic model widget.
docstr: Creates Pandas DataFrame to display most relevant documents for each topic.
  
  Args:
      text_docs: A list of text documents in string format. Important to note that
           this list of documents should be ordered in accordance with the matrix
          or corpus on which the document was trained
      topic_names: A list of pre-defined names set for each of the topics.
          Default is None
      num_docs: The number of documents to display for each topic. Default is 10
      summarize_docs: If True, the documents will be summarized (if this is the
          case, 'text_docs' should be formatted into sentences). Default is False
      summary_words: The number of words the summary should be limited to. Should
          only be specified if summarize_docs set to True
  
  Returns:
      all_top_docs_df: Pandas DataFrame displaying topics as columns and their
          most relevant documents as rows
code: def top_documents_per_topic(
      self,
      text_docs: List[str],
      topic_names: Optional[List[str]] = None,
      num_docs: int = 10,
      summarize_docs: bool = False,
      summary_words: Optional[int] = None,
  ):
      """Creates Pandas DataFrame to display most relevant documents for each topic.
  
      Args:
          text_docs: A list of text documents in string format. Important to note that
               this list of documents should be ordered in accordance with the matrix
              or corpus on which the document was trained
          topic_names: A list of pre-defined names set for each of the topics.
              Default is None
          num_docs: The number of documents to display for each topic. Default is 10
          summarize_docs: If True, the documents will be summarized (if this is the
              case, 'text_docs' should be formatted into sentences). Default is False
          summary_words: The number of words the summary should be limited to. Should
              only be specified if summarize_docs set to True
  
      Returns:
          all_top_docs_df: Pandas DataFrame displaying topics as columns and their
              most relevant documents as rows
      """
      topics = self.get_topic_nums()
  
      if summary_words and not summarize_docs:
          warnings.warn(
              "'summary_words' specified, but 'summarize' set to False."
          )
  
      all_top_docs = {}
      sentence_check = 0
      # iterate through each topic
      for topic_num in range(topics.shape[1]):
          # sort documents in order of relevancy to current topic
          topic = [topic[topic_num] for topic in topics]
          indexes = list(np.argsort(topic)[::-1])[:num_docs]
          top_docs = [text_docs[index] for index in indexes]
  
          # summarize docs if specified
          if summarize_docs:
              summarized_docs = []
              # use set number of words if specified
              # try to summarize, does not work if document is only one sentence so then just append document
              for index, doc in enumerate(top_docs):
                  if summary_words:
                      try:
                          summarized_docs.append(
                              _compat[  # type: ignore
                                  "gensim"
                              ].summarization.summarizer.summarize(
                                  doc, word_count=summary_words
                              )
                          )
                      except ValueError:
                          sentence_check += 1
                          warnings.warn(
                              "Document #{} in Topic {} cannot be summarized.".format(
                                  str(index + 1), topic_num
                              )
                          )
                          summarized_docs.append(doc)
                  else:
                      try:
                          summarized_docs.append(
                              _compat[  # type: ignore
                                  "gensim"
                              ].summarization.summarizer.summarize(doc)
                          )
                      except ValueError:
                          sentence_check += 1
                          warnings.warn(
                              "Document #{} in Topic {} cannot be summarized.".format(
                                  str(index + 1), topic_num
                              )
                          )
                          summarized_docs.append(doc)
              top_docs = summarized_docs
  
          if not topic_names:
              all_top_docs["Topic " + str(topic_num + 1)] = top_docs
          else:
              all_top_docs[
                  "Topic: " + topic_names[topic_num]
              ] = top_docs
  
      if sentence_check > (num_docs * len(topics[0]) / 4):
          warnings.warn(
              "Documents must be formatted as sentences for summarization."
          )
  
      doc_numbers = [
          "Document #" + str(num + 1) for num in range(num_docs)
      ]
      all_top_docs_df = pd.DataFrame(all_top_docs, index=doc_numbers)
      return all_top_docs_df
  
imports: import warnings
  from typing import List, Optional, Dict, Tuple, TYPE_CHECKING
  import pandas
  import numpy
  from sklearn.decomposition import TruncatedSVD, NMF
  import matplotlib.pyplot
  import seaborn
  from data_describe.config._config import get_option
  from data_describe.text.text_preprocessing import create_doc_term_matrix, create_tfidf_matrix, filter_dictionary
  from data_describe.backends import _get_viz_backend
  from data_describe.compat import _compat, _requires, _in_notebook
  from data_describe._widget import BaseWidget
label_desc: Use image node_id 21 for calling the TopicModelWidget obj's underlying member method code with example usage: obj.top_documents_per_topic(text_docs, topic_names, num_docs, summarize_docs, summary_words) and returns: all_top_docs_df