MaskedRowLoss<T>
Models & Types · AiDotNet.LossFunctions
Restricts another loss to a subset of the rows of a [rows, features] prediction, so the
excluded rows contribute neither loss nor gradient.
Inheritance: LossFunctionBase<T> → MaskedRowLoss<T>
For Beginners
In semi-supervised learning you have labels for only some of your data points, but you still have to run the model over all of them. This wrapper tells the loss “score only these rows” so the unlabeled ones cannot accidentally teach the model anything.
How It Works
This exists for TRANSDUCTIVE, semi-supervised training – the setting graph networks train in, where the forward pass must run over every node because message passing needs the whole graph, but only the training nodes are allowed to supply a learning signal.
ZEROING THE LABEL ROW OF A HELD-OUT NODE DOES NOT HOLD IT OUT, and that is the mistake this type
is here to prevent. For softmax cross-entropy the gradient of an all-zero target row is
softmax(logits) - 0 = softmax(logits), which is not zero: it pushes every logit of every
held-out node downward on every step. That is strictly worse than no signal, because it is a
consistent wrong signal rather than an absent one. Selecting the rows is what actually excludes
them – an unselected row is not part of the graph the tape differentiates, so its gradient is
exactly zero rather than approximately so.
Constructors
| Constructor | Summary |
|---|---|
MaskedRowLoss(LossFunctionBase<T> inner, bool[] mask) |
Wraps inner so it scores only the rows where mask is true. |
Properties
| Property | Summary |
|---|---|
int SelectedRowCount { get; } |
Gets the number of rows that contribute to the loss. |
Methods
| Method | Summary |
|---|---|
T CalculateLoss(Vector<T> predicted, Vector<T> actual) |
|
Tensor<T> ComputeTapeLoss(Tensor<T> predicted, Tensor<T> target) |