code: def reformat_msmarco_dev(
      queries_filename,
      passages_filename,
      qrels_filename,
      top1000_filename,
      output_filename,
  ):
      print("Reformatting MSMarco dev data...")
      top1000_file = open(top1000_filename)
      qrels_file = open(qrels_filename)
      queries_file = open(queries_filename)
      passages_file = open(passages_filename)
  
      # Generate a top1000 dict
      top1000 = dict()
      for l in tqdm(top1000_file):
          qid, pid, _, _ = l.split("\t")
          if qid not in top1000:
              top1000[qid] = []
          top1000[qid].append(pid)
  
      # Generate a qrels dict
      qrels = dict()
      for l in qrels_file:
          qid, _, pid, _ = l.split("\t")
          if qid not in qrels:
              qrels[qid] = []
          qrels[qid].append(pid)
  
      # Generate a queries dict
      queries = dict()
      for l in queries_file:
          qid, query = l.split("\t")
          queries[qid] = query[:-1]
  
      # Generate a passages dict
      passages = dict()
      for l in tqdm(passages_file):
          pid, passage = l.split("\t")
          passages[pid] = passage[:-1]
  
      # Generate dict with all needed info
      final = dict()
      for qid in tqdm(top1000):
          if qid not in final:
              final[qid] = []
          query = queries[qid]
          curr_qrel = qrels[qid]
          curr_top1000 = top1000[qid]
          for ct in curr_top1000:
              is_relevant = int(ct in curr_qrel)
              passage = passages[ct]
              quad = list([query, ct, passage, is_relevant])
              final[qid].append(quad)
  
      # Flatten the structure of final and convert to df
      records = []
      for k, v in tqdm(final.items()):
          for x in v:
              records.append([k] + x)
      df = pd.DataFrame(
          records, columns=["qid", "text", "pid", "text_b", "label"]
      )
      df.to_csv(output_filename, sep="\t", index=None)
      print(f"MSMarco train data saved at {output_filename}")
  
imports: import hashlib
  import json
  import logging
  import random
  import os
  import signal
  import numpy
  import torch
  import torch.distributed
  from requests.exceptions import ConnectionError
  from torch import multiprocessing
  import mlflow
  from copy import deepcopy
  import pandas
  from tqdm import tqdm
  import time
  import pickle
  from farm.visual.ascii.images import WELCOME_BARN, WORKER_M, WORKER_F, WORKER_X
label_desc: Use image node_id 12 for calling a global function with example usage: reformat_msmarco_dev(queries_filename, passages_filename, qrels_filename, top1000_filename, output_filename) without return types