docstr: Generates a visualization of a set of documents based on model.
  If <texts> is supplied, raw documents will be first transformed into document-topic
  matrix.  If <doc_topics> is supplied, then this will be used for visualization instead.
  Args:
      texts(list of str): list of document texts.  Mutually-exclusive with <doc_topics>
      doc_topics(ndarray): pre-computed topic distribution for each document in texts.
                           Mutually-exclusive with <texts>.
      width(int): width of image
      height(int): height of image
      point_size(int): size of circles in plot
      title(str):  title of visualization
      extra_info(dict of lists): A user-supplied information for each datapoint (attributes of the datapoint).
                                 The keys are field names.  The values are lists - each of which must
                                 be the same number of elements as <texts> or <doc_topics>. These fields are displayed
                                 when hovering over datapoints in the visualization.
      colors(list of str):  list of Hex color codes for each datapoint.
                            Length of list must match either len(texts) or doc_topics.shape[0]
      filepath(str):             Optional filepath to save the interactive visualization
docstr_tok: ["Generates","a","visualization","of","a","set","of","documents","based","on","model",".","If","<","texts",">","is","supplied",",","raw","documents","will","be","first","transformed","into","document-topic","matrix",".","If","<","doc_topics",">","is","supplied",",","then","this","will","be","used","for","visualization","instead",".","Args",":","texts","(","list","of","str",")",":","list","of","document","texts",".","Mutually-exclusive","with","<","doc_topics",">","doc_topics","(","ndarray",")",":","pre-computed","topic","distribution","for","each","document","in","texts",".","Mutually-exclusive","with","<","texts",">",".","width","(","int",")",":","width","of","image","height","(","int",")",":","height","of","image","point_size","(","int",")",":","size","of","circles","in","plot","title","(","str",")",":","title","of","visualization","extra_info","(","dict","of","lists",")",":","A","user-supplied","information","for","each","datapoint","(","attributes","of","the","datapoint",")",".","The","keys","are","field","names",".","The","values","are","lists","-","each","of","which","must","be","the","same","number","of","elements","as","<","texts",">","or","<","doc_topics",">",".","These","fields","are","displayed","when","hovering","over","datapoints","in","the","visualization",".","colors","(","list","of","str",")",":","list","of","Hex","color","codes","for","each","datapoint",".","Length","of","list","must","match","either","len","(","texts",")","or","doc_topics.shape","[","0","]","filepath","(","str",")",":","Optional","filepath","to","save","the","interactive","visualization"]
code: def visualize_documents(
      self,
      texts=None,
      doc_topics=None,
      width=700,
      height=700,
      point_size=5,
      title="Document Visualization",
      extra_info={},
      colors=None,
      filepath=None,
  ):
      """
      Generates a visualization of a set of documents based on model.
      If <texts> is supplied, raw documents will be first transformed into document-topic
      matrix.  If <doc_topics> is supplied, then this will be used for visualization instead.
      Args:
          texts(list of str): list of document texts.  Mutually-exclusive with <doc_topics>
          doc_topics(ndarray): pre-computed topic distribution for each document in texts.
                               Mutually-exclusive with <texts>.
          width(int): width of image
          height(int): height of image
          point_size(int): size of circles in plot
          title(str):  title of visualization
          extra_info(dict of lists): A user-supplied information for each datapoint (attributes of the datapoint).
                                     The keys are field names.  The values are lists - each of which must
                                     be the same number of elements as <texts> or <doc_topics>. These fields are displayed
                                     when hovering over datapoints in the visualization.
          colors(list of str):  list of Hex color codes for each datapoint.
                                Length of list must match either len(texts) or doc_topics.shape[0]
          filepath(str):             Optional filepath to save the interactive visualization
      """
  
      # error-checking
      if texts is not None:
          length = len(texts)
      else:
          length = doc_topics.shape[0]
      if colors is not None and len(colors) != length:
          raise ValueError(
              "length of colors is not consistent with length of texts or doctopics"
          )
      if texts is not None and doc_topics is not None:
          raise ValueError(
              "texts is mutually-exclusive with doc_topics"
          )
      if texts is None and doc_topics is None:
          raise ValueError("One of texts or doc_topics is required.")
      if extra_info:
          invalid_keys = ["x", "y", "topic", "fill_color"]
          for k in extra_info.keys():
              if k in invalid_keys:
                  raise ValueError(
                      'cannot use "%s" as key in extra_info' % (k)
                  )
              lst = extra_info[k]
              if len(lst) != length:
                  raise ValueError(
                      "texts and extra_info lists must be same size"
                  )
  
      # check fo bokeh
      try:
          import bokeh.plotting as bp
          from bokeh.io import output_notebook
          from bokeh.models import HoverTool
          from bokeh.plotting import save
      except:
          warnings.warn(
              "visualize_documents method requires bokeh package: pip install bokeh"
          )
          return
  
      # prepare data
      if doc_topics is not None:
          X_topics = doc_topics
      else:
          if self.verbose:
              print("transforming texts...", end="")
          X_topics = self.predict(texts, harden=False)
          if self.verbose:
              print("done.")
  
      # reduce to 2-D
      if self.verbose:
          print("reducing to 2 dimensions...", end="")
      tsne_model = TSNE(
          n_components=2,
          verbose=self.verbose,
          random_state=0,
          angle=0.99,
          init="pca",
      )
      tsne_lda = tsne_model.fit_transform(X_topics)
      print("done.")
  
      # get random colormap
      colormap = U.get_random_colors(self.n_topics)
  
      # generate inline visualization in Jupyter notebook
      lda_keys = self._harden_topics(X_topics)
      if colors is None:
          colors = colormap[lda_keys]
      topic_summaries = self.get_topics(n_words=5)
      os.environ["BOKEH_RESOURCES"] = "inline"
      output_notebook()
      dct = {
          "x": tsne_lda[:, 0],
          "y": tsne_lda[:, 1],
          "topic": [topic_summaries[tid] for tid in lda_keys],
          "fill_color": colors,
      }
      tool_tups = [
          ("index", "$index"),
          ("(x,y)", "($x,$y)"),
          ("topic", "@topic"),
      ]
      for k in extra_info.keys():
          dct[k] = extra_info[k]
          tool_tups.append((k, "@" + k))
  
      source = bp.ColumnDataSource(data=dct)
      hover = HoverTool(tooltips=tool_tups)
      p = bp.figure(
          width=width,
          height=height,
          tools=[
              hover,
              "save",
              "pan",
              "wheel_zoom",
              "box_zoom",
              "reset",
          ],
          # tools="pan,wheel_zoom,box_zoom,reset,hover,previewsave",
          title=title,
      )
      # plot_lda = bp.figure(plot_width=1400, plot_height=1100,
      # title=title,
      # tools="pan,wheel_zoom,box_zoom,reset,hover,previewsave",
      # x_axis_type=None, y_axis_type=None, min_border=1)
      p.circle(
          "x",
          "y",
          size=point_size,
          source=source,
          fill_color="fill_color",
      )
      bp.show(p)
      if filepath is not None:
          bp.output_file(filepath)
          bp.save(p)
      return
  
imports: import time
  from ..None import utils
  from ..imports import *
  from .None import preprocessor
  from .None import textutils
label_desc: Use image node_id 15 for calling the TopicModel obj's underlying member method code with example usage: obj.visualize_documents(texts, doc_topics, width, height, point_size, title, extra_info, colors, filepath) without return types