Reputation: 1307
I need to perform convolution along the text line of fixed size. So essentially, a training example is of a form: 1*N_FEATURES
where N_FEATURES
is equal to 3640 (140 characters encoded as one-hot, so 40*26=3640). I am trying to make sense of the example here, precisely:
def my_conv_model(X, y):
X = tf.reshape(X, [-1, N_FEATURES, 1, 1]) # to form a 4d tensor of shape batch_size x n_features x 1 x 1
features = skflow.ops.conv2d(X, N_FILTERS, [WINDOW_SIZE, 1], padding='VALID') # this will give you sliding window of WINDOW_SIZE x 1 convolution.
pool = tf.squeeze(tf.reduce_max(features, 1), squeeze_dims=[1])
return return skflow.models.logistic_regression(pool, y)
I do not understand why in this line:
features = skflow.ops.conv2d(X, N_FILTERS, [WINDOW_SIZE, 1], padding='VALID')
we have : [WINDOW_SIZE, 1]
and not [1, WINDOW_SIZE]
?
Since as far as I understand, convolution should be performed as following:
training example: '001010101000100101'
sliding window: |---|
|---|
|---|
and so on, each window of size [1, WINDOW_SIZE] since its height is 1, and width is 3. But why does the example given says " features = skflow.ops.conv2d(X, N_FILTERS, [WINDOW_SIZE, 1], padding='VALID'
)"?
Upvotes: 0
Views: 6548
Reputation: 77857
A 4-D tensor is exactly what it indicates: a tensor with four dimensions (subscripts, features, ...).
The notation for a sliding window in one dimension is a notational convention. For convenience, we put the significant dimension first, and keep the 1 sizes for the end. Thus, a 3-wide slice (1-D window) is given as a 3x1 window.
Upvotes: 2