    def generate(self, models, sample, **kwargs):
        """Score a batch of translations."""
        net_input = sample["net_input"]

        assert len(models) == 1, "does not support model ensemble"
        model = models[0]

        bs = net_input["src_tokens"].shape[0]
        assert (
            model.joint_classification == "none" or bs % self.mt_beam == 0
        ), f"invalid batch size ({bs}) for joint classification with beam size ({self.mt_beam})"

        model.eval()
        logits = model(**net_input)

        batch_out = model.sentence_forward(logits, net_input["src_tokens"])
        if model.joint_classification == "sent":
            batch_out = model.joint_forward(
                batch_out.view(self.mt_beam, bs // self.mt_beam, -1)
            )
        scores = model.classification_forward(
            batch_out.view(bs, 1, -1)
        )  # input: B x T x C

        return scores
Score a batch of translations.
examples/discriminative_reranking_nmt/tasks/discriminative_reranking_task.py