0
votes

I was going through this paper: CNN for Sentence Modelling

The paper seems to describe a convolution along the following lines:

With a matrix input I of size [d,m] and a weight matrix W of size [d,s]

The convolution is done like each row of Input matrix is convoluted with each row of the weight matrix, (basically a row-wise 1D convolution). The output will be of size [d,m] with appropriate padding or [d,m-s+1] without padding.

My understanding is that, The only difference between this and simply doing a 1D convolution is that each row of the input matrix will have it's own set of weights to convolve with.

Is it possible to achieve such a convolution layer in Tensorflow?

1

1 Answers

2
votes

You can do this.

I = tf.reshape(I, [1,d,1,m])
W = tf.reshape(W, [1,d,s,1)
strides = [1,stride,1,1]
output = tf.nn.depthwise_conv2d(I, W, strides, padding='SAME')

I think this is what you're looking for. It will apply each filter row wise across the input and return back the convolved result.