docstr: Encode a batch of text to T5 embeddings.
docstr_tok: ["Encode","a","batch","of","text","to","T5","embeddings","."]
code: def encode(self, text_batch, device="cuda"):
      """
      Encode a batch of text to T5 embeddings.
      """
      encoded = self.tokenizer.batch_encode_plus(
          text_batch,
          return_tensors="pt",
          padding="max_length",
          max_length=self.model_seq_len,
          truncation=True,
      )
      # We expect all the processing is done in GPU.
      input_ids = encoded.input_ids.to(device=device)
      attn_mask = encoded.attention_mask.to(device=device)
  
      with torch.no_grad():
          output = self.model(
              input_ids=input_ids, attention_mask=attn_mask
          )
          encoded_text = output.last_hidden_state.detach()
  
      encoded_text = encoded_text[:, 0 : self.max_seq_len]
      attn_mask = attn_mask[:, 0 : self.max_seq_len]
      for bnum in range(encoded_text.shape[0]):
          nvalid_elem = attn_mask[bnum].sum().item()
          encoded_text[bnum][nvalid_elem:] = 0
  
      return encoded_text, attn_mask
  
imports: import os
  import torch
  from transformers import T5Config, T5EncoderModel, T5Tokenizer
label_desc: Use image node_id 2 for calling the T5Encoder obj's underlying member method code with example usage: obj.encode(text_batch, device) and returns: encoded_text,  attn_mask