<p>Two things that come to my mind: your max-pooling layers are reducing the size of the input to the next convolutional layers every time and eventually the size is too small to run another max-pooling operation. Try running</p>
<pre><code> tf.print(model.summary) 
</code></pre>
<p>after each max-pooling operation and you will quickly find out that your tensor cannot be further reduced. You can then consider using a different <code>pool_size</code> in your max-pooling layers.</p>
<p>The second thing I notice (I am not sure if it is intentional), but <em>MaxPooling1D != Global Max Pooling</em>. Keras supports both <a href="https://keras.io/api/layers/pooling_layers/" rel="nofollow noreferrer">operations</a>. Take a look at the documentation.</p>
<p>On a side note, sentence classification with CNNs was widely popularized by the <a href="https://arxiv.org/pdf/1408.5882.pdf" rel="nofollow noreferrer">work</a> of Yoon Kim. In his work, he shows that global max-pooling operations perform much better than striding max-pooling operations in sentence classification (when using word embeddings, as you are doing).</p>
How to configure and train the model using Glove and CNN for text classification?
<p>I have worked with text classification using Glove and CNN and found the problem below:</p>
<pre><code>File &quot;c:\programfiles_anaconda\anaconda3\envs\math_stat_class\lib\site-packages\tensorflow\python\framework\ops.py&quot;, line 1657, in _create_c_op
    raise ValueError(str(e))

ValueError: Negative dimension size caused by subtracting 5 from 1 for '{{node max_pooling1d_9/MaxPool}} = MaxPool[T=DT_FLOAT, data_format=&quot;NHWC&quot;, ksize=[1, 5, 1, 1], padding=&quot;VALID&quot;, strides=[1, 5, 1, 1]](max_pooling1d_9/ExpandDims)' with input shapes: [?,1,1,128].
</code></pre>
<h3>Glove input</h3>
<pre class="lang-py prettyprint-override"><code>EMBEDDING_DIM = 100
    
embeddings_index = {}
    
f = open(glove_path, encoding='utf-8')  
for line in f:    
    values = line.split()
    word = values[0]
    coefs = np.asarray(values[1:], dtype='float32')
    embeddings_index[word] = coefs
    f.close()
    
print('Found %s word vectors.' % len(embeddings_index))
    
embedding_matrix = np.zeros((len(word_index) + 1, EMBEDDING_DIM))
    
for word, i in word_index.items():
    embedding_vector = embeddings_index.get(word)
    if embedding_vector is not None:
        # words not found in embedding index will be all-zeros.
        embedding_matrix[i] = embedding_vector
</code></pre>
<h3>Layer input of CNN</h3>
<pre class="lang-py prettyprint-override"><code># apply embedding matrix into an Embedding layer
# trainable=False to prevent the weights from being updated during training
embedding_layer = Embedding(len(word_index) + 1,
                            EMBEDDING_DIM,
                            weights=[embedding_matrix],
                            input_length=MAX_SEQUENCE_LENGTH,
                            trainable=False)
</code></pre>
<h3>Training 1D CNN</h3>
<pre class="lang-py prettyprint-override"><code>sequence_input = Input(shape=(MAX_SEQUENCE_LENGTH,), dtype='int32')
embedded_sequences = embedding_layer(sequence_input)

x = Conv1D(128, 5, activation='relu')(embedded_sequences)   
print(&quot;x shape = &quot;, x)

x = MaxPooling1D(5)(x)  
print(&quot;x shape = &quot;, x)
        
x = Conv1D(128, 5, activation='relu')(x)
print(&quot;x shape = &quot;, x)
    
#-----This line below produced error-----
x = MaxPooling1D(5)(x) #Error this line
#-----This line above produced error-----
        
print(&quot;x shape = &quot;, x)

x = Conv1D(128, 5, activation='relu')(x)
print(&quot;x shape = &quot;, x)
    
x = MaxPooling1D(35)(x)  # global max pooling
print(&quot;x shape = &quot;, x)
    
x = Flatten()(x)
x = Dense(128, activation='relu')(x)
    
preds = Dense(len(labels_index), activation='softmax')(x)
model = Model(sequence_input, preds)
model.compile(loss='categorical_crossentropy',
              optimizer='rmsprop',
              metrics=['acc'])
    
# Learning
model.fit(X_train, y_train, validation_data=(X_val, y_val),
          epochs=2, batch_size=128)
</code></pre>
<h3>My ideas</h3>
<p><strong>1) Are there some issues/problems with Glove input?</strong></p>
<p><strong>2) Conv1D:</strong></p>
<ul>
<li>Change the &quot;kernel_size&quot; from 5 to a New Value.</li>
</ul>
<p><strong>3) MaxPooling1D:</strong></p>
<ul>
<li>Change pool_size from 5 to a New Value.</li>
<li>Specify other parameters: strides, padding and so on.</li>
</ul>
<p><strong>4) I currently use keras on tensorflow 2.20 and python 3.6</strong></p>
<ul>
<li>Do I need to upgrade tensorflow and python?</li>
</ul>
<p>However, I could not figure out any better way to do. May I have your suggestions?</p>