class_docstr: Wrapper class for Hugging Face Transformers PyTorch T5 model.
class_docstr_tok: ["Wrapper","class","for","Hugging","Face","Transformers","PyTorch","T5","model","."]
docstr: Evaluate the model on the given Mixture or Task.
  
  *Note*: If a checkpoint step is provided (i.e. `checkpoint_steps is not
  None`), the model's state will be replaced by the state in those
  checkpoints. If you have not saved your model before calling `eval`, you
  should call `save_checkpoint` before `eval` to avoid losing its parameter
  values and state.
  
  Args:
    inputs: list of str or str, either a list of inputs to feed into the
      model or the path to a text file that contains a single input on each
      line.
    sequence_length: dict of int, a dict mapping feature name to length.
    batch_size: int, the number of padded sequences in each batch.
    output_file: str or None, path to write out predictions or None to skip
      writing.
    vocabulary: t5.data.vocabularies.Vocabulary or dict or None. Either the
      Vocabulary to use for processing inputs and targets, a dict mapping
      "inputs" to a Vocabulary for encoding the inputs and "targets" for
      decoding the predictions, or None (default) to use a
      t5.data.SentencePieceVocabulary with the provided
      sentencepiece_model_path (as was used in all pre-trained T5 models).
    **generate_kwargs: Additional keyword arguments to pass to
      `transformers.PretrainedModel.generate()`, for example to change the
      decoding strategy. See the documentation for
      `transformers.PretrainedModel.generate()` for options.
docstr_tok: ["Evaluate","the","model","on","the","given","Mixture","or","Task",".","*","Note","*",":","If","a","checkpoint","step","is","provided","(","i.e",".","`","checkpoint_steps","is","not","None","`",")",",","the","model","'s","state","will","be","replaced","by","the","state","in","those","checkpoints",".","If","you","have","not","saved","your","model","before","calling","`","eval","`",",","you","should","call","`","save_checkpoint","`","before","`","eval","`","to","avoid","losing","its","parameter","values","and","state",".","Args",":","inputs",":","list","of","str","or","str",",","either","a","list","of","inputs","to","feed","into","the","model","or","the","path","to","a","text","file","that","contains","a","single","input","on","each","line",".","sequence_length",":","dict","of","int",",","a","dict","mapping","feature","name","to","length",".","batch_size",":","int",",","the","number","of","padded","sequences","in","each","batch",".","output_file",":","str","or","None",",","path","to","write","out","predictions","or","None","to","skip","writing",".","vocabulary",":","t5.data.vocabularies.Vocabulary","or","dict","or","None",".","Either","the","Vocabulary","to","use","for","processing","inputs","and","targets",",","a","dict","mapping","``","inputs","''","to","a","Vocabulary","for","encoding","the","inputs","and","``","targets","''","for","decoding","the","predictions",",","or","None","(","default",")","to","use","a","t5.data.SentencePieceVocabulary","with","the","provided","sentencepiece_model_path","(","as","was","used","in","all","pre-trained","T5","models",")",".","*","*","generate_kwargs",":","Additional","keyword","arguments","to","pass","to","`","transformers.PretrainedModel.generate","(",")","`",",","for","example","to","change","the","decoding","strategy",".","See","the","documentation","for","`","transformers.PretrainedModel.generate","(",")","`","for","options","."]
code: def predict(
      self,
      inputs,
      sequence_length,
      batch_size,
      output_file=None,
      vocabulary=None,
      **generate_kwargs,
  ):
      """Evaluate the model on the given Mixture or Task.
  
      *Note*: If a checkpoint step is provided (i.e. `checkpoint_steps is not
      None`), the model's state will be replaced by the state in those
      checkpoints. If you have not saved your model before calling `eval`, you
      should call `save_checkpoint` before `eval` to avoid losing its parameter
      values and state.
  
      Args:
        inputs: list of str or str, either a list of inputs to feed into the
          model or the path to a text file that contains a single input on each
          line.
        sequence_length: dict of int, a dict mapping feature name to length.
        batch_size: int, the number of padded sequences in each batch.
        output_file: str or None, path to write out predictions or None to skip
          writing.
        vocabulary: t5.data.vocabularies.Vocabulary or dict or None. Either the
          Vocabulary to use for processing inputs and targets, a dict mapping
          "inputs" to a Vocabulary for encoding the inputs and "targets" for
          decoding the predictions, or None (default) to use a
          t5.data.SentencePieceVocabulary with the provided
          sentencepiece_model_path (as was used in all pre-trained T5 models).
        **generate_kwargs: Additional keyword arguments to pass to
          `transformers.PretrainedModel.generate()`, for example to change the
          decoding strategy. See the documentation for
          `transformers.PretrainedModel.generate()` for options.
      """
      if isinstance(inputs, str):
          if not tf.io.gfile.exists(inputs):
              raise ValueError(
                  f"A str was provided for `inputs`, but the path {inputs} does not "
                  "exist. If you want the model's output for {inputs}, you should "
                  "feed in inputs=['{inputs}']"
              )
          with tf.io.gfile.GFile(inputs) as f:
              inputs = [l.strip() for l in f]
  
      if vocabulary is None:
          vocab = t5.data.get_default_vocabulary()
          vocabs = {"inputs": vocab, "targets": vocab}
      elif isinstance(vocabulary, seqio.Vocabulary):
          vocabs = {"inputs": vocabulary, "targets": vocabulary}
      elif isinstance(vocabulary, dict):
          vocabs = vocabulary
      else:
          raise ValueError(
              "vocabulary must be a dict, a Vocabulary, or None"
          )
  
      dataset = tf.data.Dataset.from_tensor_slices(inputs)
      dataset = dataset.map(
          lambda x: {
              "inputs": tf.cast(vocabs["inputs"].encode_tf(x), tf.int64)
          },
          num_parallel_calls=tf.data.experimental.AUTOTUNE,
      )
      dataset = tokens_to_batches(
          dataset, sequence_length, batch_size, ["inputs"]
      )
  
      predictions = []
      for batch in dataset:
          predicted_tokens = self._model.generate(
              input_ids=self.to_tensor(batch["inputs"]),
              **generate_kwargs,
          )
          predicted_tokens = predicted_tokens.cpu().numpy().tolist()
          predictions.extend(
              [vocabs["targets"].decode(p) for p in predicted_tokens]
          )
  
      for inp, pred in zip(inputs, predictions):
          logging.info("%s\n  -> %s", inp, pred)
  
      if output_file is not None:
          utils.write_lines_to_file(predictions, output_file)
  
imports: import functools
  import itertools
  import os
  import re
  import time
  from absl import logging
  import mesh_tensorflow.transformer.dataset
  import seqio
  import t5.data
  from t5.models import utils
  from t5.models.t5_model import T5Model
  import tensorflow.compat.v1
  import tensorflow_datasets
  import torch
  import torch.utils.tensorboard
label_desc: Use image node_id 11 for calling the HfPyTorchModel obj's underlying member method code with example usage: obj.predict(inputs, sequence_length, batch_size, output_file, vocabulary) without return types