code: def eval_single(result_file, eval_only_type=None):
      results = {}
      for line in open(result_file):
          row = json.loads(line)
          results[row["question_id"]] = row
  
      type_counts = {}
      correct_counts = {}
      for question_data in data["questions"]:
          if (
              eval_only_type is not None
              and question_data["data_type"] != eval_only_type
          ):
              continue
          data_type = question_data["question_type_id"]
          type_counts[data_type] = type_counts.get(data_type, 0) + 1
          try:
              question_id = int(question_data["question_id"])
          except:
              question_id = question_data["question_id"]
          if question_id not in results:
              correct_counts[data_type] = correct_counts.get(
                  data_type, 0
              )
              continue
          row = results[question_id]
          if row["text"] == question_data["answer"]:
              correct_counts[data_type] = (
                  correct_counts.get(data_type, 0) + 1
              )
  
      total_count = 0
      total_correct = 0
      for data_type in sorted(type_counts.keys()):
          accuracy = (
              correct_counts[data_type] / type_counts[data_type] * 100
          )
          if eval_only_type is None:
              print(
                  f"{ques_type_id_to_name[data_type]}: {accuracy:.2f}%"
              )
  
          total_count += type_counts[data_type]
          total_correct += correct_counts[data_type]
  
      total_accuracy = total_correct / total_count * 100
      if eval_only_type is None:
          print(f"Total accuracy: {total_accuracy:.2f}%")
      else:
          print(f"{eval_only_type} accuracy: {total_accuracy:.2f}%")
  
      return results
  
imports: import os
  import json
  import argparse
label_desc: Use image node_id 2 for calling a global function with example usage: eval_single(result_file, eval_only_type) and returns: results