def predict(
        self,
        test_dataset,
        num_gpus=None,
        gpu_ids=None,
        local_rank=-1,
        batch_size=16,
        alpha=0.6,
        beam_size=5,
        min_length=15,
        max_length=150,
        fp16=False,
        verbose=True,
    ):
        """
        Predict the summarization for the input data iterator.

        Args:
            test_dataset (SummarizationDataset): Dataset for which the summary
                to be predicted.
            num_gpus (int, optional): The number of GPUs used in prediction.
                Defaults to 1.
            gpu_ids (list): List of GPU IDs to be used.
                If set to None, the first num_gpus GPUs will be used.
                Defaults to None.
            local_rank (int, optional): Local rank of the device in distributed
                inferencing. Defaults to -1, which means non-distributed inferencing.
            batch_size (int, optional): The number of test examples in each batch.
                Defaults to 16.
            alpha (float, optional): Length penalty. Defaults to 0.6.
            beam_size (int, optional): Beam size of beam search. Defaults to 5.
            min_length (int, optional): Minimum number of tokens in the output sequence.
                Defaults to 15.
            max_length (int, optional):  Maximum number of tokens in output
                sequence. Defaults to 150.
            fp16 (bool, optional): Whether to use half-precision model for prediction.
                Defaults to False.
            verbose (bool, optional): Whether to print out the training log.
                Defaults to True.

        Returns:
            List of strings which are the summaries

        """
        device, num_gpus = get_device(
            num_gpus=num_gpus, gpu_ids=gpu_ids, local_rank=local_rank
        )

        # move model to devices
        def this_model_move_callback(model, device):
            model = move_model_to_device(model, device)
            return parallelize_model(
                model, device, num_gpus=num_gpus, gpu_ids=gpu_ids, local_rank=local_rank
            )

        if fp16:
            self.model = self.model.half()

        self.model = move_model_to_device(self.model, device)
        self.model.eval()

        predictor = build_predictor(
            self.processor.tokenizer,
            self.processor.symbols,
            self.model,
            alpha=alpha,
            beam_size=beam_size,
            min_length=min_length,
            max_length=max_length,
        )
        predictor = this_model_move_callback(predictor, device)
        self.model = parallelize_model(
            self.model,
            device,
            num_gpus=num_gpus,
            gpu_ids=gpu_ids,
            local_rank=local_rank,
        )

        test_sampler = SequentialSampler(test_dataset)

        def collate_fn(data):
            return self.processor.collate(
                data, self.max_pos_length, device, train_mode=False
            )

        test_dataloader = DataLoader(
            test_dataset,
            sampler=test_sampler,
            batch_size=batch_size,
            collate_fn=collate_fn,
        )
        print("dataset length is {}".format(len(test_dataset)))

        def format_summary(translation):
            """ Transforms the output of the `from_batch` function
            into nicely formatted summaries.
            """
            raw_summary = translation
            summary = (
                raw_summary.replace("[unused0]", "")
                .replace("[unused3]", "")
                .replace("[CLS]", "")
                .replace("[SEP]", "")
                .replace("[PAD]", "")
                .replace("[unused1]", "")
                .replace(r" +", " ")
                .replace(" [unused2] ", ".")
                .replace("[unused2]", "")
                .strip()
            )

            return summary

        def generate_summary_from_tokenid(preds, pred_score):
            batch_size = preds.size()[0]  # batch.batch_size
            translations = []
            for b in range(batch_size):
                if len(preds[b]) < 1:
                    pred_sents = ""
                else:
                    pred_sents = self.processor.tokenizer.convert_ids_to_tokens(
                        [int(n) for n in preds[b] if int(n) != 0]
                    )
                    pred_sents = " ".join(pred_sents).replace(" ##", "")
                translations.append(pred_sents)
            return translations

        generated_summaries = []

        for batch in tqdm(
            test_dataloader, desc="Generating summary", disable=not verbose
        ):
            input = self.processor.get_inputs(batch, device, "bert", train_mode=False)
            translations, scores = predictor(**input)

            translations_text = generate_summary_from_tokenid(translations, scores)
            summaries = [format_summary(t) for t in translations_text]
            generated_summaries.extend(summaries)

        # release GPU memories
        self.model.cpu()
        torch.cuda.empty_cache()

        return generated_summaries

        Predict the summarization for the input data iterator.

        Args:
            test_dataset (SummarizationDataset): Dataset for which the summary
                to be predicted.
            num_gpus (int, optional): The number of GPUs used in prediction.
                Defaults to 1.
            gpu_ids (list): List of GPU IDs to be used.
                If set to None, the first num_gpus GPUs will be used.
                Defaults to None.
            local_rank (int, optional): Local rank of the device in distributed
                inferencing. Defaults to -1, which means non-distributed inferencing.
            batch_size (int, optional): The number of test examples in each batch.
                Defaults to 16.
            alpha (float, optional): Length penalty. Defaults to 0.6.
            beam_size (int, optional): Beam size of beam search. Defaults to 5.
            min_length (int, optional): Minimum number of tokens in the output sequence.
                Defaults to 15.
            max_length (int, optional):  Maximum number of tokens in output
                sequence. Defaults to 150.
            fp16 (bool, optional): Whether to use half-precision model for prediction.
                Defaults to False.
            verbose (bool, optional): Whether to print out the training log.
                Defaults to True.

        Returns:
            List of strings which are the summaries

        
utils_nlp/models/transformers/abstractive_summarization_bertsum.py