The Wayback Machine - https://web.archive.org/web/20240906160053/https://www.geeksforgeeks.org/tensorflow-js-tf-layers-dot-function/
Open In App

Tensorflow.js tf.layers.dot() Function

Last Updated : 10 Feb, 2022
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

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. Tensorflow.js tf.layers.dot() function is used to apply the dot product between the two tensors provided.

Syntax: 

tf.layers.dot(args);

Parameters: This function accepts the following parameters: 

  •  args: It is the object with the following field:
    • axes: It defined the axes to dot product to which way it is going.
    • normalize: It is boolean data used to produce the answer of the dot product in cosine value form.
    • inputShape: It defines the shape of the input layer of the model. It is used in the creation of the input layer.
    • dtype: it is the data-type of the layer. It is used for the first layer of the model.
    • name: String is the name for the input layer.
    • weight: It is the tensor whose values are the initial value for the layer.
    • trainable: It defined that is layer is trainable or not. It is a boolean data type.
    • batchInputShape: It defined the batch’s shape for the samples in the input layer. It is used in making of the input layer.
    • batchSize: It is used as supplementary of batchInputShape in the construction of the input layer. It is used in making of the input layer.
    • inputDType: It is the data type for the input data in the layer.

Returns: It returns the product tensor of two tensors.

Below are some examples of this function.

Example 1: In this example,  we will make simply a dot product of tensor with  -2 axis rotation of values.

Javascript




// import * as tf from "@tensorflow/tfjs"
 
// Generating tensor of [3,3] shape and size.
const geek_tens1 = tf.randomUniform([3 ,3]);
const geek_tens2 = tf.randomUniform([3 ,3]);
 
// Making tensor compatible to apply to dot product.
const geek_Input = [geek_tens1 ,geek_tens2];
 
// Calling dot product
const geek_config = {axes: -2};
const geek_DotPro = tf.layers.dot(geek_config);
const geek_DotProRes = geek_DotPro.apply(geek_Input);
 
// Printing our result
console.log(geek_DotProRes);
geek_DotProRes.print();


 
 Output: 

Tensor
    [[0.7034817],
     [0.2338114],
     [1.1493738]]
Tensor
    [[0.7034817],
     [0.2338114],
     [1.1493738]]

 Example 2: In this example,  we will make a dot product of two tensors and see the result in cosine form. 

Javascript




import * as tf from "@tensorflow/tfjs"
 
// Collect both outputs and print separately.
// Generating tensor of [3,3] shape and size.
const geek_tens1 = tf.randomUniform([2 ,4]);
const geek_tens2 = tf.randomUniform([2 ,4]);
 
// Making tensor compatible to apply to dot product.
const geek_Input = [geek_tens1 ,geek_tens2];
 
// Calling dot product
const geek_config = {axis: 1, normalize: true,
        dtype: 'int32', name: 'DotProduct' };
const geek_DotPro = tf.layers.dot(geek_config);
const geek_DotProRes = geek_DotPro.apply(geek_Input);
 
// Printing our result
console.log(geek_DotProRes);


 
Output: 

Tensor
    0.6817111968994141

 Reference: https://js.tensorflow.org/api/latest/#layers.dot



Similar Reads

