Implementation:Tensorflow Tfjs Exports Constraints
| Knowledge Sources | |
|---|---|
| Domains | Deep_Learning, Layers_API, Constraints |
| Last Updated | 2026-02-10 06:00 GMT |
Overview
This module provides the public API factory functions for creating weight constraint instances in TensorFlow.js Layers. These functions are thin wrappers around the constraint classes defined in constraints.ts, exposed under the tf.constraints namespace. Each function takes a configuration object and returns the corresponding Constraint instance.
Code Reference
Source Location
tfjs-layers/src/exports_constraints.ts (GitHub)
Imports
import {Constraint, MaxNorm, MaxNormArgs, MinMaxNorm, MinMaxNormArgs,
NonNeg, UnitNorm, UnitNormArgs} from './constraints';
Factory Functions
maxNorm
Creates a MaxNorm constraint that limits the L2 norm of weight vectors.
export function maxNorm(args: MaxNormArgs): Constraint
unitNorm
Creates a UnitNorm constraint that normalizes weights to unit L2 norm.
export function unitNorm(args: UnitNormArgs): Constraint
nonNeg
Creates a NonNeg constraint that clips weights to non-negative values.
export function nonNeg(): Constraint
minMaxNorm
Creates a MinMaxNorm constraint that bounds the L2 norm between min and max values.
export function minMaxNorm(config: MinMaxNormArgs): Constraint
I/O Contract
| Function | Input | Output |
|---|---|---|
maxNorm |
MaxNormArgs ({maxValue?, axis?}) |
Constraint
|
unitNorm |
UnitNormArgs ({axis?}) |
Constraint
|
nonNeg |
(none) | Constraint
|
minMaxNorm |
MinMaxNormArgs ({minValue?, maxValue?, rate?, axis?}) |
Constraint
|
Usage Example
import * as tf from '@tensorflow/tfjs';
const model = tf.sequential();
model.add(tf.layers.dense({
units: 32,
kernelConstraint: tf.constraints.maxNorm({maxValue: 2, axis: 0}),
biasConstraint: tf.constraints.nonNeg(),
inputShape: [64]
}));
Related Pages
- Tensorflow_Tfjs_Constraints - Underlying constraint class implementations
- Tensorflow_Tfjs_Exports_Initializers - Factory functions for weight initializers
- Tensorflow_Tfjs_Exports_Regularizers - Factory functions for weight regularizers