code: def visualize_text(
      datarecords: Iterable[VisualizationDataRecord],
      legend: bool = True,
  ) -> (
      "HTML"
  ):  # In quotes because this type doesn't exist in standalone mode
      assert HAS_IPYTHON, (
          "IPython must be available to visualize text. "
          "Please run 'pip install ipython'."
      )
      dom = ["<table width: 100%>"]
      rows = [
          "<tr><th>True Label</th>"
          "<th>Predicted Label</th>"
          "<th>Attribution Label</th>"
          "<th>Attribution Score</th>"
          "<th>Word Importance</th>"
      ]
      for datarecord in datarecords:
          rows.append(
              "".join(
                  [
                      "<tr>",
                      format_classname(datarecord.true_class),
                      format_classname(
                          "{0} ({1:.2f})".format(
                              datarecord.pred_class,
                              datarecord.pred_prob,
                          )
                      ),
                      format_classname(datarecord.attr_class),
                      format_classname(
                          "{0:.2f}".format(datarecord.attr_score)
                      ),
                      format_word_importances(
                          datarecord.raw_input_ids,
                          datarecord.word_attributions,
                      ),
                      "<tr>",
                  ]
              )
          )
  
      if legend:
          dom.append(
              '<div style="border-top: 1px solid; margin-top: 5px; \
              padding-top: 5px; display: inline-block">'
          )
          dom.append("<b>Legend: </b>")
  
          for value, label in zip(
              [-1, 0, 1], ["Negative", "Neutral", "Positive"]
          ):
              dom.append(
                  '<span style="display: inline-block; width: 10px; height: 10px; \
                  border: 1px solid; background-color: \
                  {value}"></span> {label}  '.format(
                      value=_get_color(value), label=label
                  )
              )
          dom.append("</div>")
  
      dom.append("".join(rows))
      dom.append("</table>")
      html = HTML("".join(dom))
      display(html)
  
      return html
  
imports: import warnings
  from enum import Enum
  from typing import Any, Iterable, List, Optional, Tuple, Union
  import numpy
  from matplotlib import cm, colors, pyplot
  from matplotlib.collections import LineCollection
  from matplotlib.colors import LinearSegmentedColormap
  from matplotlib.figure import Figure
  from matplotlib.pyplot import axis, figure
  from mpl_toolkits.axes_grid1 import make_axes_locatable
  from numpy import ndarray
label_desc: Use image node_id 13 for calling a global function with example usage: visualize_text(datarecords, legend) and returns: html