class_docstr: Version of fairseq.data.LanguagePairDataset which represents source
  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_source(self, samples) -> Dict[str, Any]:
      # sort in order of descending number of words
      samples.sort(key=lambda s: len(s["source_tokens"]), reverse=True)
      max_words = len(samples[0]["source_tokens"])
  
      id = torch.LongTensor([s["id"] for s in samples])
      src_lengths = torch.LongTensor(
          [len(s["source_tokens"]) for s in samples]
      )
  
      weights = torch.FloatTensor([s["weight"] for s in samples])
  
      word_lengths = torch.LongTensor(len(samples), max_words).fill_(0)
      for i, s in enumerate(samples):
          word_lengths_array = np.array(
              [len(w) for w in s["source_chars_list"]]
          )
          word_lengths[i, : word_lengths_array.size] = torch.LongTensor(
              word_lengths_array
          )
      max_word_length = int(word_lengths.max())
  
      src_tokens = (
          samples[0]["source_tokens"]
          .new(len(samples), max_words)
          .fill_(self.pad_idx)
      )
      for i, s in enumerate(samples):
          src_tokens[i, : len(s["source_tokens"])] = s["source_tokens"]
  
      char_inds = (
          samples[0]["source_chars_list"][0]
          .new(len(samples), max_words, max_word_length)
          .long()
          .fill_(self.pad_idx)
      )
  
      for i, s in enumerate(samples):
          chars_list = s["source_chars_list"]
          for j, chars in enumerate(chars_list):
              char_inds[i, j, : word_lengths[i, j]] = chars
      return {
          "id": id,
          "src_tokens": src_tokens,
          "src_lengths": src_lengths,
          "char_inds": char_inds,
          "word_lengths": word_lengths,
          "weights": weights,
      }
  
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 5 for calling the LanguagePairSourceCharDataset obj's underlying member method code with example usage: obj.collate_source(samples) and returns: dict