class_docstr: CIDEr scorer.
class_docstr_tok: ["CIDEr","scorer","."]
code: def compute_cider(self, df_mode="corpus"):
      def counts2vec(cnts):
          """
              Function maps counts of ngram to vector of tfidf weights.
              The function returns vec, an array of dictionary that store mapping of n-gram \
                  and tf-idf weights.
              The n-th entry of array denotes length of n-grams.
              :param cnts:
              :return: vec (array of dict), norm (array of float), length (int)
              """
          vec = [defaultdict(float) for _ in range(self.n)]
          length = 0
          norm = [0.0 for _ in range(self.n)]
          for ngram, term_freq in cnts.items():
              # give word count 1 if it doesn't appear in reference corpus
              df = np.log(max(1.0, self.document_frequency[ngram]))
              # ngram index
              n = len(ngram) - 1
              # tf (term_freq) * idf (precomputed idf) for n-grams
              vec[n][ngram] = float(term_freq) * (self.ref_len - df)
              # compute norm for the vector.  the norm will be used for computing similarity
              norm[n] += pow(vec[n][ngram], 2)
  
              if n == 1:
                  length += term_freq
          norm = [np.sqrt(n) for n in norm]
          return vec, norm, length
  
      def sim(
          vec_hyp, vec_ref, norm_hyp, norm_ref, length_hyp, length_ref
      ):
          """
          Compute the cosine similarity of two vectors.
          :param vec_hyp: array of dictionary for vector corresponding to hypothesis
          :param vec_ref: array of dictionary for vector corresponding to reference
          :param norm_hyp: array of float for vector corresponding to hypothesis
          :param norm_ref: array of float for vector corresponding to reference
          :param length_hyp: int containing length of hypothesis
          :param length_ref: int containing length of reference
          :return: array of score for each n-grams cosine similarity
          """
          delta = float(length_hyp - length_ref)
          # measure consine similarity
          val = np.array([0.0 for _ in range(self.n)])
          for n in range(self.n):
              # ngram
              for ngram, _ in vec_hyp[n].items():
                  # vrama91 : added clipping
                  val[n] += (
                      min(vec_hyp[n][ngram], vec_ref[n][ngram])
                      * vec_ref[n][ngram]
                  )
  
              if (norm_hyp[n] != 0) and (norm_ref[n] != 0):
                  val[n] /= norm_hyp[n] * norm_ref[n]
  
              assert not math.isnan(val[n])
              # vrama91: added a length based gaussian penalty
              val[n] *= np.e ** (-(delta**2) / (2 * self.sigma**2))
          return val
  
      # compute log reference length
      if df_mode == "corpus":
          self.ref_len = np.log(float(len(self.crefs)))
  
      scores = []
      for test, refs in zip(self.ctest, self.crefs):
          # compute vector for test captions
          vec, norm, length = counts2vec(test)
          # compute vector for ref captions
          score = np.array([0.0 for _ in range(self.n)])
          for ref in refs:
              vec_ref, norm_ref, length_ref = counts2vec(ref)
              score += sim(
                  vec, vec_ref, norm, norm_ref, length, length_ref
              )
          # change by vrama91 - mean of ngram scores, instead of sum
          score_avg = np.mean(score)
          # divide by number of references
          score_avg /= len(refs)
          # multiply score by 10
          score_avg *= 10.0
          # append score of an image to the score list
          scores.append(score_avg)
      return scores
  
file_path: graph4nlp/graph4nlp/pytorch/modules/evaluation/cider_tool/cider_scorer.py
imports: import copy
  import math
  import os
  import sys
  from collections import defaultdict
  import numpy
label_desc: Use image node_id 7 for calling the CiderScorer obj's underlying member method code with example usage: obj.compute_cider(df_mode) and returns: scores, vec,  norm,  length, val