code: def saliency_plot(shap_values):
      uuid = "".join(random.choices(string.ascii_lowercase, k=20))
  
      unpacked_values, clustering = unpack_shap_explanation_contents(
          shap_values
      )
      (
          tokens,
          values,
          group_sizes,
          token_id_to_node_id_mapping,
          collapsed_node_ids,
      ) = process_shap_values(
          shap_values.data,
          unpacked_values[:, 0],
          1,
          "",
          clustering,
          True,
      )
  
      def compress_shap_matrix(shap_matrix, group_sizes):
          compressed_matrix = np.zeros(
              (group_sizes.shape[0], shap_matrix.shape[1])
          )
          counter = 0
          for index in range(len(group_sizes)):
              compressed_matrix[index, :] = np.sum(
                  shap_matrix[
                      counter : counter + group_sizes[index], :
                  ],
                  axis=0,
              )
              counter += group_sizes[index]
  
          return compressed_matrix
  
      compressed_shap_matrix = compress_shap_matrix(
          shap_values.values, group_sizes
      )
  
      # generate background colors of saliency plot
  
      def get_colors(shap_values):
          input_colors = []
          cmax = max(
              abs(compressed_shap_matrix.min()),
              abs(compressed_shap_matrix.max()),
          )
          for row_index in range(compressed_shap_matrix.shape[0]):
              input_colors_row = []
              for col_index in range(compressed_shap_matrix.shape[1]):
                  scaled_value = (
                      0.5
                      + 0.5
                      * compressed_shap_matrix[row_index, col_index]
                      / cmax
                  )
                  color = colors.red_transparent_blue(scaled_value)
                  color = "rgba" + str(
                      (
                          color[0] * 255,
                          color[1] * 255,
                          color[2] * 255,
                          color[3],
                      )
                  )
                  input_colors_row.append(color)
              input_colors.append(input_colors_row)
  
          return input_colors
  
      model_output = shap_values.output_names
  
      input_colors = get_colors(shap_values)
  
      out = '<table border = "1" cellpadding = "5" cellspacing = "5" style="overflow-x:scroll;display:block;">'
  
      # add top row containing input tokens
      out += "<tr>"
      out += "<th></th>"
  
      for j in range(compressed_shap_matrix.shape[0]):
          out += (
              "<th>"
              + tokens[j]
              .replace("<", "&lt;")
              .replace(">", "&gt;")
              .replace(" ##", "")
              .replace("▁", "")
              .replace("Ġ", "")
              + "</th>"
          )
      out += "</tr>"
  
      for row_index in range(compressed_shap_matrix.shape[1]):
          out += "<tr>"
          out += (
              "<th>"
              + model_output[row_index]
              .replace("<", "&lt;")
              .replace(">", "&gt;")
              .replace(" ##", "")
              .replace("▁", "")
              .replace("Ġ", "")
              + "</th>"
          )
          for col_index in range(compressed_shap_matrix.shape[0]):
              out += (
                  '<th style="background:'
                  + input_colors[col_index][row_index]
                  + '">'
                  + str(
                      round(
                          compressed_shap_matrix[col_index][row_index],
                          3,
                      )
                  )
                  + "</th>"
              )
          out += "</tr>"
  
      out += "</table>"
  
      saliency_plot_html = f"""
          <div id="{uuid}_saliency_plot" class="{uuid}_viz_content">
              <div style="margin:5px;font-family:sans-serif;font-weight:bold;">
                  <span style="font-size: 20px;"> Saliency Plot </span>
                  <br>
                  x-axis: Output Text
                  <br>
                  y-axis: Input Text
              </div>
              {out}
          </div>
      """
      return saliency_plot_html
  
file_path: shap/shap/plots/_text.py
imports: import json
  import random
  import string
  import numpy
  from .None import colors
label_desc: Use image node_id 6 for calling a global function with example usage: saliency_plot(shap_values) and returns: saliency_plot_html, compressed_matrix, input_colors