Exemplo n.º 1
0
def get_predictor(args):
    from neural_networks.update_manager_k import get_update_manager
    from neural_networks.recurrent_layers import get_recurrent_layers
    updater = get_update_manager(args)
    recurrent_layer = get_recurrent_layers(args)

    sequence_noise = get_sequence_noise(args)
    target_selection = get_target_selection(args)

    from neural_networks.rnn_oh_keras import RNNOneHotK

    backend = 'tensorflow'

    return RNNOneHotK(mem_frac=args.mem_frac,
                      backend=backend,
                      max_length=args.max_length,
                      regularization=args.regularization,
                      updater=updater,
                      target_selection=target_selection,
                      sequence_noise=sequence_noise,
                      recurrent_layer=recurrent_layer,
                      batch_size=args.batch_size,
                      active_f=args.act,
                      tying=args.tying,
                      temperature=args.temp,
                      gamma=args.gamma,
                      iter=args.iter,
                      tying_new=args.tying_new,
                      attention=args.att)
Exemplo n.º 2
0
def get_predictor(args):
	args.layers = map(int, args.layers.split('-'))

	updater = get_update_manager(args)
	recurrent_layer = get_recurrent_layers(args)
	sequence_noise = get_sequence_noise(args)
	target_selection = get_target_selection(args)

	if args.method == "MF":
		return Factorization()
	elif args.method == "BPRMF":
		return BPRMF(k=args.hidden, reg = args.regularization, learning_rate = args.learning_rate, annealing=args.cooling, init_sigma = args.init_sigma, adaptive_sampling=(not args.no_adaptive_sampling), sampling_bias=args.fpmc_bias)
	elif args.method == "FISM":
		if args.clusters > 0:
			return FISMCluster(h=args.hidden, reg=args.regularization, alpha=args.fism_alpha, loss=args.loss, interactions_are_unique=(not args.repeated_interactions), predict_with_clusters=(not args.ignore_clusters), sampling_bias=args.sampling_bias, sampling=args.sampling, cluster_sampling=args.c_sampling, init_scale=args.init_scale, scale_growing_rate=args.scale_growing_rate, max_scale=args.max_scale, n_clusters=args.clusters, cluster_type=args.cluster_type, updater=updater, target_selection=target_selection, sequence_noise=sequence_noise, recurrent_layer=recurrent_layer, use_ratings_features=args.rf, use_movies_features=args.mf, use_users_features=args.uf, batch_size=args.batch_size)
		else:
			return FISM(k=args.hidden, reg = args.regularization, learning_rate = args.learning_rate, annealing=args.cooling, init_sigma = args.init_sigma, loss=args.loss, alpha=args.fism_alpha)
	elif args.method == "Fossil":
		return Fossil(k=args.hidden, order=args.fossil_order, reg = args.regularization, learning_rate = args.learning_rate, annealing=args.cooling, init_sigma = args.init_sigma, alpha=args.fism_alpha)
	elif args.method == "FPMC":
		return FPMC(k_cf = args.k_cf, k_mc = args.k_mc, reg = args.regularization, learning_rate = args.learning_rate, annealing=args.cooling, init_sigma = args.init_sigma, adaptive_sampling=(not args.no_adaptive_sampling), sampling_bias=args.fpmc_bias)
	elif args.method == "LTM":
		return LTM(k = args.hidden, alpha = args.ltm_damping, window = args.ltm_window, learning_rate=args.learning_rate, use_trajectory=(not args.ltm_no_trajectory))
	elif args.method == "UKNN":
		return UserKNN(neighborhood_size=args.ns)
	elif args.method == "POP":
		return Pop()
	elif args.method == "MM":
		return MarkovModel()
	elif args.method == 'RNN':
		if args.clusters > 0:
			return RNNCluster(interactions_are_unique=(not args.repeated_interactions), max_length=args.max_length, cluster_selection_noise=args.csn, loss=args.loss, predict_with_clusters=(not args.ignore_clusters), sampling_bias=args.sampling_bias, sampling=args.sampling, cluster_sampling=args.c_sampling, init_scale=args.init_scale, scale_growing_rate=args.scale_growing_rate, max_scale=args.max_scale, n_clusters=args.clusters, cluster_type=args.cluster_type, updater=updater, target_selection=target_selection, sequence_noise=sequence_noise, recurrent_layer=recurrent_layer, use_ratings_features=args.rf, use_movies_features=args.mf, use_users_features=args.uf, batch_size=args.batch_size)
		elif args.loss == 'CCE':
			return RNNOneHot(interactions_are_unique=(not args.repeated_interactions), max_length=args.max_length, diversity_bias=args.diversity_bias, regularization=args.regularization, updater=updater, target_selection=target_selection, sequence_noise=sequence_noise, recurrent_layer=recurrent_layer, use_ratings_features=args.rf, use_movies_features=args.mf, use_users_features=args.uf, batch_size=args.batch_size)
		elif args.loss in ['hinge', 'logit', 'logsig']:
			return RNNMargin(interactions_are_unique=(not args.repeated_interactions), loss_function=args.loss, balance = args.balance, popularity_based = args.pb, min_access = args.min_access, target_selection=target_selection, sequence_noise=sequence_noise, recurrent_layer=recurrent_layer, max_length=args.max_length, updater=updater, use_ratings_features=args.rf, use_movies_features=args.mf, use_users_features=args.uf, batch_size=args.batch_size)
		elif args.loss in ['BPR', 'TOP1', 'Blackout']:
			return RNNSampling(interactions_are_unique=(not args.repeated_interactions), loss_function=args.loss, diversity_bias=args.diversity_bias, sampling=args.sampling, sampling_bias=args.sampling_bias, recurrent_layer=recurrent_layer, max_length=args.max_length, updater=updater, target_selection=target_selection, sequence_noise=sequence_noise, use_ratings_features=args.rf, use_movies_features=args.mf, use_users_features=args.uf, batch_size=args.batch_size)
		else:
			raise ValueError('Unknown loss for the RNN model')
	elif args.method == "SDA":
		return StackedDenoisingAutoencoder(interactions_are_unique=(not args.repeated_interactions), layers = args.layers, input_dropout=args.input_dropout, dropout=args.dropout, updater=updater, batch_size=args.batch_size, use_ratings_features=args.rf)
