code: def _ngram_counts(
      char_or_word_list: List[str], n_gram_order: int
  ) -> Dict[int, Dict[Tuple[str, ...], Tensor]]:
      """Calculate n-gram counts.
  
      Args:
          char_or_word_list: A list of characters of words
          n_gram_order: The largest number of n-gram.
  
      Return:
          A dictionary of dictionaries with a counts of given n-grams.
  
      """
      ngrams: Dict[int, Dict[Tuple[str, ...], Tensor]] = defaultdict(
          lambda: defaultdict(lambda: tensor(0.0))
      )
      for n in range(1, n_gram_order + 1):
          for ngram in (
              tuple(char_or_word_list[i : i + n])
              for i in range(len(char_or_word_list) - n + 1)
          ):
              ngrams[n][ngram] += tensor(1)
      return ngrams
  
file_path: torchmetrics/src/torchmetrics/functional/text/chrf.py
imports: from collections import defaultdict
  from typing import Dict, List, Optional, Sequence, Tuple, Union
  import torch
  from torch import Tensor, tensor
  from torchmetrics.functional.text.helper import _validate_inputs
label_desc: Use image node_id 5 for calling a global function with example usage: _ngram_counts(char_or_word_list, n_gram_order) and returns: ngrams