class_docstr: Version of fairseq.data.LanguagePairDataset which represents source
  and target sentences as sequences of words, each represented as a
  sequence of characters (with numberized indices for both words and
  characters).
  Right-padded only.
code: def collate_tgt_chars(self, samples) -> Dict[str, Any]:
      max_tgt_words = max(len(s["target"]) for s in samples)
      tgt_word_lengths = torch.LongTensor(
          len(samples), max_tgt_words
      ).fill_(0)
      for i, s in enumerate(samples):
          word_lengths_array = np.array(
              [len(w) for w in s["target_chars_list"]]
          )
          tgt_word_lengths[
              i, : word_lengths_array.size
          ] = torch.LongTensor(word_lengths_array)
      max_tgt_word_length = int(tgt_word_lengths.max())
  
      tgt_char_inds = (
          samples[0]["target_chars_list"][0]
          .new(len(samples), max_tgt_words, max_tgt_word_length)
          .long()
          .fill_(self.pad_idx)
      )
      prev_tgt_char_inds = (
          samples[0]["target_chars_list"][0]
          .new(len(samples), max_tgt_words, max_tgt_word_length)
          .long()
          .fill_(self.pad_idx)
      )
      eos_tensor = torch.tensor([self.eos_idx])
      for i, s in enumerate(samples):
          chars_list = s["target_chars_list"]
          prev_tgt_char_inds[i, 0, :1] = eos_tensor
          for j, chars in enumerate(chars_list):
              tgt_char_inds[i, j, : tgt_word_lengths[i, j]] = chars
              if j < prev_tgt_char_inds.size()[1] - 1:
                  # We skip previous characters for the last word.
                  prev_tgt_char_inds[
                      i, j + 1, : tgt_word_lengths[i, j]
                  ] = chars
  
      prev_tgt_word_lengths = torch.cat(
          (
              torch.ones((len(samples), 1), dtype=torch.long),
              tgt_word_lengths,
          ),
          dim=1,
      )
  
      return {
          "prev_tgt_char_inds": prev_tgt_char_inds,
          "tgt_char_inds": tgt_char_inds,
          "tgt_word_lengths": tgt_word_lengths,
          "prev_tgt_word_lengths": prev_tgt_word_lengths,
      }
  
imports: from typing import Any, Dict
  import numpy
  import torch
  from fairseq import data, tokenizer
  from fvcore.common.file_io import PathManager
  from pytorch_translate import vocab_constants
  from pytorch_translate.data.dictionary import TAGS
label_desc: Use image node_id 3 for calling the LanguagePairCharDataset obj's underlying member method code with example usage: obj.collate_tgt_chars(samples) and returns: dict