class_docstr: T5 using HuggingFace Transformers and Keras.
  
  This version supports embeddings, attention, and force-decoding of the target
  text, as well as more options to control decoding (such as beam search).
docstr: Get predictions for a batch of tokenized examples.
  
  Each forward pass produces the following:
    logits: batch_size x dec_len x vocab_size
    decoder_past_key_value_states: tuple with cached outputs.
    dec_states: tuple[len:dec_layers]:
                batch_size x dec_len x hid_size
    dec_attn: [optional] tuple[len:dec_layers+1]
              batch_size x num_heads x dec_len x dec_len
    enc_final_state: batch_size x enc_len x hid_size
    enc_states: tuple[len:enc_layers]:
                batch_size x enc_len x hid_size
    enc_attn: [optional] tuple[len:enc_layers+1]
              batch_size x num_heads x enc_len x enc_len
  
  The two optional attention fields are only returned if
  config.output_attention is set.
  
  Args:
    encoded_inputs: Dict as returned from Tokenizer for inputs.
    encoded_targets: Dict as returned from Tokenizer for outputs
  
  Returns:
    batched_outputs: dict[str, tf.Tensor]
docstr_tok: ["Get","predictions","for","a","batch","of","tokenized","examples",".","Each","forward","pass","produces","the","following",":","logits",":","batch_size","x","dec_len","x","vocab_size","decoder_past_key_value_states",":","tuple","with","cached","outputs",".","dec_states",":","tuple","[","len",":","dec_layers","]",":","batch_size","x","dec_len","x","hid_size","dec_attn",":","[","optional","]","tuple","[","len",":","dec_layers+1","]","batch_size","x","num_heads","x","dec_len","x","dec_len","enc_final_state",":","batch_size","x","enc_len","x","hid_size","enc_states",":","tuple","[","len",":","enc_layers","]",":","batch_size","x","enc_len","x","hid_size","enc_attn",":","[","optional","]","tuple","[","len",":","enc_layers+1","]","batch_size","x","num_heads","x","enc_len","x","enc_len","The","two","optional","attention","fields","are","only","returned","if","config.output_attention","is","set",".","Args",":","encoded_inputs",":","Dict","as","returned","from","Tokenizer","for","inputs",".","encoded_targets",":","Dict","as","returned","from","Tokenizer","for","outputs","Returns",":","batched_outputs",":","dict","[","str",",","tf.Tensor","]"]
code: def _force_decode(self, encoded_inputs, encoded_targets):
      """Get predictions for a batch of tokenized examples.
  
      Each forward pass produces the following:
        logits: batch_size x dec_len x vocab_size
        decoder_past_key_value_states: tuple with cached outputs.
        dec_states: tuple[len:dec_layers]:
                    batch_size x dec_len x hid_size
        dec_attn: [optional] tuple[len:dec_layers+1]
                  batch_size x num_heads x dec_len x dec_len
        enc_final_state: batch_size x enc_len x hid_size
        enc_states: tuple[len:enc_layers]:
                    batch_size x enc_len x hid_size
        enc_attn: [optional] tuple[len:enc_layers+1]
                  batch_size x num_heads x enc_len x enc_len
  
      The two optional attention fields are only returned if
      config.output_attention is set.
  
      Args:
        encoded_inputs: Dict as returned from Tokenizer for inputs.
        encoded_targets: Dict as returned from Tokenizer for outputs
  
      Returns:
        batched_outputs: dict[str, tf.Tensor]
      """
      results = self.model(
          input_ids=encoded_inputs["input_ids"],
          decoder_input_ids=encoded_targets["input_ids"],
          attention_mask=encoded_inputs["attention_mask"],
          decoder_attention_mask=encoded_targets["attention_mask"],
      )
  
      model_probs = tf.nn.softmax(results.logits, axis=-1)
      top_k = tf.math.top_k(
          model_probs, k=self.config.token_top_k, sorted=True, name=None
      )
      batched_outputs = {
          "input_ids": encoded_inputs["input_ids"],
          "input_ntok": tf.reduce_sum(
              encoded_inputs["attention_mask"], axis=1
          ),
          "target_ids": encoded_targets["input_ids"],
          "target_ntok": tf.reduce_sum(
              encoded_targets["attention_mask"], axis=1
          ),
          "top_k_indices": top_k.indices,
          "top_k_probs": top_k.values,
      }
      # encoder_last_hidden_state is <float>[batch_size, num_tokens, emb_dim]
      # take the mean over real tokens to get <float>[batch_size, emb_dim]
      batched_outputs["encoder_final_embedding"] = masked_token_mean(
          results.encoder_last_hidden_state,
          encoded_inputs["attention_mask"],
      )
  
      if self.config.output_attention:
          for i in range(len(results.decoder_attentions)):
              batched_outputs[
                  f"decoder_layer_{i+1:d}_attention"
              ] = results.decoder_attentions[i]
          for i in range(len(results.encoder_attentions)):
              batched_outputs[
                  f"encoder_layer_{i+1:d}_attention"
              ] = results.encoder_attentions[i]
  
      return batched_outputs
  
imports: import re
  import attr
  from lit_nlp.api import model
  from lit_nlp.api import types
  from lit_nlp.examples.models import model_utils
  from lit_nlp.lib import file_cache
  from lit_nlp.lib import utils
  import tensorflow
  import tensorflow_text
  import transformers
  from rouge_score import rouge_scorer
label_desc: Use image node_id 4 for calling the T5HFModel obj's underlying member method code with example usage: obj._force_decode(encoded_inputs, encoded_targets) and returns: batched_outputs