Layers

See the networks documentation for more information about how to specify networks.

Default layer: Function with default argument function, so a lambda function is a short-form specification of a simple transformation layer:

Agent.create(
    ...
    policy=dict(network=[
        (lambda x: tf.clip_by_value(x, -1.0, 1.0)),
        ...
    ]),
    ...
)

Dense layers

class tensorforce.core.layers.Dense(*, size, bias=True, activation='tanh', dropout=0.0, initialization_scale=1.0, vars_trainable=True, l2_regularization=None, name=None, input_spec=None)

Dense fully-connected layer (specification key: dense).

Parameters:
  • size (int >= 0) – Layer output size, 0 implies additionally removing the axis (required).
  • bias (bool) – Whether to add a trainable bias variable (default: true).
  • ('crelu' | 'elu' | 'leaky-relu' | 'none' | 'relu' | 'selu' | 'sigmoid' | (activation) – ‘softmax’ | ‘softplus’ | ‘softsign’ | ‘swish’ | ‘tanh’): Activation nonlinearity (default: tanh).
  • dropout (parameter, 0.0 <= float < 1.0) – Dropout rate (default: 0.0).
  • initialization_scale (float > 0.0) – Initialization scale (default: 1.0).
  • vars_trainable (bool) – Whether layer variables are trainable (default: true).
  • l2_regularization (float >= 0.0) – Scalar controlling L2 regularization (default: inherit value of parent module).
  • name (string) – Layer name (default: internally chosen).
  • input_spec (specification) – internal use.
class tensorforce.core.layers.Linear(*, size, bias=True, initialization_scale=1.0, vars_trainable=True, l2_regularization=None, name=None, input_spec=None)

Linear layer (specification key: linear).

Parameters:
  • size (int >= 0) – Layer output size, 0 implies additionally removing the axis (required).
  • bias (bool) – Whether to add a trainable bias variable (default: true).
  • initialization_scale (float > 0.0) – Initialization scale (default: 1.0).
  • vars_trainable (bool) – Whether layer variables are trainable (default: true).
  • l2_regularization (float >= 0.0) – Scalar controlling L2 regularization (default: inherit value of parent module).
  • name (string) – Layer name (default: internally chosen).
  • input_spec (specification) – internal use.

Convolutional layers

class tensorforce.core.layers.Conv1d(*, size, window=3, stride=1, padding='same', dilation=1, bias=True, activation='relu', dropout=0.0, initialization_scale=1.0, vars_trainable=True, l2_regularization=None, name=None, input_spec=None)

1-dimensional convolutional layer (specification key: conv1d).

Parameters:
  • size (int >= 0) – Layer output size, 0 implies additionally removing the axis (required).
  • window (int > 0) – Window size (default: 3).
  • stride (int > 0) – Stride size (default: 1).
  • padding ('same' | 'valid') – Padding type, see TensorFlow docs (default: ‘same’).
  • dilation (int > 0 | (int > 0, int > 0)) – Dilation value (default: 1).
  • bias (bool) – Whether to add a trainable bias variable (default: true).
  • ('crelu' | 'elu' | 'leaky-relu' | 'none' | 'relu' | 'selu' | 'sigmoid' | (activation) – ‘softmax’ | ‘softplus’ | ‘softsign’ | ‘swish’ | ‘tanh’): Activation nonlinearity (default: relu).
  • dropout (parameter, 0.0 <= float < 1.0) – Dropout rate (default: 0.0).
  • initialization_scale (float > 0.0) – Initialization scale (default: 1.0).
  • vars_trainable (bool) – Whether layer variables are trainable (default: true).
  • l2_regularization (float >= 0.0) – Scalar controlling L2 regularization (default: inherit value of parent module).
  • name (string) – Layer name (default: internally chosen).
  • input_spec (specification) – internal use.
class tensorforce.core.layers.Conv2d(*, size, window=3, stride=1, padding='same', dilation=1, bias=True, activation='relu', dropout=0.0, initialization_scale=1.0, vars_trainable=True, l2_regularization=None, name=None, input_spec=None)

2-dimensional convolutional layer (specification key: conv2d).