Exemplo n.º 3
0
def predictor_command_parser(parser):
	parser.add_argument('-m', dest='method', choices=['RNN', 'SDA', 'BPRMF', 'FPMC', 'FISM', 'Fossil', 'LTM', 'UKNN', 'MM', 'POP'],
	 help='Method', default='RNN')
	parser.add_argument('-b', dest='batch_size', help='Batch size', default=16, type=int)
	parser.add_argument('-l', dest='learning_rate', help='Learning rate', default=0.01, type=float)
	parser.add_argument('-r', dest='regularization', help='Regularization (positive for L2, negative for L1)', default=0., type=float)
	parser.add_argument('-g', dest='gradient_clipping', help='Gradient clipping', default=100, type=int)
	parser.add_argument('-H', dest='hidden', help='Number of hidden neurons (for LTM and BPRMF)', default=20, type=int)
	parser.add_argument('-L', dest='layers', help='Layers (for SDA)', default="20", type=str)
	parser.add_argument('--db', dest='diversity_bias', help='Diversity bias (for RNN with CCE, TOP1, BPR or Blackout loss)', default=0.0, type=float)
	parser.add_argument('--rf', help='Use rating features.', action='store_true')
	parser.add_argument('--mf', help='Use movie features.', action='store_true')
	parser.add_argument('--uf', help='Use users features.', action='store_true')
	parser.add_argument('--ns', help='Neighborhood size (for UKNN).', default=80, type=int)
	parser.add_argument('--cooling', help='Simulated annealing', default=1., type=float)
	parser.add_argument('--init_sigma', help='Sigma of the gaussian initialization (for MF)', default=1, type=float
	parser.add_argument('--no_adaptive_sampling', help='No adaptive sampling (for MF)', action='store_true')
	parser.add_argument('--fpmc_bias', help='Sampling bias (for MF)', default=100., type=float)
	parser.add_argument('--ltm_no_trajectory', help='Do not use users trajectory in LTM, just use word2vec', action='store_true')
	parser.add_argument('--max_length', help='Maximum length of sequences during training (for RNNs)', default=30, type=int)
	parser.add_argument('--repeated_interactions', help='The model can recommend items with which the user already interacted', action='store_true')
	update_manager_command_parser(parser)
	recurrent_layers_command_parser(parser)
	sequence_noise_command_parser(parser)
	target_selection_command_parser(parser)

def get_predictor(args):
	args.layers = map(int, args.layers.split('-'))

	updater = get_update_manager(args)
	recurrent_layer = get_recurrent_layers(args)
	sequence_noise = get_sequence_noise(args)
	target_selection = get_target_selection(args)

	if args.method == "MF":
		return BPRMF(k=args.hidden, reg = args.regularization, learning_rate = args.learning_rate, annealing=args.cooling, init_sigma = args.init_sigma, adaptive_sampling=(not args.no_adaptive_sampling), sampling_bias=args.fpmc_bias)
	elif args.method == "UKNN":
		return UserKNN(neighborhood_size=args.ns)
	elif args.method == "MM":
		return MarkovModel()
	elif args.method == 'RNN':
		return RNNOneHot(interactions_are_unique=(not args.repeated_interactions), max_length=args.max_length, diversity_bias=args.diversity_bias, regularization=args.regularization, updater=updater, target_selection=target_selection, sequence_noise=sequence_noise, recurrent_layer=recurrent_layer, use_ratings_features=args.rf, use_movies_features=args.mf, use_users_features=args.uf, batch_size=args.batch_size)
Exemplo n.º 4
0
def get_predictor(args):
    # args.layers = map(int, args.layers.split('-'))

    updater = get_update_manager(args)
    recurrent_layer = get_recurrent_layers(args)
    sequence_noise = get_sequence_noise(args)
    target_selection = get_target_selection(args)

    if args.method == 'RNN':
        if args.clusters > 0:
            return RNNCluster(interactions_are_unique=(not args.repeated_interactions), max_length=args.max_length,
                              cluster_selection_noise=args.csn, loss=args.loss,
                              predict_with_clusters=(not args.ignore_clusters), sampling_bias=args.sampling_bias,
                              sampling=args.sampling, cluster_sampling=args.c_sampling, init_scale=args.init_scale,
                              scale_growing_rate=args.scale_growing_rate, max_scale=args.max_scale,
                              n_clusters=args.clusters, cluster_type=args.cluster_type, updater=updater,
                              target_selection=target_selection, sequence_noise=sequence_noise,
                              recurrent_layer=recurrent_layer, use_ratings_features=args.rf,
                              use_movies_features=args.mf, use_users_features=args.uf, batch_size=args.batch_size)
        elif args.loss == 'CCE':
            return RNNOneHot(interactions_are_unique=(not args.repeated_interactions), max_length=args.max_length,
                             diversity_bias=args.diversity_bias, regularization=args.regularization, updater=updater,
                             target_selection=target_selection, sequence_noise=sequence_noise,
                             recurrent_layer=recurrent_layer, use_ratings_features=args.rf, use_movies_features=args.mf,
                             use_users_features=args.uf, batch_size=args.batch_size)
        elif args.loss in ['hinge', 'logit', 'logsig']:
            return RNNMargin(interactions_are_unique=(not args.repeated_interactions), loss_function=args.loss,
                             balance=args.balance, popularity_based=args.pb, min_access=args.min_access,
                             target_selection=target_selection, sequence_noise=sequence_noise,
                             recurrent_layer=recurrent_layer, max_length=args.max_length, updater=updater,
                             use_ratings_features=args.rf, use_movies_features=args.mf, use_users_features=args.uf,
                             batch_size=args.batch_size)
        elif args.loss in ['BPR', 'TOP1', 'Blackout']:
            return RNNSampling(interactions_are_unique=(not args.repeated_interactions), loss_function=args.loss,
                               diversity_bias=args.diversity_bias, sampling=args.sampling,
                               sampling_bias=args.sampling_bias, recurrent_layer=recurrent_layer,
                               max_length=args.max_length, updater=updater, target_selection=target_selection,
                               sequence_noise=sequence_noise, use_ratings_features=args.rf, use_movies_features=args.mf,
                               use_users_features=args.uf, batch_size=args.batch_size)
        else:
            raise ValueError('Unknown loss for the RNN model')
Exemplo n.º 5
0
def get_predictor(args):

    if args.framework == 'th':
        from neural_networks.update_manager_th import get_update_manager
        from neural_networks.recurrent_layers_th import get_recurrent_layers
        updater = get_update_manager(args)
        recurrent_layer = get_recurrent_layers(args)
    elif args.framework == 'tf':
        from neural_networks.update_manager import get_update_manager
        from neural_networks.recurrent_layers import get_recurrent_layers
        updater = get_update_manager(args)
        recurrent_layer = get_recurrent_layers(args)
    else:
        from neural_networks.update_manager_k import get_update_manager
        from neural_networks.recurrent_layers import get_recurrent_layers
        updater = get_update_manager(args)
        recurrent_layer = get_recurrent_layers(args)

    sequence_noise = get_sequence_noise(args)
    target_selection = get_target_selection(args)

    if args.framework == 'th':
        from neural_networks.rnn_onehot_theano import RNNOneHotTH

        return RNNOneHotTH(max_length=args.max_length,
                           regularization=args.regularization,
                           updater=updater,
                           target_selection=target_selection,
                           sequence_noise=sequence_noise,
                           recurrent_layer=recurrent_layer,
                           batch_size=args.batch_size,
                           active_f=args.act,
                           tying=args.tying,
                           temperature=args.temp,
                           gamma=args.gamma,
                           iter=args.iter,
                           tying_new=args.tying_new,
                           attention=args.att)

    elif args.framework == 'tf':
        from neural_networks.rnn_one_hot import RNNOneHotTF

        return RNNOneHotTF(mem_frac=args.mem_frac,
                           save_log=args.save_log,
                           max_length=args.max_length,
                           regularization=args.regularization,
                           updater=updater,
                           target_selection=target_selection,
                           sequence_noise=sequence_noise,
                           recurrent_layer=recurrent_layer,
                           batch_size=args.batch_size,
                           active_f=args.act,
                           tying=args.tying,
                           temperature=args.temp,
                           gamma=args.gamma,
                           iter=args.iter,
                           tying_new=args.tying_new,
                           attention=args.att)

    if args.framework == 'kth' or args.framework == 'ktf':
        from neural_networks.rnn_oh_keras import RNNOneHotK

        if args.framework == 'kth':
            backend = 'theano'
        else:
            backend = 'tensorflow'

        return RNNOneHotK(mem_frac=args.mem_frac,
                          backend=backend,
                          max_length=args.max_length,
                          regularization=args.regularization,
                          updater=updater,
                          target_selection=target_selection,
                          sequence_noise=sequence_noise,
                          recurrent_layer=recurrent_layer,
                          batch_size=args.batch_size,
                          active_f=args.act,
                          tying=args.tying,
                          temperature=args.temp,
                          gamma=args.gamma,
                          iter=args.iter,
                          tying_new=args.tying_new,
                          attention=args.att)