class_docstr: A `CnnEncoder` is a combination of multiple convolution layers and max pooling layers.  As a
  [`Seq2VecEncoder`](./seq2vec_encoder.md), the input to this module is of shape `(batch_size, num_tokens,
  input_dim)`, and the output is of shape `(batch_size, output_dim)`.
  
  The CNN has one convolution layer for each ngram filter size. Each convolution operation gives
  out a vector of size num_filters. The number of times a convolution layer will be used
  is `num_tokens - ngram_size + 1`. The corresponding maxpooling layer aggregates all these
  outputs from the convolution layer and outputs the max.
  
  This operation is repeated for every ngram size passed, and consequently the dimensionality of
  the output after maxpooling is `len(ngram_filter_sizes) * num_filters`.  This then gets
  (optionally) projected down to a lower dimensional output, specified by `output_dim`.
  
  We then use a fully connected layer to project in back to the desired output_dim.  For more
  details, refer to "A Sensitivity Analysis of (and Practitioners’ Guide to) Convolutional Neural
  Networks for Sentence Classification", Zhang and Wallace 2016, particularly Figure 1.
  
  Registered as a `Seq2VecEncoder` with name "cnn".
  
  # Parameters
  
  embedding_dim : `int`, required
      This is the input dimension to the encoder.  We need this because we can't do shape
      inference in pytorch, and we need to know what size filters to construct in the CNN.
  num_filters : `int`, required
      This is the output dim for each convolutional layer, which is the number of "filters"
      learned by that layer.
  ngram_filter_sizes : `Tuple[int]`, optional (default=`(2, 3, 4, 5)`)
      This specifies both the number of convolutional layers we will create and their sizes.  The
      default of `(2, 3, 4, 5)` will have four convolutional layers, corresponding to encoding
      ngrams of size 2 to 5 with some number of filters.
  conv_layer_activation : `Activation`, optional (default=`torch.nn.ReLU`)
      Activation to use after the convolution layers.
  output_dim : `Optional[int]`, optional (default=`None`)
      After doing convolutions and pooling, we'll project the collected features into a vector of
      this size.  If this value is `None`, we will just return the result of the max pooling,
      giving an output of shape `len(ngram_filter_sizes) * num_filters`.
class_docstr_tok: ["A","`","CnnEncoder","`","is","a","combination","of","multiple","convolution","layers","and","max","pooling","layers",".","As","a","[","`","Seq2VecEncoder","`","]","(",".\/seq2vec_encoder.md",")",",","the","input","to","this","module","is","of","shape","`","(","batch_size",",","num_tokens",",","input_dim",")","`",",","and","the","output","is","of","shape","`","(","batch_size",",","output_dim",")","`",".","The","CNN","has","one","convolution","layer","for","each","ngram","filter","size",".","Each","convolution","operation","gives","out","a","vector","of","size","num_filters",".","The","number","of","times","a","convolution","layer","will","be","used","is","`","num_tokens","-","ngram_size","+","1","`",".","The","corresponding","maxpooling","layer","aggregates","all","these","outputs","from","the","convolution","layer","and","outputs","the","max",".","This","operation","is","repeated","for","every","ngram","size","passed",",","and","consequently","the","dimensionality","of","the","output","after","maxpooling","is","`","len","(","ngram_filter_sizes",")","*","num_filters","`",".","This","then","gets","(","optionally",")","projected","down","to","a","lower","dimensional","output",",","specified","by","`","output_dim","`",".","We","then","use","a","fully","connected","layer","to","project","in","back","to","the","desired","output_dim",".","For","more","details",",","refer","to","``","A","Sensitivity","Analysis","of","(","and","Practitioners","\u2019","Guide","to",")","Convolutional","Neural","Networks","for","Sentence","Classification","''",",","Zhang","and","Wallace","2016",",","particularly","Figure","1",".","Registered","as","a","`","Seq2VecEncoder","`","with","name","``","cnn","''",".","#","Parameters","embedding_dim",":","`","int","`",",","required","This","is","the","input","dimension","to","the","encoder",".","We","need","this","because","we","ca","n't","do","shape","inference","in","pytorch",",","and","we","need","to","know","what","size","filters","to","construct","in","the","CNN",".","num_filters",":","`","int","`",",","required","This","is","the","output","dim","for","each","convolutional","layer",",","which","is","the","number","of","``","filters","''","learned","by","that","layer",".","ngram_filter_sizes",":","`","Tuple","[","int","]","`",",","optional","(","default=","`","(","2",",","3",",","4",",","5",")","`",")","This","specifies","both","the","number","of","convolutional","layers","we","will","create","and","their","sizes",".","The","default","of","`","(","2",",","3",",","4",",","5",")","`","will","have","four","convolutional","layers",",","corresponding","to","encoding","ngrams","of","size","2","to","5","with","some","number","of","filters",".","conv_layer_activation",":","`","Activation","`",",","optional","(","default=","`","torch.nn.ReLU","`",")","Activation","to","use","after","the","convolution","layers",".","output_dim",":","`","Optional","[","int","]","`",",","optional","(","default=","`","None","`",")","After","doing","convolutions","and","pooling",",","we","'ll","project","the","collected","features","into","a","vector","of","this","size",".","If","this","value","is","`","None","`",",","we","will","just","return","the","result","of","the","max","pooling",",","giving","an","output","of","shape","`","len","(","ngram_filter_sizes",")","*","num_filters","`","."]
code: def get_output_dim(self) -> int:
      return self._output_dim
  
file_path: allennlp/allennlp/modules/seq2vec_encoders/cnn_encoder.py
imports: from typing import Optional, Tuple
  import torch
  from torch.nn import Conv1d, Linear
  from allennlp.modules.seq2vec_encoders.seq2vec_encoder import Seq2VecEncoder
  from allennlp.nn import Activation
  from allennlp.nn.util import min_value_of_dtype
label_desc: Use image node_id 3 for calling the CnnEncoder obj's underlying member method code with example usage: obj.get_output_dim() and returns: self