Double-Dot “..” vs. Triple-Dot “…” in Git Commit Ranges
Git, the distributed version control system, is a powerful tool for tracking changes in source code during software development. Among its many features, the syntax for specifying commit ranges is important for managing and understanding changes in your repository. Two such syntaxes are the double-dot `..` and the triple-dot `....` While they might
4 min read
Tensorflow.js tf.dot() 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. The tf.dot() function is used to compute the dot product of two given matrices or vectors, t1 and t2. Syntax: tf.dot(t1, t2); Parameters: This function accepts a parameter which is ill
1 min read
Tensorflow.js tf.layers.embedding() Function
Tensorflow.js is an open-source library that is developed by Google for running machine learning models as well as deep learning neural networks in the browser or node environment. The tf.layers.embedding() function is used to map positive integers into dense vectors of fixed size. Syntax: tf.layers.embedding(args)Parameters: This function accepts
3 min read
Tensorflow.js tf.layers.elu() 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 Node.js. The tf.layers.elu() function is abbreviated as Exponential L
2 min read
Tensorflow.js tf.layers.globalMaxPooling1d() Function
Tensorflow.js is a Google-developed open-source toolkit for executing machine learning models and deep learning neural networks in the browser or on the node platform. It also enables developers to create machine learning models in JavaScript and utilize them directly in the browser or with Node.js. The tf.layers.globalMaxPooling1d() function is us
2 min read
Tensorflow.js tf.layers.timeDistributed() 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. The tf.layers.timeDistributed() function is used to apply the wrap of a layer to every temporal slice of a specified input. The given input must be at least 3D, and the index 1 for the
3 min read
Tensorflow.js tf.layers.average() 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 Node.js. The tf.layers.average() function is used to calculate averag
2 min read
Tensorflow.js tf.layers.gruCell() Function
Tensorflow.js is an open-source library that is being developed by Google for running machine learning models as well as deep learning neural networks in the browser or node environment. The .layers.gruCell( ) function is used to create a cell class for GRU. Syntax: tf.layers.gruCell (args) Parameters: recurrentActivation: It is a tensor input that
4 min read
Tensorflow.js tf.layers.thresholdedReLU() Function
Tensorflow.js is a Google-developed open-source toolkit for executing machine learning models and deep learning neural networks in the browser or on the node platform. It also enables developers to create machine learning models in JavaScript and utilize them directly in the browser or with Node.js. The tf.layers.thresholdedReLU() function is used
2 min read
Tensorflow.js tf.layers.minimum() 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. The tf.layers.minimum() function is used to create a layer that is used to compute the element-wise minimum of an Array of inputs. It takes as input a list of tensors, having the same
2 min read
Tensorflow.js tf.layers.dense() Function
The tf.layers.dense() is an inbuilt function of Tensorflow.js library. This function is used to create fully connected layers, in which every output depends on every input. Syntax: tf.layers.dense(args)Parameters: This function takes the args object as a parameter which can have the following properties: units: It is a positive number that defines
3 min read
Tensorflow.js tf.layers.dropout() 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. The tf.layers.dropout() function is an inbuilt function of Tensorflow.js library. This function is used to prevent overfitting in a model by randomly setting a fraction rate of input u
2 min read
Tensorflow.js tf.layers.flatten() 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. The tf.layers.flatten() function is used to flatten the input, without affecting the batch size. A Flatten layer flattens each batch in the inputs to 1-dimension. Syntax: tf.layers.fla
2 min read
Tensorflow.js tf.layers.multiply() 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. The tf.layers.multiply() function is used to perform element-wise multiplication of an array of inputs. Syntax: tf.layers.multiply() Parameters: inputShape: If this parameter is define
2 min read
Tensorflow.js tf.layers.repeatVector() 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. The tf.layers.repeatVector() function is used to repeat the input n number of times in a new specified dimension. It is an inbuilt function of TensorFlow's.js library. Syntax: tf.layer
1 min read
Tensorflow.js tf.layers.maximum() 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 Node.js. The tf.layers.maximum() function is used to calculate maximu
2 min read
Tensorflow.js tf.layers.add() 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 Node.js. The tf.layers.add() function is used to calculate addition o
2 min read
Tensorflow.js tf.layers.simpleRNNCell() Function
Tensorflow.js is an open-source library that is being developed by Google for running machine learning models as well as deep learning neural networks in the browser or node environment. The .layers.simpleRNNCell( ) function is used to find a cell class for simpleRNN. Syntax: tf.layers.simpleRNNCell (args) Parameters: units: It is a tensor input th
4 min read
Tensorflow.js tf.layers.gru() 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. Tensorflow.js tf.layers.gru() function is used to create a RNN layer which consists of only one GRUCell and the apply method of this layer operates on a sequence of input tensors. The
2 min read
Tensorflow.js tf.layers.alphaDropout() 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 Node.js. The tf.layers.AlphaDropout() function is used to apply Alpha
2 min read
Tensorflow.js tf.layers.gaussianDropout() 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 Node.js. The tf.layers.gaussianDropout() function is used to apply mu
2 min read
Tensorflow.js tf.layers.masking() 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 Node.js. The tf.layers.masking() function is used to mask a sequence
2 min read
Tensorflow.js tf.layers.gaussianNoise() 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 Node.js. The tf.layers.gaussianNoise() function is used to apply addi
2 min read
Tensorflow.js tf.layers.concatenate() 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. The tf.layers.concatenate() function is used to concatenate an array of inputs. Syntax: tf.layers.concatenate() Parameters: args(Object): specifies the given object. It is an optional
2 min read
Tensorflow.js tf.layers.lstmCell() Function
Tensorflow.js is an open-source library that is being developed by Google for running machine learning models as well as deep learning neural networks in the browser or node environment. The layers.lstmCell() function is used for Cell class for LSTM. It is separate from the RNN subclass. Syntax: tf.layers.lstmCell(args) Parameters: The function con
3 min read
Tensorflow.js tf.layers.reshape() Function
Tensorflow.js is an open-source library that is being developed by Google for running machine learning models as well as deep learning neural networks in the browser or node environment. The tf.layers.reshape() function is used to Reshape an input to a certain shape. Syntax: tf.layers.reshape(args) Parameters: This function takes the args object as
2 min read
Tensorflow.js tf.layers.permute() Function
The layers in models are the basic blocks in constructions of models, for every layer perform some computation on input and output to the next layer. The tf.layers.permute() function is inherited from layers class and is used to permute the dimensions of the input in a given pattern, Also used to connect RNNs and convnet together. In this post, we
2 min read
Tensorflow.js tf.layers.zeroPadding2d() 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. The tf.layers.zeroPadding2d( ) function is used for adding rows and columns for zeros at the top, bottom, left, and right side of and image tensor. Syntax: tf.layers.zeroPadding2d(args
3 min read
Tensorflow.js tf.layers.inputLayer() Function
Tensorflow.js is an open-source library that is developed by Google for running machine learning models as well as deep learning neural networks in the browser or node environment. The tf.layers.inputLayer() function is an inlet point towards a tf.LayersModel. It is produced spontaneously in favor of tf.Sequentialmodels by defining the inputshape o
2 min read
Tensorflow.js tf.layers.activation() Function
Introduction: 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. Tensorflow.js tf.layers.activation() function is used to applied to function to all the element of our input layer . we can also apply function to the input data with den
3 min read