class_docstr: CharLSTM aims to generate character-level embeddings for tokens.
  It summarizes the information of characters in each token to an embedding using a LSTM layer.
  
  Args:
      n_char (int):
          The number of characters.
      n_embed (int):
          The size of each embedding vector as input to LSTM.
      n_out (int):
          The size of each output vector.
      pad_index (int):
          The index of the padding token in the vocabulary. Default: 0.
class_docstr_tok: ["CharLSTM","aims","to","generate","character-level","embeddings","for","tokens",".","It","summarizes","the","information","of","characters","in","each","token","to","an","embedding","using","a","LSTM","layer",".","Args",":","n_char","(","int",")",":","The","number","of","characters",".","n_embed","(","int",")",":","The","size","of","each","embedding","vector","as","input","to","LSTM",".","n_out","(","int",")",":","The","size","of","each","output","vector",".","pad_index","(","int",")",":","The","index","of","the","padding","token","in","the","vocabulary",".","Default",":","0","."]
docstr: Args:
      x (~torch.Tensor): ``[batch_size, seq_len, fix_len]``.
          Characters of all tokens.
          Each token holds no more than `fix_len` characters, and the excess is cut off directly.
  Returns:
      ~torch.Tensor:
          The embeddings of shape ``[batch_size, seq_len, n_out]`` derived from the characters.
docstr_tok: ["Args",":","x","(","~torch.Tensor",")",":","``","[","batch_size",",","seq_len",",","fix_len","]","``",".","Characters","of","all","tokens",".","Each","token","holds","no","more","than","`","fix_len","`","characters",",","and","the","excess","is","cut","off","directly",".","Returns",":","~torch.Tensor",":","The","embeddings","of","shape","``","[","batch_size",",","seq_len",",","n_out","]","``","derived","from","the","characters","."]
code: def forward(self, x):
      r"""
      Args:
          x (~torch.Tensor): ``[batch_size, seq_len, fix_len]``.
              Characters of all tokens.
              Each token holds no more than `fix_len` characters, and the excess is cut off directly.
      Returns:
          ~torch.Tensor:
              The embeddings of shape ``[batch_size, seq_len, n_out]`` derived from the characters.
      """
      # [batch_size, seq_len, fix_len]
      mask = x.ne(self.pad_index)
      # [batch_size, seq_len]
      lens = mask.sum(-1)
      char_mask = lens.gt(0)
  
      # [n, fix_len, n_embed]
      x = self.embed(x[char_mask])
      x = pack_padded_sequence(
          x,
          lengths=lens[char_mask].cpu(),
          batch_first=True,
          enforce_sorted=False,
      )
      x, (h, _) = self.lstm(x)
      # [n, fix_len, n_out]
      h = torch.cat(torch.unbind(h), -1)
      # [batch_size, seq_len, n_out]
      embed = h.new_zeros(*lens.shape, self.n_out)
      embed = embed.masked_scatter_(char_mask.unsqueeze(-1), h)
  
      return embed
  
imports: import torch
  import torch.nn
  from torch.nn.utils.rnn import pack_padded_sequence, PackedSequence
  from torch.nn.modules.rnn import apply_permutation
label_desc: Use image node_id 3 for calling the CharLSTM obj's underlying member method code with example usage: obj.forward(x) and returns: embed