code: def calculate_scores_form_logprobs(logprobs: Dict[str, Any]) -> float:
      """
      Calculate the score according to log probabilities returned by text-davinci-003.
  
      Calculation formula:
          score = sum(score_i * exp(value)) where score_i is the score which corresponds to the key(predicted token) and value is its log probability.
  
      Ref: https://arxiv.org/abs/2303.16634
      This paper proposes NLG evaluation methods using text-davinci-003(log probabilities returned by completion models) and GPT-4(probabilities obtained by sampling).
  
      Args:
          logprobs: logprobs returned by openai.Completion.
  
      Returns:
          The score of one answer.
      """
  
      # GPT-3.5 only returns score of 1 to 5.
      prob = np.zeros(5)
  
      for key, value in logprobs.items():
          # Sometimes the key will be one byte of a unicode character which takes the form of "bytes:\\xe7".
          # It is meaningless and thus we don't calculate probability.
          if "bytes" in key:
              continue
          # results[0] is the score which corresponds to the key(predicted token).
          # For example, key "5" corresponds to score 5.
          results = re.findall(r"\d", key)
          if len(results) == 1:
              prob[int(results[0]) - 1] = prob[
                  int(results[0]) - 1
              ] + np.exp(value)
  
      score = np.dot(np.arange(1, 6), prob)
  
      return score
  
imports: import concurrent.futures
  import os
  import re
  import time
  from copy import deepcopy
  from typing import Any, Dict, List
  import matplotlib.pyplot
  import numpy
  import openai
  import pandas
  import seaborn
  import tqdm
  from colossal_eval.utils import jdump, jload
label_desc: Use image node_id 11 for calling a global function with example usage: calculate_scores_form_logprobs(logprobs) and returns: score