Friday, February 6, 2026
HomeLanguagesJavascriptTensorflow.js tf.initializers.leCunNormal() Function

Tensorflow.js tf.initializers.leCunNormal() Function

Tensorflow.js is an open-source library developed by Google for running machine learning models and deep learning neural networks in the browser or node environment. It also helps the developers to develop ML models in JavaScript language and can use ML directly in the browser or in Node.js.

The tf.initializers.leCunNormal() function extracts samples from a truncated normal distribution which is centered at zero with stddev = sqrt(1 / fanIn). Note that fanIn is the number of inputs in the tensor weight.

Syntax:

tf.initializers.leCunNormal(arguments).

Parameters:

  • arguments: It is an object that contains seed (a number) which is the random number generator seed/number.

Returns value: It returns tf.initializers.Initializer.

Example 1:

Javascript




// Importing the tensorflow.Js library
import * as tf from "@tensorflow/tfjs"
 
// Initializing the .initializers.leCunNormal() function
const geek = tf.initializers.leCunNormal(3)
 
// Printing gain
 
console.log(geek);
console.log('\nIndividual values:\n');
console.log(geek.scale);
console.log(geek.mode);
console.log(geek.distribution);


 
 Output:

{
    "scale": 1,
    "mode": "fanIn",
    "distribution": "normal"
}

Individual values:

1
fanIn
normal

Example 2:

Javascript




// Importing the tensorflow.Js library
import * as tf from "@tensorflow/tfjs"
 
// Defining the input value
let inputValue = tf.input({ shape: [4] });
 
// Initializing tf.initializers.leCunNormal()
// function
let funcValue = tf.initializers.leCunNormal(7)
 
// Creating dense layer 1
let dense_layer_1 = tf.layers.dense({
    units: 5,
    activation: 'relu',
    kernelInitialize: funcValue
});
 
// Creating dense layer 2
let dense_layer_2 = tf.layers.dense({
    units: 7,
    activation: 'softmax'
});
 
// Output
let outputValue = dense_layer_2.apply(
    dense_layer_1.apply(inputValue)
);
 
// Creation the model.
let model = tf.model({
    inputs: inputValue,
    outputs: outputValue
});
 
// Predicting the output
let finalOutput = model.predict(tf.ones([2, 4]));
finalOutput.print();


Output:

Tensor
    [[0.0666204, 0.1171203, 0.2322821, 0.1056982, 
            0.2149536, 0.1846998, 0.0786256],
     [0.0666204, 0.1171203, 0.2322821, 0.1056982, 
            0.2149536, 0.1846998, 0.0786256]]

Reference:  https://js.tensorflow.org/api/latest/#initializers.leCunNormal

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32489 POSTS0 COMMENTS
Milvus
126 POSTS0 COMMENTS
Nango Kala
6862 POSTS0 COMMENTS
Nicole Veronica
11983 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12073 POSTS0 COMMENTS
Shaida Kate Naidoo
6995 POSTS0 COMMENTS
Ted Musemwa
7236 POSTS0 COMMENTS
Thapelo Manthata
6946 POSTS0 COMMENTS
Umr Jansen
6930 POSTS0 COMMENTS