code: def text2text_generate_encoded(sample_generator,
                                 vocab,
                                 targets_vocab=None,
                                 has_inputs=True,
                                 inputs_prefix="",
                                 targets_prefix=""):
    
    targets_vocab = targets_vocab or vocab
    for sample in sample_generator:
      if has_inputs:
        sample["inputs"] = vocab.encode(inputs_prefix + sample["inputs"])
        sample["inputs"].append(text_encoder.EOS_ID)
      sample["targets"] = targets_vocab.encode(targets_prefix + sample["targets"])
      sample["targets"].append(text_encoder.EOS_ID)
      yield sample
docs: Encode Text2Text samples from the generator with the vocab.