One dimensional convolution is usually used to process text, so the input is usually a long piece of text, which is a list of words
The function is defined as follows:
tf.layers.conv1d(
inputs,
filters,
kernel_size,
strides=1,
padding='valid',
data_format='channels_last',
dilation_rate=1,
activation=None,
use_bias=True,
kernel_initializer=None,
bias_initializer=tf.zeros_initializer(),
kernel_regularizer=None,
bias_regularizer=None,
activity_regularizer=None,
kernel_constraint=None,
bias_constraint=None,
trainable=True,
name=None,
reuse=None
)
The more important parameters are inputs, filters and kernel_ Size, which are described below
Inputs: input tensor. Dimension (none, a, b) is a three-dimensional tensor
None: usually the number of samples to be filled, batch_ size
A: the number of words or words in a sentence
B: vector dimension of word or word
Filters: the number of filters
kernel_ Size: the size of convolution kernel. Convolution kernel should be two-dimensional. Only one dimension needs to be specified here, because the second dimension of convolution kernel is consistent with the input word vector dimension, because for sentences, convolution can only move along the word direction, that is, it can only move in the column dimension
An example:
inputs = tf.placeholder (‘float’, shape=[None, 6, 8])
out = tf.layers.conv1d (inputs, 5, 3)
Note: for a sample, the sentence length is 6 words, and the dimension of the word vector is 8
filters=5, kernel_ Size = 3, so the dimension of convolution kernel is 3 * 8
Then the input 6 * 8 is convoluted by 3 * 8 convolution kernel to get a vector of 4 * 1 (4 = 6-3 + 1)
And because there are five filters, we get five 4 * 1 vectors
The drawing is as follows: