| nn_mc_loss | R Documentation |
Module wrapper for nnf_mc_loss() with configurable parameters.
Stores the ancestor matrix R and evaluation mask for reuse across batches.
nn_mc_loss(
R,
to_eval = NULL,
criterion = nnf_binary_cross_entropy_with_logits,
reduction = "mean"
)
R |
Ancestor matrix tensor of shape |
to_eval |
Optional logical tensor of shape |
criterion |
Loss function module or functional to apply after constraint
propagation. Default: |
reduction |
(string, optional): Reduction method: |
Input output: (N, C) where N = batch size, C = number of classes
Input target: (N, C), same shape as output, binary values
Output: scalar by default. If reduction = "none", then (N, C')
where C' is the number of evaluated classes
nnf_mc_loss(), build_ancestor_matrix_from_outcomes(), get_constr_output()
## Not run:
# Build ancestor matrix from hierarchy
R <- build_ancestor_matrix_from_outcomes(my_tree, processed$outcomes, device = "cuda")
# Create loss module
loss_fn <- nn_mc_loss(R = R, reduction = "mean")
# Forward pass
output <- model(x) # (batch, n_classes)
loss <- loss_fn(output, labels)
loss$backward()
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.