Parameters:
  • size (int >= 0) – Layer output size, 0 implies additionally removing the axis (required).
  • window (int > 0 | (int > 0, int > 0)) – Window size (default: 3).
  • stride (int > 0 | (int > 0, int > 0)) – Stride size (default: 1).
  • padding ('same' | 'valid') – Padding type, see TensorFlow docs (default: ‘same’).
  • dilation (int > 0 | (int > 0, int > 0)) – Dilation value (default: 1).
  • bias (bool) – Whether to add a trainable bias variable (default: true).
  • ('crelu' | 'elu' | 'leaky-relu' | 'none' | 'relu' | 'selu' | 'sigmoid' | (activation) – ‘softmax’ | ‘softplus’ | ‘softsign’ | ‘swish’ | ‘tanh’): Activation nonlinearity (default: “relu”).
  • dropout (parameter, 0.0 <= float < 1.0) – Dropout rate (default: 0.0).
  • initialization_scale (float > 0.0) – Initialization scale (default: 1.0).
  • vars_trainable (bool) – Whether layer variables are trainable (default: true).
  • l2_regularization (float >= 0.0) – Scalar controlling L2 regularization (default: inherit value of parent module).
  • name (string) – Layer name (default: internally chosen).
  • input_spec (specification) – internal use.
class tensorforce.core.layers.Conv1dTranspose(*, size, window=3, output_width=None, stride=1, padding='same', dilation=1, bias=True, activation='relu', dropout=0.0, initialization_scale=1.0, vars_trainable=True, l2_regularization=None, name=None, input_spec=None)

1-dimensional transposed convolutional layer, also known as deconvolution layer (specification key: deconv1d).

Parameters:
  • size (int >= 0) – Layer output size, 0 implies additionally removing the axis (required).
  • window (int > 0) – Window size (default: 3).
  • output_width (int > 0) – Output width (default: same as input).
  • stride (int > 0) – Stride size (default: 1).
  • padding ('same' | 'valid') – Padding type, see TensorFlow docs (default: ‘same’).
  • dilation (int > 0 | (int > 0, int > 0)) – Dilation value (default: 1).
  • bias (bool) – Whether to add a trainable bias variable (default: true).
  • ('crelu' | 'elu' | 'leaky-relu' | 'none' | 'relu' | 'selu' | 'sigmoid' | (activation) – ‘softmax’ | ‘softplus’ | ‘softsign’ | ‘swish’ | ‘tanh’): Activation nonlinearity (default: “relu”).
  • dropout (parameter, 0.0 <= float < 1.0) – Dropout rate (default: 0.0).
  • initialization_scale (float > 0.0) – Initialization scale (default: 1.0).
  • vars_trainable (bool) – Whether layer variables are trainable (default: true).
  • l2_regularization (float >= 0.0) – Scalar controlling L2 regularization (default: inherit value of parent module).
  • name (string) – Layer name (default: internally chosen).
  • input_spec (specification) – internal use.
class tensorforce.core.layers.Conv2dTranspose(*, size, window=3, output_shape=None, stride=1, padding='same', dilation=1, bias=True, activation='relu', dropout=0.0, initialization_scale=1.0, vars_trainable=True, l2_regularization=None, name=None, input_spec=None)

2-dimensional transposed convolutional layer, also known as deconvolution layer (specification key: deconv2d).

Parameters:
  • size (int >= 0) – Layer output size, 0 implies additionally removing the axis (required).
  • window (int > 0 | (int > 0, int > 0)) – Window size (default: 3).
  • output_shape (int > 0 | (int > 0, int > 0)) – Output shape (default: same as input).
  • stride (int > 0 | (int > 0, int > 0)) – Stride size (default: 1).
  • padding ('same' | 'valid') – Padding type, see TensorFlow docs (default: ‘same’).
  • dilation (int > 0 | (int > 0, int > 0)) – Dilation value (default: 1).
  • bias (bool) – Whether to add a trainable bias variable (default: true).
  • ('crelu' | 'elu' | 'leaky-relu' | 'none' | 'relu' | 'selu' | 'sigmoid' | (activation) – ‘softmax’ | ‘softplus’ | ‘softsign’ | ‘swish’ | ‘tanh’): Activation nonlinearity (default: “relu”).
  • dropout (parameter, 0.0 <= float < 1.0) – Dropout rate (default: 0.0).
  • initialization_scale (float > 0.0) – Initialization scale (default: 1.0).
  • vars_trainable (bool) – Whether layer variables are trainable (default: true).
  • l2_regularization (float >= 0.0) – Scalar controlling L2 regularization (default: inherit value of parent module).
  • name (string) – Layer name (default: internally chosen).
  • input_spec (specification) – internal use.

