Losses

Which loss fits which problem type, along with output and label shapes, is covered in the Loss Overview. Every module here takes raw logits and works in ordinary PyTorch loops.

BinaryClassificationLoss

class relational_transformers.BinaryClassificationLoss(*args, **kwargs)

Binary cross entropy over one logit per relational context.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

Parameters:
  • args (Any)

  • kwargs (Any)

forward(logits, labels)

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Parameters:
Return type:

Tensor

MulticlassClassificationLoss

class relational_transformers.MulticlassClassificationLoss(*args, **kwargs)

Cross entropy over mutually exclusive class logits.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

Parameters:
  • args (Any)

  • kwargs (Any)

forward(logits, labels)

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Parameters:
Return type:

Tensor

MultilabelClassificationLoss

class relational_transformers.MultilabelClassificationLoss(*args, **kwargs)

Binary cross entropy over independent label logits.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

Parameters:
  • args (Any)

  • kwargs (Any)

forward(logits, labels)

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Parameters:
Return type:

Tensor

RegressionLoss

class relational_transformers.RegressionLoss(delta=1.0)

Huber loss for regression and forecasting targets.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

Parameters:

delta (float)

forward(predictions, labels)

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Parameters:
Return type:

Tensor

loss_for

relational_transformers.losses.loss_for(problem_type)

Return the standard loss module for a supported problem type.

Parameters:

problem_type (str)

Return type:

Module