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.1KB

3 years ago
3 years ago
3 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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=1, type=int)
  21. args = args.parse_args()
  22. params = {}
  23. for k, v in vars(args).items():
  24. params[k] = v
  25. params['device'] = torch.device('cuda:'+str(args.device))
  26. # params['device'] = torch.device('cpu')
  27. return params, args
  28. if __name__ == '__main__':
  29. params, args = get_params()
  30. if params['seed'] is not None:
  31. SEED = params['seed']
  32. torch.manual_seed(SEED)
  33. torch.cuda.manual_seed(SEED)
  34. torch.backends.cudnn.deterministic = True
  35. np.random.seed(SEED)
  36. random.seed(SEED)
  37. user_train, usernum_train, itemnum, user_input_test, user_test, user_input_valid, user_valid = data_load(args.dataset, args.K)
  38. sampler = WarpSampler(user_train, usernum_train, itemnum, batch_size=args.batch_size, maxlen=args.K, n_workers=3)
  39. sampler_test = DataLoader(user_input_test, user_test, itemnum, params)
  40. sampler_valid = DataLoader(user_input_valid, user_valid, itemnum, params)
  41. trainer = Trainer([sampler, sampler_valid, sampler_test], itemnum, params)
  42. trainer.train()
  43. sampler.close()