GRUCellMML

class keras_mml.layers.recurrent.GRUCellMML[source]

Cell class for the GRUMML layer.

This class processes one step within the whole time sequence input, whereas GRUMML processes the whole sequence.

units

Dimensionality of the output space.

fully_mml

Whether to use matmul-free operations for all the layers.

num_heads

Number of heads to use when performing the recurrent step.

activation

Activation function to use.

recurrent_activation

Activation function to use for the recurrent step.

use_bias

Whether to use a bias vector for the layer.

weights_initializer

Initializer for the gates’ matrices. Used for the linear transformation of the inputs.

bias_initializer

Initializer for the bias vector.

weights_regularizer

Regularizer function applied to the gates’ matrices.

bias_regularizer

Regularizer function applied to the bias vector.

weights_constraint

Constraint function applied to the gates’ matrices.

bias_constraint

Constraint function applied to the bias vector.

state_size

Size of the recurrent state.

output_size

Size of the output vector.

__init__(units, fully_mml=False, num_heads=1, activation='silu', recurrent_activation='sigmoid', use_bias=True, weights_initializer='glorot_uniform', bias_initializer='zeros', weights_regularizer=None, bias_regularizer=None, weights_constraint=None, bias_constraint=None, **kwargs)[source]

Initializes a new instance of the layer.

Parameters:
  • units (int) – Dimensionality of the output space.

  • fully_mml (bool, default: False) – Whether to use matmul-free operations for all the layers.

  • num_heads (int, default: 1) – Number of heads to use when performing the recurrent step.

  • activation (str, default: 'silu') – Activation function to use.

  • recurrent_activation (str, default: 'sigmoid') – Activation function to use for the recurrent step.

  • use_bias (bool, default: True) – Whether to use a bias vector for the layer.

  • weights_initializer (str, default: 'glorot_uniform') – Initializer for the gates’ matrices. Used for the linear transformation of the inputs.

  • bias_initializer (str, default: 'zeros') – Initializer for the bias vector.

  • weights_regularizer (Optional[str], default: None) – Regularizer function applied to the gates’ matrices.

  • bias_regularizer (Optional[str], default: None) – Regularizer function applied to the bias vector.

  • weights_constraint (Optional[str], default: None) – Constraint function applied to the gates’ matrices.

  • bias_constraint (Optional[str], default: None) – Constraint function applied to the bias vector.

  • **kwargs – Keyword arguments for keras.Layer.

Raises:
  • ValueError – If the units provided is not a positive integer.

  • ValueError – If the number of heads to use is not a positive integer.

  • ValueError – If the number of heads does not divide the units provided.

build(input_shape)[source]

Create layer weights.

Parameters:

input_shape (Tuple[int, int]) – Shape of the input.

call(inputs, states, training=False)[source]

Calling method of the cell.

Parameters:
  • inputs (Float[ndarray, 'batch_size features']) – Inputs into the layer.

  • states (Float[ndarray, '*state_dims']) – State(s) from the previous timestep.

  • training (default: False) – Whether the layer should behave in training mode or in inference mode.

Returns:

Float[ndarray, 'batch_size units'] – Transformed inputs.

get_config()[source]

Gets the configuration for the layer.

Returns:

Layer configuration.

get_initial_state(batch_size=None)[source]

Gets the initial states.

Parameters:

batch_size (Optional[int], default: None) – Batch size for the cell.

Returns:

List[ndarray] – Initial states.