build method
Initializes the layer's parameters based on the shape of the first input.
Subclasses should override this method to create their weights and biases.
This method is called automatically by call and should not be called directly.
Implementation
@override
void build(Tensor<dynamic> input) {
Matrix pe = [];
for (int i = 0; i < maxLength; i++) {
Vector row = [];
for (int j = 0; j < dModel; j++) {
row.add(0.0);
}
pe.add(row);
}
for (int pos = 0; pos < maxLength; pos++) {
for (int i = 0; i < dModel; i++) {
double angle = pos / pow(10000, (2 * i) / dModel);
if (i % 2 == 0) {
pe[pos][i] = sin(angle);
} else {
pe[pos][i] = cos(angle);
}
}
}
encodingMatrix = Tensor<Matrix>(pe);
super.build(input);
}