code: def format_cosmosqa(ex, rng):
      true_answer = ex["answer" + str(ex["label"])]
      if "None of the above choices ." in true_answer:
          hard_label = 0
      else:
          assert (
              "None of the above choices" not in true_answer
          ), true_answer
          hard_label = int(rng.random() < 0.5)
      if hard_label:
          answer = true_answer
      else:
          candidate_answers = [ex["answer" + str(i)] for i in range(4)]
          answer = rng.choice(
              [x for x in candidate_answers if x != true_answer]
          )
      txt = f"Context: {ex['context']}\nQuestion: {ex['question']}\nAnswer: {answer}"
      return dict(txt=txt, hard_label=hard_label)
  
file_path: weak-to-strong/weak_to_strong/datasets.py
imports: import functools
  from dataclasses import dataclass
  from random import Random
  from typing import Any, Callable, Optional
  from datasets import Dataset
  from datasets import load_dataset
label_desc: Use image node_id 8 for calling a global function with example usage: format_cosmosqa(ex, rng) and returns: dict