Tensorflow.js tf.inTopKAsync() Function Last Updated : 25 May, 2021 Comments Improve Suggest changes Like Article Like Report 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 .inTopKAsync() function is used to check if the stated targets are in the given top K predictions. Syntax : tf.inTopKAsync(predictions, targets, k?) Parameters: predictions: It is the stated 2-D or upper tensor input whose last size is not lesser than k and it can be of type tf.Tensor, TypedArray, or Array.targets: It is the stated 1-D or upper tensor input and it can be of type tf.Tensor, TypedArray, or Array.k: It is the alternative number of top elements which are to be considered for calculating precision. The by default value is 1 and it is of type number. Return Value: It returns Promise tf.Tensor object. Example 1: JavaScript // Importing the tensorflow.js library import * as tf from "@tensorflow/tfjs" // Defining predictions and targets const pred = tf.tensor2d([ [11, 22, 33, 55], [33, 66, 22, -11] ]); const targ = tf.tensor1d([1, 1]); // Calling tf.inTopKAsync() method const res = await tf.inTopKAsync(pred, targ); // Printing output res.print(); Output: Tensor [false, true] Example 2: JavaScript // Importing the tensorflow.js library import * as tf from "@tensorflow/tfjs" // Calling tf.inTopKAsync() method with // all its parameters const res = await tf.inTopKAsync( tf.tensor2d([[1.1, 2.2], [3.3, 6.6]]), tf.tensor1d([0, 1]), 2); // Printing output res.print(); Output: Tensor [true, true] Reference: https://js.tensorflow.org/api/latest/#inTopKAsync Comment More infoAdvertise with us Next Article Tensorflow.js tf.inTopKAsync() Function N nidhi1352singh Follow Improve Article Tags : JavaScript Web Technologies Fabric.js Similar Reads Tensorflow.js tf.io.http() 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 .io.http() function is used to generate an IOHandler subset which transmits model artifacts to the HTTP server. Mor 2 min read Tensorflow.js tf.gatherND() 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. 2 min read Tensorflow.js tf.gather() 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 .gather() function is used to collect the fragments from the stated tensor x's axis as per the stated indices. Synt 2 min read Tensorflow.js tf.initializers.ones() Function Tensorflow.js is a very well-known machine learning library that used to develop a machine learning model using JavaScript. The main purpose to use this library is to run and deploy a machine learning model directly from the browser or in Node.js. Tensorflow.js is an open-source hardware-accelerated 2 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 o 2 min read Like