Thursday, September 18, 2025
HomeLanguagesJavascriptTensorflow.js tf.initializers.randomNormal() Function

Tensorflow.js tf.initializers.randomNormal() 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.randomNormal() function produces random values that are initialized to a normal distribution.

tf.initializers.randomNormal(arguments)

Parameters:

  • arguments: It is an object that contains 3 key-values listed below:
    1. mean: It is the mean of the random values to be generated.
    2. stddev: It is the standard deviation of the random values to be generated.
    3. seed: It is the random number generator seed.

Returns value: It returns tf.initializers.Initializer

Example 1:

Javascript




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
 
// Initializing the .initializers.randomNormal() function
let geek = tf.initializers.randomNormal(3)
 
// Printing gain value
console.log(geek);
 
// Printing individual gain value.
console.log('\nIndividual values:\n');
console.log(geek.DEFAULT_MEAN);
console.log(geek.DEFAULT_STDDEV);
console.log(geek.mean);
console.log(geek.stddev);


Output:

{
  "DEFAULT_MEAN": 0,
  "DEFAULT_STDDEV": 0.05,
  "mean": 0,
  "stddev": 0.05
}

Individual values:

0
0.05
0
0.05

Example 2: 

Javascript




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


Output:

Tensor
    [[0.1165049, 0.2952721, 0.1367277, 0.1689866, 
      0.0897676, 0.0964029, 0.0963382],
     [0.1165049, 0.2952721, 0.1367277, 0.1689866, 
      0.0897676, 0.0964029, 0.0963382]]

Reference: https://js.tensorflow.org/api/3.6.0/#initializers.randomNormal

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
32299 POSTS0 COMMENTS
Milvus
84 POSTS0 COMMENTS
Nango Kala
6664 POSTS0 COMMENTS
Nicole Veronica
11837 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11895 POSTS0 COMMENTS
Shaida Kate Naidoo
6779 POSTS0 COMMENTS
Ted Musemwa
7054 POSTS0 COMMENTS
Thapelo Manthata
6738 POSTS0 COMMENTS
Umr Jansen
6744 POSTS0 COMMENTS