class_docstr: A Conv network to generate word embedding from character embeddings, from
  Character-Aware Neural Language Models, https://arxiv.org/abs/1508.06615.
  
  Components include convolutional filters, pooling, and
  optional highway network. We also have the ability to use pretrained ELMo
  which corresponds to the byte embeddings, CNN weights and the highway layer.
class_docstr_tok: ["A","Conv","network","to","generate","word","embedding","from","character","embeddings",",","from","Character-Aware","Neural","Language","Models",",","https",":","\/\/arxiv.org\/abs\/1508.06615",".","Components","include","convolutional","filters",",","pooling",",","and","optional","highway","network",".","We","also","have","the","ability","to","use","pretrained","ELMo","which","corresponds","to","the","byte","embeddings",",","CNN","weights","and","the","highway","layer","."]
code: def __init__(
      self,
      dictionary,
      num_chars=50,
      char_embed_dim=32,
      convolutions_params="((128, 3), (128, 5))",
      nonlinear_fn_type="tanh",
      num_highway_layers=0,
      # A value of -1 for char_cnn_output_dim implies no projection layer
      # layer at the output of the highway network
      char_cnn_output_dim=-1,
      use_pretrained_weights=False,
      finetune_pretrained_weights=False,
      weights_file=None,
  ):
      super().__init__()
      self.dictionary = dictionary
      self.padding_idx = dictionary.pad()
      self.use_pretrained_weights = use_pretrained_weights
  
      self.convolutions_params = convolutions_params
      self.num_highway_layers = num_highway_layers
      self.char_embed_dim = char_embed_dim
      self.num_embeddings = num_chars
      self.char_cnn_output_dim = char_cnn_output_dim
      self.filter_dims = sum(f[0] for f in self.convolutions_params)
  
      # If specified, load the pretrained weights from file
      if use_pretrained_weights:
          self._weight_file = weights_file
          self._finetune_pretrained_weights = (
              finetune_pretrained_weights
          )
          self._load_weights()
      else:
          if nonlinear_fn_type == "tanh":
              nonlinear_fn = nn.Tanh
          elif nonlinear_fn_type == "relu":
              nonlinear_fn = nn.ReLU
          else:
              raise Exception(
                  "Invalid nonlinear type: {}".format(nonlinear_fn_type)
              )
  
          self.embed_chars = rnn.Embedding(
              num_embeddings=num_chars,
              embedding_dim=char_embed_dim,
              padding_idx=self.padding_idx,
              freeze_embed=False,
          )
          self.convolutions = nn.ModuleList(
              [
                  nn.Sequential(
                      nn.Conv1d(
                          char_embed_dim,
                          num_filters,
                          kernel_size,
                          padding=kernel_size,
                      ),
                      nonlinear_fn(),
                  )
                  for (
                      num_filters,
                      kernel_size,
                  ) in self.convolutions_params
              ]
          )
  
          highway_layers = []
          for _ in range(self.num_highway_layers):
              highway_layers.append(HighwayLayer(self.filter_dims))
          self.highway_layers = nn.ModuleList(highway_layers)
  
          if char_cnn_output_dim != -1:
              self.projection = nn.Linear(
                  self.filter_dims, self.char_cnn_output_dim, bias=True
              )
  
imports: import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  from pytorch_translate import common_layers, rnn, utils
  from pytorch_translate.data.dictionary import TAGS
  from torch.nn.utils.rnn import pack_padded_sequence
label_desc: Use image node_id 1 to create a new CharCNNModel object from inherited base classes: nn with example: obj = CharCNNModel(dictionary, num_chars, char_embed_dim, convolutions_params, nonlinear_fn_type, num_highway_layers, char_cnn_output_dim, use_pretrained_weights, finetune_pretrained_weights, weights_file)