Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Max over time pooling in Keras

I'm using CNNs in Keras for an NLP task and instead of max pooling, I'm trying to achieve max over time pooling.

Any ideas/hacks on how to achieve this?

What I mean by max over time pooling is to pool the highest value, no matter where they are in the vector

like image 868
bluesummers Avatar asked Jan 31 '17 12:01

bluesummers


People also ask

What is Max over time pooling?

The max-over-time pooling operation is very simple: max_c = max(c) , i.e., it's a single number that gets a max over the whole feature map. The reason to do this, instead of "down-sampling" the sentence like in a CNN, is that in NLP the sentences naturally have different length in a corpus.

What is Max pooling keras?

Max pooling operation for 2D spatial data. Downsamples the input along its spatial dimensions (height and width) by taking the maximum value over an input window (of size defined by pool_size ) for each channel of the input. The window is shifted by strides along each dimension.

Which is better Max pooling or average pooling?

Average pooling method smooths out the image and hence the sharp features may not be identified when this pooling method is used. Max pooling selects the brighter pixels from the image. It is useful when the background of the image is dark and we are interested in only the lighter pixels of the image.

What is the difference between Max pooling and Global Max pooling?

max-pooling layer gave the largest value in a certain subarea as an output, while the global max-pooling did this in the whole area. Figure 4 shows the difference. If MR data adopted global max-pooling, the large number of missing values would be discovered. ...


1 Answers

Assuming that your data shape is (batch_size, seq_len, features) you may apply:

seq_model = Reshape((seq_len * features, 1))(seq_model)
seq_model = GlobalMaxPooling1D()(seq_model)
like image 62
Marcin Możejko Avatar answered Oct 25 '22 03:10

Marcin Możejko