code: def main(cfg):
      cwd = get_original_cwd()
      os.chdir(cwd)
      params = util.Params(cfg.ex_index, cfg.corpus_type)
      setattr(params, "root_path", cwd)
      setattr(
          params,
          "data_dir",
          os.path.join(params.root_path, f"data/{cfg.corpus_type}"),
      )
      setattr(
          params,
          "ex_dir",
          os.path.join(
              params.root_path, f"experiments/ex{cfg.ex_index}"
          ),
      )
      setattr(
          params,
          "model_dir",
          os.path.join(params.root_path, f"model/ex{cfg.ex_index}"),
      )
      setattr(
          params,
          "bert_model_dir",
          os.path.join(
              params.root_path, f"pretrain_models", cfg.pretrain_model
          ),
      )
      setattr(
          params,
          "rel2idx",
          json.load(
              open(
                  os.path.join(params.data_dir, "rel2id.json"),
                  "r",
                  encoding="utf-8",
              )
          )[-1],
      )
      setattr(params, "rel_num", len(params.rel2idx))
      for key, value in cfg.items():
          setattr(params, key, value)
      setattr(params, "restore_file", "last")
  
      ex_params = {
          "corres_threshold": params.corres_threshold,
          "rel_threshold": params.rel_threshold,
          "ensure_corres": params.ensure_corres,
          "ensure_rel": params.ensure_rel,
          "emb_fusion": params.emb_fusion,
      }
  
      torch.cuda.set_device(params.device_id)
      print("current device:", torch.cuda.current_device())
      mode = cfg.mode
      # Set the random seed for reproducible experiments
      random.seed(params.seed)
      torch.manual_seed(params.seed)
      params.seed = params.seed
  
      # Set the logger
      util.set_logger()
  
      # get dataloader
      dataloader = CustomDataLoader(params)
  
      # Define the model
      logging.info("Loading the model...")
      logging.info(
          f"Path: {os.path.join(params.model_dir, params.restore_file)}.pth.tar"
      )
      # Reload weights from the saved file
      model, optimizer = util.load_checkpoint(
          os.path.join(
              params.model_dir, params.restore_file + ".pth.tar"
          )
      )
      model.to(params.device)
      logging.info("- done.")
  
      logging.info("Loading the dataset...")
      loader = dataloader.get_dataloader(
          data_sign=mode, ex_params=ex_params
      )
      logging.info("-done")
  
      logging.info("Starting prediction...")
      _, predictions, ground_truths = evaluate(
          model, loader, params, ex_params, mark=mode
      )
      with open(
          os.path.join(params.data_dir, f"{mode}_triples.json"),
          "r",
          encoding="utf-8",
      ) as f_src:
          src = json.load(f_src)
          df = pd.DataFrame(
              {
                  "text": [sample["text"] for sample in src],
                  "pre": predictions,
                  "truth": ground_truths,
              }
          )
          df.to_csv(os.path.join(params.ex_dir, f"{mode}_result.csv"))
      logging.info("-done")
  
file_path: DeepKE/example/triple/PRGC/predict.py
imports: import json
  import logging
  import random
  import argparse
  from tqdm import tqdm
  import os
  import torch
  import numpy
  import pandas
  import hydra
  from hydra.utils import get_original_cwd
  from deepke.triple_extraction.PRGC import *
label_desc: Use image node_id 4 for calling a global function with example usage: main(cfg) without return types