# Setting input shape for an NLP task in R(Rstudio) using keras 1D convolution layer, when it expects 3 dimensional input (a tensor)

I am using R programming language and using Keras API to build a functional 1D CNN.

I have a matrix of my dataset of the following shape rows*features (6000*1024).

The input layer is set using the following code:

input_layer = layer_input(shape = 1024, batch_shape = c(nrow(train_matrix),1024), dtype = 'float64')


and then I am building a 1d conv layer as follows:

conv1 = input_layer %>% layer_conv_1d(filters = 32, kernel_size = 50, strides = 10, input_shape = 1024, batch_input_shape = list(NULL, 1024) ,dtype = 'float64', activation = 'relu' )


But I get the following error:

Error in py_call_impl(callable, dots$$args, dots$$keywords) : ValueError: Input 0 is incompatible with layer conv1d: expected ndim=3, found ndim=2

I believe it is due to the fact that 1D cnn layer expects the input in the following form

Input shape: 3D tensor with shape: (batch_size, steps, input_dim)

I understand that I have to reshape my data as (NULL, nrow(train_matrix), 1; as this has been suggested in various answer for the same issue arising for keras when used in Python.

If I am right,

1. what values should I provide to input layer
2. how should i reshape my training data?
3. does that mean I have to reshape the test data as well?

also if my understanding is wrong what should be done otherwise ?

I used Keras R API function k_reshape( 2d_tensor, (list_of_new_dims)) --> k_reshape(input_layer, list(nrow(train_matrix), num_of_feature_vectors, 1).
nrow(train_matrix) - the total number of rows in my matrix (no of samples)
num_of_feature_vectors - total number of columns in matrix (total number of features)
1 - i want a 3d tensor with only 1 element at z axis, therefore z axis is initialised to 1