It’s the requirement of the assignment.
Per batch, the output of the convolutional layer is 64 sentences (batch size) x 50 kernels x # tokens per sentence - 1 x 1. This means that per each kernel, I get a grid of 64 sentences by # tokens per sentence - 1. I want to pick the largest value in each vector of convolutional outputs corresponding to each sentence, however because the sentence length varies per batch I don’t know how to handle this.
The problem is, the batches are of variable width. The width of each batch depends on the sentence of maximum length in each batch (since any sentences that are shorter than the maximum sentence get padded by the BucketIterator). To handle the variable width of the batches, the MaxPool is used to pick out the largest number in each sentence, thereby producing a vector of length of the number of sentences and width of 1.