Sequential Recommendation for cold-start users with meta transitional learning
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

main.py 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. from trainer import *
  2. from utils import *
  3. from sampler import *
  4. import json
  5. import argparse
  6. def get_params():
  7. args = argparse.ArgumentParser()
  8. args.add_argument("-data", "--dataset", default="electronics", type=str)
  9. args.add_argument("-seed", "--seed", default=None, type=int)
  10. args.add_argument("-K", "--K", default=3, type=int) #NUMBER OF SHOT
  11. args.add_argument("-dim", "--embed_dim", default=100, type=int)
  12. args.add_argument("-bs", "--batch_size", default=1024, type=int)
  13. args.add_argument("-lr", "--learning_rate", default=0.001, type=float)
  14. args.add_argument("-epo", "--epoch", default=100000, type=int)
  15. args.add_argument("-prt_epo", "--print_epoch", default=100, type=int)
  16. args.add_argument("-eval_epo", "--eval_epoch", default=1000, type=int)
  17. args.add_argument("-b", "--beta", default=5, type=float)
  18. args.add_argument("-m", "--margin", default=1, type=float)
  19. args.add_argument("-p", "--dropout_p", default=0.5, type=float)
  20. args.add_argument("-gpu", "--device", default=0, type=int)
  21. args.add_argument("--number_of_neg",default=5,type=int)
  22. args = args.parse_args()
  23. params = {}
  24. for k, v in vars(args).items():
  25. params[k] = v
  26. # params['device'] = torch.device('cuda:'+str(args.device))
  27. params['device'] = args.device
  28. # params['device'] = torch.device('cpu')
  29. return params, args
  30. if __name__ == '__main__':
  31. print(torch.cuda.is_available())
  32. params, args = get_params()
  33. if params['seed'] is not None:
  34. SEED = params['seed']
  35. torch.manual_seed(SEED)
  36. torch.cuda.manual_seed(SEED)
  37. torch.backends.cudnn.deterministic = True
  38. np.random.seed(SEED)
  39. random.seed(SEED)
  40. print("===============", torch.cuda.device_count(), "=======")
  41. user_train, usernum_train, itemnum, user_input_test, user_test, user_input_valid, user_valid = data_load(args.dataset, args.K)
  42. sampler = WarpSampler(user_train, usernum_train, itemnum, batch_size=args.batch_size, maxlen=args.K, n_workers=3,params=params)
  43. sampler_test = DataLoader(user_input_test, user_test, itemnum, params)
  44. sampler_valid = DataLoader(user_input_valid, user_valid, itemnum, params)
  45. print("===============", torch.cuda.device_count(), "=======")
  46. trainer = Trainer([sampler, sampler_valid, sampler_test], itemnum, params)
  47. print("===============", torch.cuda.device_count(), "=======")
  48. trainer.train()
  49. sampler.close()