Embedding layers

class tensorforce.core.layers.Embedding(*, size, num_embeddings=None, max_norm=None, bias=True, activation='tanh', dropout=0.0, vars_trainable=True, l2_regularization=None, name=None, input_spec=None)

Embedding layer (specification key: embedding).

Parameters:
  • size (int >= 0) – Layer output size, 0 implies additionally removing the axis (required).
  • num_embeddings (int > 0) – If set, specifies the number of embeddings (default: none).
  • max_norm (float) – If set, embeddings are clipped if their L2-norm is larger (default: none).
  • bias (bool) – Whether to add a trainable bias variable (default: true).
  • ('crelu' | 'elu' | 'leaky-relu' | 'none' | 'relu' | 'selu' | 'sigmoid' | (activation) – ‘softmax’ | ‘softplus’ | ‘softsign’ | ‘swish’ | ‘tanh’): Activation nonlinearity (default: tanh).
  • dropout (parameter, 0.0 <= float < 1.0) – Dropout rate (default: 0.0).
  • vars_trainable (bool) – Whether layer variables are trainable (default: true).
  • l2_regularization (float >= 0.0) – Scalar controlling L2 regularization (default: inherit value of parent module).
  • name (string) – Layer name (default: internally chosen).
  • input_spec (specification) – internal use.

Recurrent layers (unrolled over timesteps)

class tensorforce.core.layers.Rnn(*, cell, size, horizon, bias=True, activation='tanh', dropout=0.0, vars_trainable=True, l2_regularization=None, name=None, input_spec=None, **kwargs)

Recurrent neural network layer which is unrolled over the sequence of timesteps (per episode), that is, the RNN cell is applied to the layer input at each timestep and the RNN consequently maintains a temporal internal state over the course of an episode (specification key: rnn).

Parameters:
  • cell ('gru' | 'lstm') – The recurrent cell type (required).
  • size (int >= 0) – Layer output size, 0 implies additionally removing the axis (required).
  • horizon (parameter, int >= 0) – Past horizon, for truncated backpropagation through time (required).
  • bias (bool) – Whether to add a trainable bias variable (default: true).
  • ('crelu' | 'elu' | 'leaky-relu' | 'none' | 'relu' | 'selu' | 'sigmoid' | (activation) – ‘softmax’ | ‘softplus’ | ‘softsign’ | ‘swish’ | ‘tanh’): Activation nonlinearity (default: tanh).
  • dropout (parameter, 0.0 <= float < 1.0) – Dropout rate (default: 0.0).
  • vars_trainable (bool) – Whether layer variables are trainable (default: true).
  • l2_regularization (float >= 0.0) – Scalar controlling L2 regularization (default: inherit value of parent module).
  • name (string) – Layer name (default: internally chosen).
  • input_spec (specification) – internal use.
  • kwargs – Additional arguments for Keras RNN cell layer, see TensorFlow docs.
class tensorforce.core.layers.Lstm(*, size, horizon, bias=False, activation=None, dropout=0.0, vars_trainable=True, l2_regularization=None, name=None, input_spec=None, **kwargs)

Long short-term memory layer which is unrolled over the sequence of timesteps (per episode), that is, the LSTM cell is applied to the layer input at each timestep and the LSTM consequently maintains a temporal internal state over the course of an episode (specification key: lstm).

