MultiplyLayer<T>
Layers · AiDotNet.NeuralNetworks.Layers
Represents a layer that performs element-wise multiplication of multiple input tensors.
Inheritance: LayerBase<T> → MultiplyLayer<T>
Implements: IShapeContract
For Beginners
This layer multiplies tensors together, element by element.
Think of it like multiplying numbers together in corresponding positions:
- If you have two vectors [1, 2, 3] and [4, 5, 6]
- The result would be [1×4, 2×5, 3×6] = [4, 10, 18]
This is useful for:
- Controlling information flow (like gates in LSTM or GRU cells)
- Applying masks (to selectively focus on certain values)
- Combining features in a multiplicative way
For example, in an attention mechanism, you might multiply feature values by attention weights to focus on important features and diminish the influence of less relevant ones.
How It Works
The MultiplyLayer performs element-wise multiplication (Hadamard product) of two or more input tensors of identical shape. This operation can be useful for implementing gating mechanisms, attention masks, or feature-wise interactions in neural networks. The layer requires that all input tensors have the same shape, and it produces an output tensor of that same shape.
Constructors
| Constructor | Summary |
|---|---|
MultiplyLayer(int[][] inputShapes, IActivationFunction<T> activationFunction) |
Initializes a new instance of the MultiplyLayer class with the specified input shapes and a vector activation function. |
MultiplyLayer(int[][] inputShapes, IVectorActivationFunction<T> vectorActivationFunction) |
Initializes a new instance of the MultiplyLayer class with the specified input shapes and a vector activation function. |
Properties
| Property | Summary |
|---|---|
IReadOnlyList<LayerPort> InputPorts { get; } |
|
bool SupportsGpuTraining { get; } |
|
bool SupportsTraining { get; } |
Gets a value indicating whether this layer supports training. |
Methods
| Method | Summary |
|---|---|
IReadOnlyList<OutputAxisContract> OutputAxesFor(int inputRank) |
Derived from this type’s [TensorLayout] declarations. |
Tensor<T>[] BackwardGpu(Tensor<T> outputGradient) |
Computes the gradients of the loss with respect to the inputs on the GPU. |
void ResetState() |
Resets the internal state of the multiply layer. |