code: def _negative_sampling_offline(
      instance_input_file,
      valid_file,
      test_file,
      valid_neg_nums=4,
      test_neg_nums=49,
  ):
      columns = ["label", "user_id", "item_id", "timestamp", "cate_id"]
      ns_df = pd.read_csv(instance_input_file, sep="\t", names=columns)
      items_with_popular = list(ns_df["item_id"])
  
      global item2cate
  
      # valid negative sampling
      logger.info("start valid negative sampling")
      with open(valid_file, "r") as f:
          valid_lines = f.readlines()
      write_valid = open(valid_file, "w")
      for line in valid_lines:
          write_valid.write(line)
          words = line.strip().split("\t")
          positive_item = words[2]
          count = 0
          neg_items = set()
          while count < valid_neg_nums:
              neg_item = random.choice(items_with_popular)
              if neg_item == positive_item or neg_item in neg_items:
                  continue
              count += 1
              neg_items.add(neg_item)
              words[0] = "0"
              words[2] = neg_item
              words[3] = item2cate[neg_item]
              write_valid.write("\t".join(words) + "\n")
  
      # test negative sampling
      logger.info("start test negative sampling")
      with open(test_file, "r") as f:
          test_lines = f.readlines()
      write_test = open(test_file, "w")
      for line in test_lines:
          write_test.write(line)
          words = line.strip().split("\t")
          positive_item = words[2]
          count = 0
          neg_items = set()
          while count < test_neg_nums:
              neg_item = random.choice(items_with_popular)
              if neg_item == positive_item or neg_item in neg_items:
                  continue
              count += 1
              neg_items.add(neg_item)
              words[0] = "0"
              words[2] = neg_item
              words[3] = item2cate[neg_item]
              write_test.write("\t".join(words) + "\n")
  
imports: import os
  import shutil
  import pandas
  import gzip
  import random
  import logging
  import _pickle
  from recommenders.utils.constants import SEED
  from recommenders.datasets.download_utils import maybe_download
label_desc: Use image node_id 4 for calling a global function with example usage: _negative_sampling_offline(instance_input_file, valid_file, test_file, valid_neg_nums, test_neg_nums) without return types