• Cell class for GRU.

    GRUCell is distinct from the RNN subclass GRU in that its apply method takes the input data of only a single time step and returns the cell's output at the time step, while GRU takes the input data over a number of time steps. For example:

    const cell = tf.layers.gruCell({units: 2});
    const input = tf.input({shape: [10]});
    const output = cell.apply(input);

    console.log(JSON.stringify(output.shape));
    // [null, 10]: This is the cell's output at a single time step. The 1st
    // dimension is the unknown batch size.

    Instance(s) of GRUCell can be used to construct RNN layers. The most typical use of this workflow is to combine a number of cells into a stacked RNN cell (i.e., StackedRNNCell internally) and use it to create an RNN. For example:

    const cells = [
    tf.layers.gruCell({units: 4}),
    tf.layers.gruCell({units: 8}),
    ];
    const rnn = tf.layers.rnn({cell: cells, returnSequences: true});

    // Create an input with 10 time steps and a length-20 vector at each step.
    const input = tf.input({shape: [10, 20]});
    const output = rnn.apply(input);

    console.log(JSON.stringify(output.shape));
    // [null, 10, 8]: 1st dimension is unknown batch size; 2nd dimension is the
    // same as the sequence length of `input`, due to `returnSequences`: `true`;
    // 3rd dimension is the last `gruCell`'s number of units.

    To create an RNN consisting of only one GRUCell, use the tf.layers.gru.

    Parameters

    • args: GRUCellLayerArgs

    Returns GRUCell

    Doc

Generated using TypeDoc