code: def test_bleu_computed_correctly(self, device: str):
      self.metric.reset()
  
      # shape: (batch_size, max_sequence_length)
      predictions = torch.tensor(
          [[1, 0, 0], [1, 1, 0], [1, 1, 1]], device=device
      )
  
      # shape: (batch_size, max_gold_sequence_length)
      gold_targets = torch.tensor(
          [[2, 0, 0], [1, 0, 0], [1, 1, 2]], device=device
      )
  
      self.metric(predictions, gold_targets)
  
      assert self.metric._prediction_lengths == 6
      assert self.metric._reference_lengths == 5
  
      # Number of unigrams in predicted sentences that match gold sentences
      # (but not more than maximum occurrence of gold unigram within batch).
      assert self.metric._precision_matches[1] == (
          0
          + 1  # no matches in first sentence.
          + 2  # one clipped match in second sentence.  # two clipped matches in third sentence.
      )
  
      # Total number of predicted unigrams.
      assert self.metric._precision_totals[1] == (1 + 2 + 3)
  
      # Number of bigrams in predicted sentences that match gold sentences
      # (but not more than maximum occurrence of gold bigram within batch).
      assert self.metric._precision_matches[2] == (0 + 0 + 1)
  
      # Total number of predicted bigrams.
      assert self.metric._precision_totals[2] == (0 + 1 + 2)
  
      # Brevity penalty should be 1.0
      assert self.metric._get_brevity_penalty() == 1.0
  
      bleu = self.metric.get_metric(reset=True)["BLEU"]
      check = math.exp(
          0.5 * (math.log(3) - math.log(6))
          + 0.5 * (math.log(1) - math.log(3))
      )
      assert_allclose(bleu, check)
  
file_path: allennlp/tests/training/metrics/bleu_test.py
imports: from typing import Any, Dict, List, Tuple, Union
  import math
  from collections import Counter
  import torch
  from torch.testing import assert_allclose
  from allennlp.common.testing import AllenNlpTestCase, multi_device, global_distributed_metric, run_distributed_test
  from allennlp.training.metrics import BLEU
  from allennlp.training.util import ngrams, get_valid_tokens_mask
label_desc: Use image node_id 4 for calling the BleuTest obj's underlying member method code with example usage: obj.test_bleu_computed_correctly(device) without return types