def METHOD_NAME(self, emissions, targets, masks=None):
    batch_size, seq_len = targets.size()
    emission_scores = emissions.gather(2, targets[:, :, None])[:, :, 0]  # B x T
    transition_scores = (self.E1(targets[:, :-1]) * self.E2(targets[:, 1:])).sum(2)
    scores = emission_scores
    scores[:, 1:] += transition_scores
    if masks is not None:
        scores = scores * masks.type_as(scores)
    return scores.sum(-1)