def METHOD_NAME(self, sample_list, batch_size):
    # turn off teacher forcing during beam search
    # (otherwise one cannot run beam search on val set)
    self.teacher_forcing = self.config.inference.type != "beam_search" and hasattr(
        sample_list, "text"
    )
    data = {}
    if self.teacher_forcing:
        caption_lengths, sort_ind = sample_list.caption_len.sort(
            dim=0, descending=True
        )
        data["decode_lengths"] = (caption_lengths - 1).tolist()
        sample_list.text = sample_list.text[sort_ind]
        sample_list.answers = sample_list.answers[sort_ind]
        sample_list.image_feature_0 = sample_list.image_feature_0[sort_ind]
        data["texts"] = sample_list.text
        timesteps = max(data["decode_lengths"])
        sample_list.add_field("targets", sample_list.text[:, 1:])
    else:
        data["texts"] = sample_list.answers.new_full(
            (batch_size, 1), self.vocab.SOS_INDEX, dtype=torch.long
        )
        timesteps = self.text_processor.max_length
        sample_list.add_field("targets", sample_list.answers[:, 0, 1:])
    return data, sample_list, timesteps