MaskingLayer<T>
Layers · AiDotNet.NeuralNetworks.Layers
Represents a layer that masks specified values in the input tensor, typically used to ignore padding in sequential data.
Inheritance: LayerBase<T> → MaskingLayer<T>
Implements: IShapeContract
For Beginners
This layer helps the network ignore certain parts of your data.
Think of it like a highlighter that marks which parts of your data are important:
- Any value matching the “mask value” (usually 0) gets ignored
- All other values pass through unchanged
- This is especially useful for sequences of different lengths
For example, if you have sentences of different lengths:
- Short sentences might be padded with zeros to match longer ones
- The masking layer tells the network to ignore those zeros
- This helps the network focus only on the real data
Without masking, the network would try to learn patterns from the padding values, which would confuse the learning process.
How It Works
The MaskingLayer is used to skip certain time steps in sequential data by masking out specific values. During the forward pass, time steps with values equal to the mask value are multiplied by zero, effectively removing them from consideration by subsequent layers. This is particularly useful for handling variable-length sequences where padding is used to make all sequences the same length.
Constructors
| Constructor | Summary |
|---|---|
MaskingLayer(double maskValue) |
Initializes a new instance of the MaskingLayer class. |
Properties
| Property | Summary |
|---|---|
bool SupportsGpuTraining { get; } |
|
bool SupportsTraining { get; } |
Gets a value indicating whether this layer supports training through backpropagation. |
Methods
| Method | Summary |
|---|---|
IReadOnlyList<OutputAxisContract> OutputAxesFor(int inputRank) |
Derived from this type’s [TensorLayout] declarations. |
void ResetState() |
Resets the internal state of the layer. |