Parameters:
  • size (int >= 0) – Layer output size, 0 implies additionally removing the axis (required).
  • horizon (parameter, int >= 0) – Past horizon, for truncated backpropagation through time (required).
  • bias (bool) – Whether to add a trainable bias variable (default: true).
  • ('crelu' | 'elu' | 'leaky-relu' | 'none' | 'relu' | 'selu' | 'sigmoid' | (activation) – ‘softmax’ | ‘softplus’ | ‘softsign’ | ‘swish’ | ‘tanh’): Activation nonlinearity (default: tanh).
  • dropout (parameter, 0.0 <= float < 1.0) – Dropout rate (default: 0.0).
  • vars_trainable (bool) – Whether layer variables are trainable (default: true).
  • l2_regularization (float >= 0.0) – Scalar controlling L2 regularization (default: inherit value of parent module).
  • name (string) – Layer name (default: internally chosen).
  • input_spec (specification) – internal use.
  • kwargs – Additional arguments for Keras LSTM layer, see TensorFlow docs.
class tensorforce.core.layers.Gru(*, size, horizon, bias=False, activation=None, dropout=0.0, vars_trainable=True, l2_regularization=None, name=None, input_spec=None, **kwargs)

Gated recurrent unit layer which is unrolled over the sequence of timesteps (per episode), that is, the GRU cell is applied to the layer input at each timestep and the GRU consequently maintains a temporal internal state over the course of an episode (specification key: gru).

Parameters:
  • size (int >= 0) – Layer output size, 0 implies additionally removing the axis (required).
  • horizon (parameter, int >= 0) – Past horizon, for truncated backpropagation through time (required).
  • bias (bool) – Whether to add a trainable bias variable (default: true).
  • ('crelu' | 'elu' | 'leaky-relu' | 'none' | 'relu' | 'selu' | 'sigmoid' | (activation) – ‘softmax’ | ‘softplus’ | ‘softsign’ | ‘swish’ | ‘tanh’): Activation nonlinearity (default: tanh).
  • dropout (parameter, 0.0 <= float < 1.0) – Dropout rate (default: 0.0).
  • vars_trainable (bool) – Whether layer variables are trainable (default: true).
  • l2_regularization (float >= 0.0) – Scalar controlling L2 regularization (default: inherit value of parent module).
  • name (string) – Layer name (default: internally chosen).
  • input_spec (specification) – internal use.
  • kwargs – Additional arguments for Keras GRU layer, see TensorFlow docs.

Input recurrent layers (unrolled over sequence input)

class tensorforce.core.layers.InputRnn(*, cell, size, return_final_state=True, bias=True, activation='tanh', dropout=0.0, vars_trainable=True, l2_regularization=None, name=None, input_spec=None, **kwargs)

Recurrent neural network layer which is unrolled over a sequence input independently per timestep, and consequently does not maintain an internal state (specification key: input_rnn).

Parameters:
  • cell ('gru' | 'lstm') – The recurrent cell type (required).
  • size (int >= 0) – Layer output size, 0 implies additionally removing the axis (required).
  • return_final_state (bool) – Whether to return the final state instead of the per-step outputs (default: true).
  • bias (bool) – Whether to add a trainable bias variable (default: true).
  • ('crelu' | 'elu' | 'leaky-relu' | 'none' | 'relu' | 'selu' | 'sigmoid' | (activation) – ‘softmax’ | ‘softplus’ | ‘softsign’ | ‘swish’ | ‘tanh’): Activation nonlinearity (default: tanh).
  • dropout (parameter, 0.0 <= float < 1.0) – Dropout rate (default: 0.0).
  • vars_trainable (bool) – Whether layer variables are trainable (default: true).
  • l2_regularization (float >= 0.0) – Scalar controlling L2 regularization (default: inherit value of parent module).
  • name (string) – Layer name (default: internally chosen).
  • input_spec (specification) – internal use.
  • kwargs – Additional arguments for Keras RNN layer, see TensorFlow docs.
class tensorforce.core.layers.InputLstm(*, size, return_final_state=True, bias=False, activation=None, dropout=0.0, vars_trainable=True, l2_regularization=None, name=None, input_spec=None, **kwargs)

Long short-term memory layer which is unrolled over a sequence input independently per timestep, and consequently does not maintain an internal state (specification key: input_lstm).

