Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

pad_sequences

Pad a linear sequence for an RNN input


Description

Transform a list of num_samples sequences (lists of scalars) into a 2D Numpy array of shape (num_samples, num_timesteps). num_timesteps is either the maxlen argument if provided, or the length of the longest sequence otherwise. Sequences that are shorter than num_timesteps are padded with value at the end. Sequences longer than num_timesteps are truncated so that it fits the desired length. Position where padding or truncation happens is determined by padding or truncating, respectively.

Usage

pad_sequences(sequences, maxlen = NULL, dtype = "int32", padding = "pre",
  truncating = "pre", value = 0)

Arguments

sequences

vector of lists of int or float.

maxlen

None or int. Maximum sequence length, longer sequences are truncated and shorter sequences are padded with zeros at the end.

dtype

datatype of the Numpy array returned.

padding

'pre' or 'post', pad either before or after each sequence.

truncating

'pre' or 'post', remove values from sequences larger than maxlen either in the beginning or in the end of the sequence

value

float, value to pad the sequences to the desired value.

Author(s)

Taylor B. Arnold, taylor.arnold@acm.org

References

See Also


kerasR

R Interface to the Keras Deep Learning Library

v0.6.1
LGPL-2
Authors
Taylor Arnold [aut, cre]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.