exampleLayerNorm function

void exampleLayerNorm()

Implementation

void exampleLayerNorm() {
  print("\n--- Example 3: Layer Normalization Demonstration ---");

  final dim = 5;
  final ln = LayerNorm(dim);

  // Example vector that is not normalized
  final inputVector = ValueVector([
    Value(10.0),
    Value(20.0),
    Value(30.0),
    Value(40.0),
    Value(50.0),
  ]);

  print(
      "Input vector: ${inputVector.values.map((v) => v.data.toStringAsFixed(2)).toList()}");

  final normalizedVector = ln.forward(inputVector);

  print(
      "Normalized vector: ${normalizedVector.values.map((v) => v.data.toStringAsFixed(2)).toList()}");

  // To check if it's "normalized" (mean ~0, variance ~1) before gamma/beta:
  // You would need to temporarily set gamma=1, beta=0, and then calculate mean/variance of normalizedVector's data.
  // For simplicity, we just observe the output values.
  print("LayerNorm parameters count: ${ln.parameters().length}");
}