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 libraryimport * as tf from "@tensorflow/tfjs"// Initializing the .initializers.leCunNormal() functionconst geek = tf.initializers.leCunNormal(3)// Printing gainconsole.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 libraryimport * as tf from "@tensorflow/tfjs"// Defining the input valuelet inputValue = tf.input({ shape: [4] });// Initializing tf.initializers.leCunNormal()// functionlet funcValue = tf.initializers.leCunNormal(7)// Creating dense layer 1let dense_layer_1 = tf.layers.dense({ units: 5, activation: 'relu', kernelInitialize: funcValue});// Creating dense layer 2let dense_layer_2 = tf.layers.dense({ units: 7, activation: 'softmax'});// Outputlet outputValue = dense_layer_2.apply( dense_layer_1.apply(inputValue));// Creation the model.let model = tf.model({ inputs: inputValue, outputs: outputValue});// Predicting the outputlet 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, zambiatek 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!



