forward method

  1. @override
Tensor<Matrix> forward(
  1. Tensor input
)
override

The core logic of the layer's transformation.

Subclasses must implement this method to define how they process input tensors and return an output tensor.

Implementation

@override
Tensor<Matrix> forward(Tensor<dynamic> input) {
  Tensor<Matrix> inputMatrix = input as Tensor<Matrix>;
  int sequenceLength = inputMatrix.value.length;

  Matrix applicableEncodings = [];
  for(int i=0; i < sequenceLength; i++){
    applicableEncodings.add(encodingMatrix.value[i]);
  }
  Tensor<Matrix> positionalTensor = Tensor<Matrix>(applicableEncodings);

  return addMatrix(inputMatrix, positionalTensor);
}