code: def commonsense_reasoning_prediction(model, data_gen):
      """Common part for ReCoRD and RuCoS tasks that gets their predictions in needed format.
  
      Args:
          model: The model itself.
          data_gen: Iterator with data to be submitted.
      """
  
      submission = []
      output = defaultdict(lambda: {"predicted": [], "probability": []})
  
      for x, _ in tqdm(data_gen):
          indices, _, _, entities, _ = x[0]
          prediction = model.compute(x)[:, 1]
          output[indices]["predicted"].append(entities)
          output[indices]["probability"].append(prediction)
  
      for key, value in output.items():
          answer_index = np.argmax(value["probability"])
          answer = value["predicted"][answer_index]
          submission.append(
              {"idx": int(key.split("-")[1]), "label": answer}
          )
      return submission
  
file_path: DeepPavlov/deeppavlov/utils/benchmarks/benchmarks.py
imports: import argparse
  from collections import defaultdict
  from logging import getLogger
  import numpy
  from tqdm import tqdm
  from deeppavlov import build_model
  from deeppavlov.core.commands.train import read_data_by_config, get_iterator_from_config
  from deeppavlov.core.commands.utils import parse_config, expand_path
  from deeppavlov.core.common.file import save_jsonl
label_desc: Use image node_id 4 for calling a global function with example usage: commonsense_reasoning_prediction(model, data_gen) and returns: submission