pad_sequences: Pad a linear sequence for an RNN input

View source: R/preprocessing.R

pad_sequencesR Documentation

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

Chollet, Francois. 2015. Keras: Deep Learning library for Theano and TensorFlow.

See Also

Other preprocessing: Tokenizer, expand_dims, img_to_array, load_img, one_hot, text_to_word_sequence


kerasR documentation built on Aug. 17, 2022, 5:06 p.m.