Ejemplo n.º 1
0
 def get_normalized_name(cls) -> str:
     """Get the normalized name of the negative sampler."""
     return normalize_string(cls.__name__, suffix=NegativeSampler.__name__)
Ejemplo n.º 2
0
 def get_normalized_name(cls) -> str:
     """Get the normalized name of the regularizer class."""
     return normalize_string(cls.__name__, suffix=_REGULARIZER_SUFFIX)
Ejemplo n.º 3
0
        return loss


_LOSS_SUFFIX = 'Loss'
_LOSSES: Set[Type[Loss]] = {
    MarginRankingLoss,
    BCEWithLogitsLoss,
    SoftplusLoss,
    BCEAfterSigmoidLoss,
    CrossEntropyLoss,
    MSELoss,
    NSSALoss,
}
losses_synonyms: Mapping[str, Type[Loss]] = {
    normalize_string(synonym, suffix=_LOSS_SUFFIX): cls
    for cls in _LOSSES if cls.synonyms is not None for synonym in cls.synonyms
}
loss_resolver = Resolver(
    _LOSSES,
    base=Loss,
    default=MarginRankingLoss,
    suffix=_LOSS_SUFFIX,
    synonyms=losses_synonyms,
)


def has_mr_loss(model) -> bool:
    """Check if the model has a marging ranking loss."""
    return isinstance(model.loss, MarginRankingLoss)