code: def converter(batch, device, max_caption_length=None):
      """Optional preprocessing of the batch before forward pass."""
      pad = max_caption_length is not None
  
      imgs = []
      captions = []
      for img, caption in batch:
          # Preproess the caption by either fixing the length by padding (LSTM)
          # or by simply wrapping each caption in an ndarray (NStepLSTM)
          if pad:
              arr = np.full(max_caption_length, _ignore, dtype=np.int32)
  
              # Clip to max length if necessary
              arr[: len(caption)] = caption[:max_caption_length]
              caption = arr
          else:
              caption = to_device(
                  device, np.asarray(caption, dtype=np.int32)
              )
  
          imgs.append(img)
          captions.append(caption)
  
      if pad:
          captions = to_device(device, np.stack(captions))
      imgs = to_device(device, np.stack(imgs))
  
      return imgs, captions
  
file_path: chainer/examples/image_captioning/datasets.py
imports: from collections import defaultdict
  import os
  import numpy
  from PIL import Image
  from pycocotools.coco import COCO
  from chainer import dataset
  from chainer.dataset.convert import to_device
label_desc: Use image node_id 3 for calling a global function with example usage: converter(batch, device, max_caption_length) and returns: imgs,  captions