code: def test_caption_bleu4(self):
      path = os.path.join(
          os.path.abspath(__file__),
          "../../../mmf/configs/datasets/coco/defaults.yaml",
      )
      config = load_yaml(os.path.abspath(path))
      captioning_config = config.dataset_config.coco
      caption_processor_config = (
          captioning_config.processors.caption_processor
      )
      vocab_path = os.path.join(
          os.path.abspath(__file__), "..", "..", "data", "vocab.txt"
      )
      caption_processor_config.params.vocab.type = "random"
      caption_processor_config.params.vocab.vocab_file = (
          os.path.abspath(vocab_path)
      )
      caption_processor = CaptionProcessor(
          caption_processor_config.params
      )
      registry.register("coco_caption_processor", caption_processor)
  
      caption_bleu4 = metrics.CaptionBleu4Metric()
      expected = Sample()
      predicted = dict()
  
      # Test complete match
      expected.answers = torch.empty((5, 5, 10))
      expected.answers.fill_(4)
      predicted["scores"] = torch.zeros((5, 10, 19))
      predicted["scores"][:, :, 4] = 1.0
  
      self.assertEqual(
          caption_bleu4.calculate(expected, predicted).item(), 1.0
      )
  
      # Test partial match
      expected.answers = torch.empty((5, 5, 10))
      expected.answers.fill_(4)
      predicted["scores"] = torch.zeros((5, 10, 19))
      predicted["scores"][:, 0:5, 4] = 1.0
      predicted["scores"][:, 5:, 18] = 1.0
  
      self.assertAlmostEqual(
          caption_bleu4.calculate(expected, predicted).item(), 0.3928, 4
      )
  
imports: import os
  import unittest
  import mmf.modules.metrics
  import torch
  from mmf.common.registry import registry
  from mmf.common.sample import Sample
  from mmf.datasets.processors import CaptionProcessor
  from mmf.utils.configuration import load_yaml
label_desc: Use image node_id 1 for calling the TestModuleMetrics obj's underlying member method code with example usage: obj.test_caption_bleu4() without return types