madmom.ml.rnn

This module contains recurrent neural network (RNN) related functionality.

It’s main purpose is to serve as a substitute for testing neural networks which were trained by other ML packages or programs without requiring these packages or programs as dependencies.

The only allowed dependencies are Python + numpy + scipy.

The structure reflects just the needed functionality for testing networks. This module is not meant to be a general purpose RNN with lots of functionality. Just use one of the many NN/ML packages out there if you need training or any other stuff.

class madmom.ml.rnn.BidirectionalLayer

Bidirectional network layer.

Parameters:

fwd_layer : Layer instance

Forward layer.

bwd_layer : Layer instance

Backward layer.

activate()

Activate the layer.

After activating the fwd_layer with the data and the bwd_layer with the data in reverse temporal order, the two activations are stacked and returned.

Parameters:

data : numpy array

Activate with this data.

Returns:

numpy array

Activations for this data.

class madmom.ml.rnn.Cell

Cell as used by LSTM units.

Parameters:

weights : numpy array, shape ()

Weights.

bias : scalar or numpy array, shape ()

Bias.

recurrent_weights : numpy array, shape ()

Recurrent weights.

transfer_fn : numpy ufunc, optional

Transfer function.

activate()

Activate the cell / gate with the given data, state (if peephole connections are used) and the output (if recurrent connections are used).

Parameters:

data : scalar or numpy array, shape ()

Input data for the cell.

prev : scalar or numpy array, shape ()

Output data of the previous time step.

state : scalar or numpy array, shape ()

State data of the {current | previous} time step.

Returns:

numpy array

Activations of the gate for this data.

class madmom.ml.rnn.FeedForwardLayer

Feed-forward network layer.

Parameters:

weights : numpy array, shape ()

Weights.

bias : scalar or numpy array, shape ()

Bias.

transfer_fn : numpy ufunc

Transfer function.

activate()

Activate the layer.

Parameters:

data : numpy array

Activate with this data.

Returns:

numpy array

Activations for this data.

class madmom.ml.rnn.Gate

Gate as used by LSTM units.

Parameters:

weights : numpy array, shape ()

Weights.

bias : scalar or numpy array, shape ()

Bias.

recurrent_weights : numpy array, shape ()

Recurrent weights.

peephole_weights : numpy array, shape ()

Peephole weights.

transfer_fn : numpy ufunc, optional

Transfer function.

class madmom.ml.rnn.LSTMLayer

Recurrent network layer with Long Short-Term Memory units.

Parameters:

weights : numpy array, shape ()

Weights.

bias : scalar or numpy array, shape ()

Bias.

recurrent_weights : numpy array, shape ()

Recurrent weights.

peephole_weights : numpy array, shape ()

Peephole weights.

transfer_fn : numpy ufunc, optional

Transfer function.

activate()

Activate the LSTM layer.

Parameters:

data : numpy array

Activate with this data.

Returns:

numpy array

Activations for this data.

madmom.ml.rnn.RNN

alias of RecurrentNeuralNetwork

class madmom.ml.rnn.RNNProcessor

Recurrent Neural Network (RNN) processor class.

Parameters:

nn_files : list

List of files with the RNN models.

num_threads : int, optional

Number of parallel working threads.

add_arguments

Add recurrent neural network testing options to an existing parser.

Parameters:

parser : argparse parser instance

Existing argparse parser object.

nn_files : list

RNN model files.

Returns:

argparse argument group

Recurrent neural network argument parser group.

class madmom.ml.rnn.RecurrentLayer

Recurrent network layer.

Parameters:

weights : numpy array, shape ()

Weights.

bias : scalar or numpy array, shape ()

Bias.

recurrent_weights : numpy array, shape ()

Recurrent weights.

transfer_fn : numpy ufunc

Transfer function.

activate()

Activate the layer.

Parameters:

data : numpy array

Activate with this data.

Returns:

numpy array

Activations for this data.

class madmom.ml.rnn.RecurrentNeuralNetwork

Recurrent Neural Network (RNN) class.

Parameters:

layers : list

Layers of the RNN.

classmethod load()

Instantiate a RecurrentNeuralNetwork from a .npz model file.

Parameters:

filename : str

Name of the .npz file with the RNN model.

Returns:

RecurrentNeuralNetwork instance

RNN instance

process()

Process the given data with the RNN.

Parameters:

data : numpy array

Activate the network with this data.

Returns:

numpy array

Network predictions for this data.

madmom.ml.rnn.average_predictions

Returns the average of all predictions.

Parameters:

predictions : list

Predictions (i.e. NN activation functions).

Returns:

numpy array

Averaged prediction.

madmom.ml.rnn.linear

Linear function.

Parameters:

x : numpy array

Input data.

out : numpy array, optional

Array to hold the output data.

Returns:

numpy array

Unaltered input data.

madmom.ml.rnn.relu

Rectified linear (unit) transfer function.

Parameters:

x : numpy array

Input data.

out : numpy array, optional

Array to hold the output data.

Returns:

numpy array

Rectified linear of input data.

madmom.ml.rnn.sigmoid

Logistic sigmoid function.

Parameters:

x : numpy array

Input data.

out : numpy array, optional

Array to hold the output data.

Returns:

numpy array

Logistic sigmoid of input data.

madmom.ml.rnn.softmax

Softmax transfer function.

Parameters:

x : numpy array

Input data.

out : numpy array, optional

Array to hold the output data.

Returns:

numpy array

Softmax of input data.