code: def ngram_evaluation_details(data, LM):
      """
      Evaluates the N-gram LM on each sentence in data
  
      Call `ngram_perplexity` with the output of this function to compute the
      perplexity.
  
      Arguments
      ---------
      data : iterator
          An iterator over sentences, where each sentence should be an iterator
          as returned by `speechbrain.lm.counting.ngrams_for_evaluation`
      LM : BackoffNgramLM
          The language model to evaluate
  
      Returns
      -------
      list
          List of `collections.Counter`s which have the keys "num_tokens" and
          "neglogprob", giving the number of tokens and logprob of each sentence
          (in the same order as data).
  
      NOTE
      ----
      The `collections.Counter` cannot add negative numbers. Thus it is important
      to use negative log probabilities (always >=0).
  
      Example
      -------
      >>> class MockLM:
      ...     def __init__(self):
      ...         self.top_order = 3
      ...     def logprob(self, token, context):
      ...         return -1.0
      >>> LM = MockLM()
      >>> data = [[("S", ("<s>",)),
      ...          ("p", ("<s>", "S")),
      ...          ("e", ("S", "p")),
      ...          ("e", ("p", "e")),
      ...          ("c", ("e", "e")),
      ...          ("h", ("e", "c")),
      ...          ("</s>", ("c", "h"))],
      ...         [("B", ("<s>",)),
      ...          ("r", ("<s>", "B")),
      ...          ("a", ("B", "r")),
      ...          ("i", ("r", "a")),
      ...          ("n", ("a", "i")),
      ...          ("</s>", ("i", "n"))]]
      >>> sum(ngram_evaluation_details(data, LM), collections.Counter())
      Counter({'num_tokens': 13, 'neglogprob': 13.0})
  
      """
      details = []
      for sentence in data:
          counter = collections.Counter()
          for token, context in sentence:
              counter["num_tokens"] += 1
              counter["neglogprob"] += -LM.logprob(token, context)
          details.append(counter)
      return details
  
imports: import collections
label_desc: Use image node_id 1 for calling a global function with example usage: ngram_evaluation_details(data, LM) and returns: details