Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Tensorflow Tfjs Noise Layers

From Leeroopedia


Knowledge Sources
Domains Deep_Learning, Layers_API, Regularization
Last Updated 2026-02-10 06:00 GMT

Overview

This module implements three noise-based regularization layers for TensorFlow.js Layers: GaussianNoise, GaussianDropout, and AlphaDropout. These layers add stochastic noise to inputs during training to reduce overfitting, and pass inputs through unchanged during inference. All three layers support masking.

Code Reference

Source Location

tfjs-layers/src/layers/noise.ts (GitHub)

Key Imports

import {add, greaterEqual, mul, randomUniform, serialization, Tensor, tidy} from '@tensorflow/tfjs-core';
import * as K from '../backend/tfjs_backend';
import {Layer, LayerArgs} from '../engine/topology';

Layer Classes

GaussianNoise

Adds additive zero-centered Gaussian noise during training.

export class GaussianNoise extends Layer {
  static className = 'GaussianNoise';
  readonly stddev: number;
  constructor(args: GaussianNoiseArgs);  // { stddev: number }
  override call(inputs: Tensor | Tensor[], kwargs: Kwargs): Tensor | Tensor[];
}

During training: output = input + N(0, stddev). During inference: identity pass-through.

GaussianDropout

Applies multiplicative Gaussian noise during training.

export class GaussianDropout extends Layer {
  static className = 'GaussianDropout';
  readonly rate: number;
  constructor(args: GaussianDropoutArgs);  // { rate: number }
  override call(inputs: Tensor | Tensor[], kwargs: Kwargs): Tensor | Tensor[];
}

During training (when 0 < rate < 1): output = input * N(1, sqrt(rate / (1 - rate))). During inference: identity pass-through.

AlphaDropout

Applies alpha dropout that preserves the mean and variance of inputs, designed for use with SELU activations (self-normalizing networks).

export class AlphaDropout extends Layer {
  static className = 'AlphaDropout';
  readonly rate: number;
  readonly noiseShape: Shape;
  constructor(args: AlphaDropoutArgs);  // { rate: number, noiseShape?: Shape }
  override call(inputs: Tensor | Tensor[], kwargs: Kwargs): Tensor | Tensor[];
}

Uses the SELU constants (alpha = 1.6732..., scale = 1.0507...) to maintain self-normalizing properties after dropout.

I/O Contract

Layer Input Output (training) Output (inference)
GaussianNoise Tensor of any shape Tensor + Gaussian noise Same as input
GaussianDropout Tensor of any shape Tensor * multiplicative noise Same as input
AlphaDropout Tensor of any shape Alpha-dropout transformed tensor Same as input

All layers preserve the input shape (output shape equals input shape).

Usage Example

import * as tf from '@tensorflow/tfjs';

const model = tf.sequential();
model.add(tf.layers.dense({units: 64, activation: 'relu', inputShape: [128]}));
model.add(tf.layers.gaussianNoise({stddev: 0.1}));

// For self-normalizing networks with SELU
const seluModel = tf.sequential();
seluModel.add(tf.layers.dense({units: 64, activation: 'selu', inputShape: [128]}));
seluModel.add(tf.layers.alphaDropout({rate: 0.1}));

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment