src/transformers/pipelines/text_generation.py/TextGenerationPipeline/postprocess
class TextGenerationPipeline:    def postprocess(self, model_outputs, return_type=ReturnType.FULL_TEXT, clean_up_tokenization_spaces=True):
        generated_sequence = model_outputs["generated_sequence"]
        input_ids = model_outputs["input_ids"]
        prompt_text = model_outputs["prompt_text"]
        if self.framework == "pt" and generated_sequence is not None:
            generated_sequence = generated_sequence.cpu()
        generated_sequence = generated_sequence.numpy().tolist()
        if return_type == ReturnType.TENSORS:
            record = {"generated_token_ids": generated_sequence}
        elif return_type in {ReturnType.NEW_TEXT, ReturnType.FULL_TEXT}:
            # Decode text
            record = []
            for sequence in generated_sequence:
                text = self.tokenizer.decode(
                    sequence,
                    skip_special_tokens=True,
                    clean_up_tokenization_spaces=clean_up_tokenization_spaces,
                )

                # Remove PADDING prompt of the sequence if XLNet or Transfo-XL model is used
                if input_ids is None:
                    prompt_length = 0
                else:
                    prompt_length = len(
                        self.tokenizer.decode(
                            input_ids[0],
                            skip_special_tokens=True,
                            clean_up_tokenization_spaces=clean_up_tokenization_spaces,
                        )
                    )

                if return_type == ReturnType.FULL_TEXT:
                    all_text = prompt_text + text[prompt_length:]
                else:
                    all_text = text[prompt_length:]

                item = {"generated_text": all_text}
                record.append(item)

        return record