Tensorflow.js tf.layers.gru() Function
Last Updated :
17 Jun, 2021
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 shape of input tensor must be atleast 2D and the first dimension must be time steps. gru is Gated Recurrent Unit.
Syntax:
tf.layers.gru(args)
Parameters:
- args: It specifies the given config object.
- recurrentActivation: It specifies the activation function which will be used for the recurrent step. The default value of this parameter is hard sigmoid.
- implementation: It specifies the implementation mode. It can be either 1 or 2. For superior performance implementation is recommended.
Return value: It returns a tf.layers.Layer
Example 1:
Javascript
const tf = require( "@tensorflow/tfjs" );
const RNN = tf.layers.gru({units: 8, returnSequences: true });
const input = tf.input({shape: [5, 10]});
const output = RNN.apply(input);
console.log(JSON.stringify(output.shape));
|
Output:
[null, 5, 8]
Example 2:
Javascript
const tf = require( "@tensorflow/tfjs" );
const rnn = tf.layers.gru({units: 4, returnSequences: true });
const x = tf.tensor3d([
[
[1, 2],
[3, 4],
],
[
[5, 6],
[7, 8],
],
]);
const output = rnn.apply(x);
output.print()
|
Output:
Reference: https://js.tensorflow.org/api/1.0.0/#layers.gru
Share your thoughts in the comments
Please Login to comment...