Parameters:
  • size (int >= 0) – Layer output size, 0 implies additionally removing the axis (required).
  • return_final_state (bool) – Whether to return the final state instead of the per-step outputs (default: true).
  • bias (bool) – Whether to add a trainable bias variable (default: true).
  • ('crelu' | 'elu' | 'leaky-relu' | 'none' | 'relu' | 'selu' | 'sigmoid' | (activation) – ‘softmax’ | ‘softplus’ | ‘softsign’ | ‘swish’ | ‘tanh’): Activation nonlinearity (default: tanh).
  • dropout (parameter, 0.0 <= float < 1.0) – Dropout rate (default: 0.0).
  • vars_trainable (bool) – Whether layer variables are trainable (default: true).
  • l2_regularization (float >= 0.0) – Scalar controlling L2 regularization (default: inherit value of parent module).
  • name (string) – Layer name (default: internally chosen).
  • input_spec (specification) – internal use.
  • kwargs – Additional arguments for Keras LSTM layer, see TensorFlow docs.
class tensorforce.core.layers.InputGru(*, size, return_final_state=True, bias=False, activation=None, dropout=0.0, vars_trainable=True, l2_regularization=None, name=None, input_spec=None, **kwargs)

Gated recurrent unit layer which is unrolled over a sequence input independently per timestep, and consequently does not maintain an internal state (specification key: input_gru).

Parameters:
  • size (int >= 0) – Layer output size, 0 implies additionally removing the axis (required).
  • return_final_state (bool) – Whether to return the final state instead of the per-step outputs (default: true).
  • bias (bool) – Whether to add a trainable bias variable (default: true).
  • ('crelu' | 'elu' | 'leaky-relu' | 'none' | 'relu' | 'selu' | 'sigmoid' | (activation) – ‘softmax’ | ‘softplus’ | ‘softsign’ | ‘swish’ | ‘tanh’): Activation nonlinearity (default: tanh).
  • dropout (parameter, 0.0 <= float < 1.0) – Dropout rate (default: 0.0).
  • vars_trainable (bool) – Whether layer variables are trainable (default: true).
  • l2_regularization (float >= 0.0) – Scalar controlling L2 regularization (default: inherit value of parent module).
  • name (string) – Layer name (default: internally chosen).
  • input_spec (specification) – internal use.
  • kwargs – Additional arguments for Keras GRU layer, see TensorFlow docs.

Pooling layers

class tensorforce.core.layers.Flatten(*, name=None, input_spec=None)

Flatten layer (specification key: flatten).

Parameters:
  • name (string) – Layer name (default: internally chosen).
  • input_spec (specification) – internal use.
class tensorforce.core.layers.Pooling(*, reduction, name=None, input_spec=None)

Pooling layer (global pooling) (specification key: pooling).

Parameters:
  • reduction ('concat' | 'max' | 'mean' | 'product' | 'sum') – Pooling type (required).
  • name (string) – Layer name (default: internally chosen).
  • input_spec (specification) – internal use.
class tensorforce.core.layers.Pool1d(*, reduction, window=2, stride=2, padding='same', name=None, input_spec=None)

1-dimensional pooling layer (local pooling) (specification key: pool1d).

Parameters:
  • reduction ('average' | 'max') – Pooling type (required).
  • window (int > 0) – Window size (default: 2).
  • stride (int > 0) – Stride size (default: 2).
  • padding ('same' | 'valid') – Padding type, see TensorFlow docs (default: ‘same’).
  • name (string) – Layer name (default: internally chosen).
  • input_spec (specification) – internal use.
class tensorforce.core.layers.Pool2d(*, reduction, window=2, stride=2, padding='same', name=None, input_spec=None)

2-dimensional pooling layer (local pooling) (specification key: pool2d).

Parameters:
  • reduction ('average' | 'max') – Pooling type (required).
  • window (int > 0 | (int > 0, int > 0)) – Window size (default: 2).
  • stride (int > 0 | (int > 0, int > 0)) – Stride size (default: 2).
  • padding ('same' | 'valid') – Padding type, see TensorFlow docs (default: ‘same’).
  • name (string) – Layer name (default: internally chosen).
  • input_spec (specification) – internal use.

Normalization layers

class tensorforce.core.layers.LinearNormalization(*, min_value=None, max_value=None, name=None, input_spec=None)

