class_docstr: Helper object for creating Attention visualizations.
class_docstr_tok: ["Helper","object","for","creating","Attention","visualizations","."]
docstr: Constructs the data needed for visualizing attentions.
  
  Args:
    sess: A tf.Session object.
    input_string: The input sentence to be translated and visualized.
  
  Returns:
    Tuple of (
        output_string: The translated sentence.
        input_list: Tokenized input sentence.
        output_list: Tokenized translation.
        att_mats: Tuple of attention matrices; (
            enc_atts: Encoder self attention weights.
              A list of `num_layers` numpy arrays of size
              (batch_size, num_heads, inp_len, inp_len)
            dec_atts: Decoder self attention weights.
              A list of `num_layers` numpy arrays of size
              (batch_size, num_heads, out_len, out_len)
            encdec_atts: Encoder-Decoder attention weights.
              A list of `num_layers` numpy arrays of size
              (batch_size, num_heads, out_len, inp_len)
        )
docstr_tok: ["Constructs","the","data","needed","for","visualizing","attentions",".","Args",":","sess",":","A","tf.Session","object",".","input_string",":","The","input","sentence","to","be","translated","and","visualized",".","Returns",":","Tuple","of","(","output_string",":","The","translated","sentence",".","input_list",":","Tokenized","input","sentence",".","output_list",":","Tokenized","translation",".","att_mats",":","Tuple","of","attention","matrices",";","(","enc_atts",":","Encoder","self","attention","weights",".","A","list","of","`","num_layers","`","numpy","arrays","of","size","(","batch_size",",","num_heads",",","inp_len",",","inp_len",")","dec_atts",":","Decoder","self","attention","weights",".","A","list","of","`","num_layers","`","numpy","arrays","of","size","(","batch_size",",","num_heads",",","out_len",",","out_len",")","encdec_atts",":","Encoder-Decoder","attention","weights",".","A","list","of","`","num_layers","`","numpy","arrays","of","size","(","batch_size",",","num_heads",",","out_len",",","inp_len",")",")"]
code: def get_vis_data_from_string(self, sess, input_string):
      """Constructs the data needed for visualizing attentions.
  
      Args:
        sess: A tf.Session object.
        input_string: The input sentence to be translated and visualized.
  
      Returns:
        Tuple of (
            output_string: The translated sentence.
            input_list: Tokenized input sentence.
            output_list: Tokenized translation.
            att_mats: Tuple of attention matrices; (
                enc_atts: Encoder self attention weights.
                  A list of `num_layers` numpy arrays of size
                  (batch_size, num_heads, inp_len, inp_len)
                dec_atts: Decoder self attention weights.
                  A list of `num_layers` numpy arrays of size
                  (batch_size, num_heads, out_len, out_len)
                encdec_atts: Encoder-Decoder attention weights.
                  A list of `num_layers` numpy arrays of size
                  (batch_size, num_heads, out_len, inp_len)
            )
      """
      encoded_inputs = self.encode(input_string)
  
      # Run inference graph to get the translation.
      out = sess.run(
          self.samples,
          {
              self.inputs: encoded_inputs,
          },
      )
  
      # Run the decoded translation through the training graph to get the
      # attention tensors.
      att_mats = sess.run(
          self.att_mats,
          {
              self.inputs: encoded_inputs,
              self.targets: np.reshape(out, [1, -1, 1, 1]),
          },
      )
  
      output_string = self.decode(out)
      input_list = self.encode_list(encoded_inputs)
      output_list = self.decode_list(out)
  
      return output_string, input_list, output_list, att_mats
  
file_path: tensor2tensor/tensor2tensor/visualization/visualization.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import numpy
  from tensor2tensor import models
  from tensor2tensor import problems
  from tensor2tensor.utils import registry
  from tensor2tensor.utils import trainer_lib
  import tensorflow.compat.v1
  from tensorflow.compat.v1 import estimator
label_desc: Use image node_id 6 for calling the AttentionVisualizer obj's underlying member method code with example usage: obj.get_vis_data_from_string(sess, input_string) and returns: output_string,  input_list,  output_list,  att_mats