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 Exports Regularizers

From Leeroopedia


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

Overview

This module provides the public API factory functions for creating weight regularizer instances in TensorFlow.js Layers. Regularizers add penalty terms to the loss function during training to prevent overfitting. The three factory functions correspond to L1 regularization, L2 regularization, and combined L1+L2 regularization, exposed under the tf.regularizers namespace.

Code Reference

Source Location

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

Imports

import * as regularizers from './regularizers';
import {L1Args, L1L2, L1L2Args, L2Args, Regularizer} from './regularizers';

Factory Functions

l1l2

Creates a regularizer applying both L1 and L2 penalties: loss += sum(l1 * abs(x)) + sum(l2 * x^2).

export function l1l2(config?: L1L2Args): Regularizer

l1

Creates a regularizer applying L1 penalty only: loss += sum(l1 * abs(x)).

export function l1(config?: L1Args): Regularizer

l2

Creates a regularizer applying L2 penalty only: loss += sum(l2 * x^2).

export function l2(config?: L2Args): Regularizer

I/O Contract

Function Input Output
l1l2 L1L2Args ({l1?, l2?}) Regularizer
l1 L1Args ({l1}) Regularizer
l2 L2Args ({l2}) Regularizer

Usage Example

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

const model = tf.sequential();
model.add(tf.layers.dense({
  units: 64,
  kernelRegularizer: tf.regularizers.l1l2({l1: 0.01, l2: 0.01}),
  inputShape: [128]
}));

Related Pages

Page Connections

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