Extract local patterns across time steps.
Temporal sequence modeling
TensorFlow · Class
A Keras layer that performs one-dimensional convolution over spatial or temporal sequences. It transforms sliding input windows into a configurable number of output channels.
Conv1D slides a learned kernel across one spatial or temporal axis. It optionally adds a bias and activation, converting each input window into an output with the configured number of filters.
tf.keras.layers.Conv1D(filters, kernel_size, strides=1, padding='valid', data_format=None, dilation_rate=1, groups=1, activation=None, use_bias=True, kernel_initializer='glorot_uniform', bias_initializer='zeros', kernel_regularizer=None, bias_regularizer=None, activity_regularizer=None, kernel_constraint=None, bias_constraint=None, **kwargs)| Name | Type | Description |
|---|---|---|
filters | int | Number of output filters and output channels. |
kernel_size | int or tuple/list of 1 integer | Width of the one-dimensional convolution window. |
strides | int or tuple/list of 1 integer | Step size of the convolution window. |
padding | string | Padding mode: valid, same, or causal. |
data_format | string or None | Input/output channel layout. |
dilation_rate | int or tuple/list of 1 integer | Dilation rate of the convolution. |
groups | int | Number of input channels grouped together for convolution. |
activation | string or callable or None | Optional activation function. |
use_bias | bool | Whether to add a bias vector. |
kernel_initializer | initializer | Initializer for the convolution kernel. |
bias_initializer | initializer | Initializer for the bias vector. |
kernel_regularizer | regularizer or None | Regularizer for the kernel. |
A 3D output tensor. With channels_last it has shape (batch_shape, new_steps, filters); with channels_first it has shape (batch_shape, filters, new_steps).
import tensorflow as tf
layer = tf.keras.layers.Conv1D(
filters=16, kernel_size=3, padding="same", activation="relu"
)
x = tf.random.normal((4, 10, 8))
y = layer(x)
print(y.shape) # (4, 10, 16)Creates a Conv1D layer, applies it to a batch of 10-step sequences with 8 channels, and prints the resulting shape.
Temporal sequence modeling
One-dimensional signal processing
Text classification
Time-series forecasting
Conv1D applies each learned filter across a single spatial or temporal dimension. For channels-last data, the input is shaped as batch, steps, channels, and the output is batch, new steps, filters.
Follow-up: How would you preserve the number of steps? Use padding="same" when the stride is one; the resulting output length matches the input length.
filters determines the output-space size and therefore the number of channels in the result. kernel_size determines the width of the sliding convolution window.
Follow-up: What changes when data_format="channels_first"? The input and output place channels before the steps dimension.
The layer can add a bias vector when use_bias is enabled and then apply activation when activation is not None. Its padding choices are valid, same, and causal.
Follow-up: When is causal padding useful? It prevents an output at a time step from depending on later input steps, making it suitable for some temporal models.
tf.keras.layers.Convolution1Dtf.keras.layers.DepthwiseConv1Dtf.keras.layers.SeparableConv1Dtf.keras.layers.Conv1DTranspose