    def get_regularization_penalty(self) -> Optional[torch.Tensor]:
        """
        Computes the regularization penalty for the model.
        Returns None if the model was not configured to use regularization.
        """
        if self._regularizer is None:
            regularization_penalty = None
        else:
            try:
                regularization_penalty = self._regularizer(self)
                if isinstance(regularization_penalty, float):
                    assert regularization_penalty == 0.0
                    regularization_penalty = torch.tensor(regularization_penalty)
            except AssertionError:
                raise RuntimeError("The regularizer cannot be a non-zero float.")
        return regularization_penalty
Computes the regularization penalty for the model.
Returns None if the model was not configured to use regularization.
allennlp/models/model.py