Linear normalization layer which scales and shifts the input to [-2.0, 2.0], for bounded states with min/max_value (specification key: linear_normalization).

Parameters:
  • min_value (float | array[float]) – Lower bound of the value (default: based on input_spec).
  • max_value (float | array[float]) – Upper bound of the value range (default: based on input_spec).
  • name (string) – Layer name (default: internally chosen).
  • input_spec (specification) – internal use.
class tensorforce.core.layers.ExponentialNormalization(*, decay, axes=None, only_mean=False, min_variance=0.0001, name=None, input_spec=None)

Normalization layer based on the exponential moving average of mean and variance over the temporal sequence of inputs (specification key: exponential_normalization).

Parameters:
  • decay (parameter, 0.0 <= float <= 1.0) – Decay rate (required).
  • axes (iter[int >= 0]) – Normalization axes, excluding batch axis (default: all but last input axes).
  • only_mean (bool) – Whether to normalize only with respect to mean, not variance (default: false).
  • min_variance (float > 0.0) – Clip variance lower than minimum (default: 1e-4).
  • name (string) – Layer name (default: internally chosen).
  • input_spec (specification) – internal use.
class tensorforce.core.layers.InstanceNormalization(*, axes=None, only_mean=False, min_variance=0.0001, name=None, input_spec=None)

Instance normalization layer (specification key: instance_normalization).

Parameters:
  • axes (iter[int >= 0]) – Normalization axes, excluding batch axis (default: all input axes).
  • only_mean (bool) – Whether to normalize only with respect to mean, not variance (default: false).
  • min_variance (float > 0.0) – Clip variance lower than minimum (default: 1e-4).
  • name (string) – Layer name (default: internally chosen).
  • input_spec (specification) – internal use.
class tensorforce.core.layers.BatchNormalization(*, axes=None, only_mean=False, min_variance=0.0001, name=None, input_spec=None)

Batch normalization layer, generally should only be used for the agent arguments reward_processing[return_processing] and reward_processing[advantage_processing] (specification key: batch_normalization).

Parameters:
  • axes (iter[int >= 0]) – Normalization axes, excluding batch axis (default: all but last input axes).
  • only_mean (bool) – Whether to normalize only with respect to mean, not variance (default: false).
  • min_variance (float > 0.0) – Clip variance lower than minimum (default: 1e-4).
  • name (string) – Layer name (default: internally chosen).
  • input_spec (specification) – internal use.

Misc layers

class tensorforce.core.layers.Reshape(*, shape, name=None, input_spec=None)

Reshape layer (specification key: reshape).

Parameters:
  • shape (int | iter[int]) – New shape (required).
  • name (string) – Layer name (default: internally chosen).
  • input_spec (specification) – internal use.
class tensorforce.core.layers.Activation(*, nonlinearity, name=None, input_spec=None)

Activation layer (specification key: activation).

Parameters:
  • ('crelu' | 'elu' | 'leaky-relu' | 'none' | 'relu' | 'selu' | 'sigmoid' | (nonlinearity) – ‘softmax’ | ‘softplus’ | ‘softsign’ | ‘swish’ | ‘tanh’): Nonlinearity (required).
  • name (string) – Layer name (default: internally chosen).
  • input_spec (specification) – internal use.
class tensorforce.core.layers.Dropout(*, rate, name=None, input_spec=None)

Dropout layer (specification key: dropout).

Parameters:
  • rate (parameter, 0.0 <= float < 1.0) – Dropout rate (required).
  • name (string) – Layer name (default: internally chosen).
  • input_spec (specification) – internal use.
class tensorforce.core.layers.Clipping(*, lower=None, upper=None, name=None, input_spec=None)

Clipping layer (specification key: clipping).

Parameters:
  • lower (parameter, float) – Lower clipping value (default: no lower bound).
  • upper (parameter, float) – Upper clipping value (default: no upper bound).
  • name (string) – Layer name (default: internally chosen).
  • input_spec (specification) – internal use.
class tensorforce.core.layers.Image(*, height=None, width=None, grayscale=False, name=None, input_spec=None)

Image preprocessing layer (specification key: image).

