code: def gen_experiment_splits(
      file_Author2ReferencePapers,
      OutFile_dir,
      InFile_paper_feature,
      tag,
      item_ratio=1.0,
      process_num=1,
  ):
      if not os.path.exists(OutFile_dir):
          os.mkdir(OutFile_dir)
  
      user_behavior_file = os.path.join(
          OutFile_dir, "user_history_{0}.txt".format(tag)
      )
      train_file = os.path.join(
          OutFile_dir, "train_{0}.txt".format(tag)
      )
      valid_file = os.path.join(
          OutFile_dir, "valid_{0}.txt".format(tag)
      )
      test_file = os.path.join(OutFile_dir, "test_{0}.txt".format(tag))
  
      item_set = load_has_feature_items(InFile_paper_feature)
      if item_ratio < 1.0:
          _selected_items = random.sample(
              item_set, int(len(item_set) * item_ratio)
          )
          item_set = set(_selected_items)
  
      _min_seq_len = 2
      _min_test_seq_len = 6
      _max_instance_per_user = 20
      train_neg_cnt = 4
      test_neg_cnt = 19
  
      train_samples, valid_samples, test_samples = [], [], []
      item2cnt = {}
      positive_pairs = set()
      print("expanding user behaviors...")
      _cnt = 0
      _t0 = time.time()
      with open(file_Author2ReferencePapers, "r") as rd, open(
          user_behavior_file, "w"
      ) as wt:
          while True:
              line = rd.readline()
              if not line:
                  break
              _cnt += 1
              if _cnt % 1000 == 0:
                  print(
                      "\rprocessing user number : {0}, time elapses: {1:.1f}s".format(
                          _cnt, time.time() - _t0
                      ),
                      end=" ",
                  )
              words = line.strip().split("\t")
              act_items = words[1].split(",")
              act_items = [
                  _item for _item in act_items if _item in item_set
              ]
              act_items_len = len(act_items)
              if act_items_len <= _min_seq_len:
                  continue
              for act_item in act_items:
                  positive_pairs.add((words[0], act_item))
  
              user_behavior = ""
              for i in range(1, act_items_len):
                  if i == 1:
                      user_behavior = act_items[i - 1]
                  else:
                      user_behavior += "," + act_items[i - 1]
  
                  if act_items_len - 2 - _max_instance_per_user > i:
                      continue
  
                  if act_items[i] not in item2cnt:
                      item2cnt[act_items[i]] = 1
                  else:
                      item2cnt[act_items[i]] += 1
  
                  user_tag = "{0}_{1}".format(words[0], i)
                  wt.write("{0} {1}\n".format(user_tag, user_behavior))
                  instance = "{0} {1} {2}%{3}".format(
                      1, user_tag, act_items[i], words[0]
                  )
                  if act_items_len <= _min_test_seq_len:
                      train_samples.append(instance)
                  else:
                      if i == act_items_len - 1:
                          test_samples.append(instance)
                      elif i == act_items_len - 2:
                          valid_samples.append(instance)
                      else:
                          train_samples.append(instance)
      print(
          "done. \nsample number in train / valid / test is {0} / {1} / {2}".format(
              len(train_samples), len(valid_samples), len(test_samples)
          )
      )
  
      random.shuffle(train_samples)
  
      ## only keep items which have features
      item2cnt = {k: v for k, v in item2cnt.items() if k in item_set}
  
      item_list, sample_probs = get_normalized_item_freq(item2cnt)
      print("negative sampling for train...")
      sample_negative_and_write_to_file_wrapper(
          train_file,
          train_samples,
          train_neg_cnt,
          positive_pairs,
          item_list,
          sample_probs,
          process_num=process_num,
      )
      print("negative sampling for validation...")
      sample_negative_and_write_to_file_wrapper(
          valid_file,
          valid_samples,
          train_neg_cnt,
          positive_pairs,
          item_list,
          sample_probs,
          process_num=process_num,
      )
      print("negative sampling for test...")
      sample_negative_and_write_to_file_wrapper(
          test_file,
          test_samples,
          test_neg_cnt,
          positive_pairs,
          item_list,
          sample_probs,
          process_num=process_num,
      )
      print("done.")
  
      dump_dict_as_txt(
          item2cnt, os.path.join(OutFile_dir, "item2freq.tsv")
      )
  
imports: import codecs
  import pickle
  import time
  import os
  from datetime import datetime
  import random
  import numpy
  import math
  from multiprocessing import Process
  from utils.general import *
  from utils.data_helper import *
label_desc: Use image node_id 12 for calling a global function with example usage: gen_experiment_splits(file_Author2ReferencePapers, OutFile_dir, InFile_paper_feature, tag, item_ratio, process_num) without return types