code: def __init__(
      self,
      embedding_dim,
      num_filters,
      ngram_filter_sizes=(2, 3, 4, 5),  # pylint: disable=bad-whitespace
      conv_layer_activation=None,
      output_dim=None,
  ):
      super(CnnEncoder, self).__init__()
      self._embedding_dim = embedding_dim
      self._num_filters = num_filters
      self._ngram_filter_sizes = ngram_filter_sizes
      self._activation = (
          conv_layer_activation or Activation.by_name("relu")()
      )
      self._output_dim = output_dim
  
      self._convolution_layers = [
          Conv1d(
              in_channels=self._embedding_dim,
              out_channels=self._num_filters,
              kernel_size=ngram_size,
          )
          for ngram_size in self._ngram_filter_sizes
      ]
      for i, conv_layer in enumerate(self._convolution_layers):
          self.add_module("conv_layer_%d" % i, conv_layer)
  
      maxpool_output_dim = self._num_filters * len(
          self._ngram_filter_sizes
      )
      if self._output_dim:
          self.projection_layer = Linear(
              maxpool_output_dim, self._output_dim
          )
      else:
          self.projection_layer = None
          self._output_dim = maxpool_output_dim
  
file_path: magnitude/pymagnitude/third_party/allennlp/modules/seq2vec_encoders/cnn_encoder.py
imports: from __future__ import absolute_import
  import torch
  from torch.nn import Conv1d, Linear
  from allennlp.modules.seq2vec_encoders.seq2vec_encoder import Seq2VecEncoder
  from allennlp.nn import Activation
label_desc: Use image node_id 1 to create a new CnnEncoder object from inherited base classes: Seq2VecEncoder with example: obj = CnnEncoder(embedding_dim, num_filters, ngram_filter_sizes, conv_layer_activation, output_dim)