code: def test_ngrams(self, device: str):
      tensor = torch.tensor([1, 2, 3, 1, 2, 0], device=device)
  
      exclude_indices = self.metric._exclude_indices
  
      # Unigrams.
      counts: Counter = Counter(ngrams(tensor, 1, exclude_indices))
      unigram_check = {(1,): 2, (2,): 2, (3,): 1}
      assert counts == unigram_check
  
      # Bigrams.
      counts = Counter(ngrams(tensor, 2, exclude_indices))
      bigram_check = {(1, 2): 2, (2, 3): 1, (3, 1): 1}
      assert counts == bigram_check
  
      # Trigrams.
      counts = Counter(ngrams(tensor, 3, exclude_indices))
      trigram_check = {(1, 2, 3): 1, (2, 3, 1): 1, (3, 1, 2): 1}
      assert counts == trigram_check
  
      # ngram size too big, no ngrams produced.
      counts = Counter(ngrams(tensor, 7, exclude_indices))
      assert counts == {}
  
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 3 for calling the BleuTest obj's underlying member method code with example usage: obj.test_ngrams(device) without return types