Parameters:
  • height (int) – Height of resized image (default: no resizing or relative to width).
  • width (int) – Width of resized image (default: no resizing or relative to height).
  • grayscale (bool | iter[float]) – Turn into grayscale image, optionally using given weights (default: false).
  • name (string) – Layer name (default: internally chosen).
  • input_spec (specification) – internal use.
class tensorforce.core.layers.Deltafier(*, concatenate=False, name=None, input_spec=None)

Deltafier layer computing the difference between the current and the previous input; can only be used as preprocessing layer (specification key: deltafier).

Parameters:
  • concatenate (False | int >= 0) – Whether to concatenate instead of replace deltas with input, and if so, concatenation axis (default: false).
  • name (string) – Layer name (default: internally chosen).
  • input_spec (specification) – internal use.
class tensorforce.core.layers.Sequence(*, length, axis=-1, concatenate=True, name=None, input_spec=None)

Sequence layer stacking the current and previous inputs; can only be used as preprocessing layer (specification key: sequence).

Parameters:
  • length (int > 0) – Number of inputs to concatenate (required).
  • axis (int >= 0) – Concatenation axis, excluding batch axis (default: last axis).
  • concatenate (bool) – Whether to concatenate inputs at given axis, otherwise introduce new sequence axis (default: true).
  • name (string) – Layer name (default: internally chosen).
  • input_spec (specification) – internal use.

Special layers

class tensorforce.core.layers.Function(function, output_spec=None, l2_regularization=None, name=None, input_spec=None)

Custom TensorFlow function layer (specification key: function).

Parameters:
  • function (lambda[x -> x]) – TensorFlow function (required).
  • output_spec (specification) – Output tensor specification containing type and/or shape information (default: same as input).
  • l2_regularization (float >= 0.0) – Scalar controlling L2 regularization (default: inherit value of parent module).
  • name (string) – Layer name (default: internally chosen).
  • input_spec (specification) – internal use.
class tensorforce.core.layers.Register(*, tensor, name=None, input_spec=None)

Tensor retrieval layer, which is useful when defining more complex network architectures which do not follow the sequential layer-stack pattern, for instance, when handling multiple inputs (specification key: register).

Parameters:
  • tensor (string) – Name under which tensor will be registered (required).
  • name (string) – Layer name (default: internally chosen).
  • input_spec (specification) – internal use.
class tensorforce.core.layers.Retrieve(*, tensors, aggregation='concat', axis=0, name=None, input_spec=None)

Tensor retrieval layer, which is useful when defining more complex network architectures which do not follow the sequential layer-stack pattern, for instance, when handling multiple inputs (specification key: retrieve).

Parameters:
  • tensors (iter[string]) – Names of tensors to retrieve, either state names or previously registered tensors (required).
  • aggregation ('concat' | 'product' | 'stack' | 'sum') – Aggregation type in case of multiple tensors (default: ‘concat’).
  • axis (int >= 0) – Aggregation axis, excluding batch axis (default: 0).
  • name (string) – Layer name (default: internally chosen).
  • input_spec (specification) – internal use.
class tensorforce.core.layers.Block(*, layers, name=None, input_spec=None)

Block of layers (specification key: block).

Parameters:
  • layers (iter[specification]) –

    Layers configuration, see layers (required).

  • name (string) – Layer name (default: internally chosen).
  • input_spec (specification) – internal use.
class tensorforce.core.layers.Reuse(*, layer, name=None, input_spec=None)

Reuse layer (specification key: reuse).

Parameters:
  • layer (string) – Name of a previously defined layer (required).
  • name (string) – Layer name (default: internally chosen).
  • input_spec (specification) – internal use.

Keras layer

class tensorforce.core.layers.Keras(*, layer, l2_regularization=None, name=None, input_spec=None, **kwargs)

Keras layer (specification key: keras).

Parameters:
  • layer (string) – Keras layer class name, see TensorFlow docs (required).
  • l2_regularization (float >= 0.0) – Scalar controlling L2 regularization (default: inherit value of parent module).
  • name (string) – Layer name (default: internally chosen).
  • input_spec (specification) – internal use.
  • kwargs – Arguments for the Keras layer, see TensorFlow docs.