Layer constructor

Layer(
  1. int nin,
  2. int nout, {
  3. required bool useGelu,
})

Implementation

Layer(int nin, int nout, {required this.useGelu}) {
  // Xavier/Glorot Initialization
  double scale = sqrt(2.0 / (nin + nout));
  w = Tensor.fromList(
    [nin, nout],
    List.generate(nin * nout, (_) => (Random().nextDouble() * 2 - 1) * scale),
  );
  // Initialize bias slightly positive to prevent "dead" neurons
  b = Tensor.fill([1, nout], 0.01);
}