def build_gmf(user_num, item_num): input = Input(shape=[2]) user_emb = LatentFactorMapper(column_id=0, num_of_entities=user_num, embedding_dim=64)(input) item_emb = LatentFactorMapper(column_id=1, num_of_entities=item_num, embedding_dim=64)(input) output = InnerProductInteraction()([user_emb, item_emb]) output = RatingPredictionOptimizer()(output) model = RPRecommender(inputs=input, outputs=output) return model
def build_mlp(user_num, item_num): input = Input(shape=[2]) user_emb_mlp = LatentFactorMapper(feat_column_id=0, id_num=user_num, embedding_dim=64)(input) item_emb_mlp = LatentFactorMapper(feat_column_id=1, id_num=user_num, embedding_dim=64)(input) output = MLPInteraction()([user_emb_mlp, item_emb_mlp]) output = RatingPredictionOptimizer()(output) model = RPRecommender(inputs=input, outputs=output) return model
def build_gmf(user_num, item_num): input = Input(shape=[2]) user_emb = LatentFactorMapper(feat_column_id=0, id_num=user_num, embedding_dim=64)(input) item_emb = LatentFactorMapper(feat_column_id=1, id_num=item_num, embedding_dim=64)(input) output = ElementwiseInteraction(elementwise_type="innerporduct")( [user_emb, item_emb]) output = RatingPredictionOptimizer()(output) model = RPRecommender(inputs=input, outputs=output) return model
def build_autorec(user_num, item_num): input = Input(shape=[2]) user_emb_1 = LatentFactorMapper(column_id=0, num_of_entities=user_num, embedding_dim=64)(input) item_emb_1 = LatentFactorMapper(column_id=1, num_of_entities=item_num, embedding_dim=64)(input) user_emb_2 = LatentFactorMapper(column_id=0, num_of_entities=user_num, embedding_dim=64)(input) item_emb_2 = LatentFactorMapper(column_id=1, num_of_entities=item_num, embedding_dim=64)(input) output = HyperInteraction()( [user_emb_1, item_emb_1, user_emb_2, item_emb_2]) output = RatingPredictionOptimizer()(output) model = RPRecommender(inputs=input, outputs=output) return model
def build_neumf(user_num, item_num): input = Input(shape=[2]) user_emb_gmf = LatentFactorMapper(column_id=0, num_of_entities=user_num, embedding_dim=64)(input) item_emb_gmf = LatentFactorMapper(column_id=1, num_of_entities=item_num, embedding_dim=64)(input) innerproduct_output = InnerProductInteraction()( [user_emb_gmf, item_emb_gmf]) user_emb_mlp = LatentFactorMapper(column_id=0, num_of_entities=user_num, embedding_dim=64)(input) item_emb_mlp = LatentFactorMapper(column_id=1, num_of_entities=item_num, embedding_dim=64)(input) mlp_output = MLPInteraction()([user_emb_mlp, item_emb_mlp]) output = RatingPredictionOptimizer()([innerproduct_output, mlp_output]) model = RPRecommender(inputs=input, outputs=output) return model
# dataset_paths = ["./examples/datasets/netflix-prize-data/combined_data_" + str(i) + ".txt" for i in range(1, 5)] # data = NetflixPrizePreprocessor(dataset_paths) # Step 1: Preprocess data movielens = MovielensPreprocessor() train_X, train_y, val_X, val_y, test_X, test_y = movielens.preprocess() train_X_categorical = movielens.get_x_categorical(train_X) val_X_categorical = movielens.get_x_categorical(val_X) test_X_categorical = movielens.get_x_categorical(test_X) user_num, item_num = movielens.get_hash_size() # Step 2: Build the recommender, which provides search space # Step 2.1: Setup mappers to handle inputs input = Input(shape=[2]) user_emb_gmf = LatentFactorMapper(column_id=0, num_of_entities=user_num, embedding_dim=64)(input) item_emb_gmf = LatentFactorMapper(column_id=1, num_of_entities=item_num, embedding_dim=64)(input) user_emb_mlp = LatentFactorMapper(column_id=0, num_of_entities=user_num, embedding_dim=64)(input) item_emb_mlp = LatentFactorMapper(column_id=1, num_of_entities=item_num, embedding_dim=64)(input) # Step 2.2: Setup interactors to handle models innerproduct_output = InnerProductInteraction()([user_emb_gmf, item_emb_gmf]) mlp_output = MLPInteraction()([user_emb_mlp, item_emb_mlp])
level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s') logging.basicConfig( level=logging.DEBUG, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s') logger = logging.getLogger(__name__) # load dataset ml_1m = MovielensCTRPreprocessor("./examples/datasets/ml-1m/ratings.dat") ml_1m.preprocessing(test_size=0.1, random_state=1314, num_neg=10, mult=2) train_X, train_y, val_X, val_y = ml_1m.train_X, ml_1m.train_y, ml_1m.val_X, ml_1m.val_y # build the pipeline. input = Input(shape=[2]) user_emb_gmf = LatentFactorMapper(feat_column_id=0, id_num=10000, embedding_dim=64)(input) item_emb_gmf = LatentFactorMapper(feat_column_id=1, id_num=10000, embedding_dim=64)(input) user_emb_mlp = LatentFactorMapper(feat_column_id=0, id_num=10000, embedding_dim=64)(input) item_emb_mlp = LatentFactorMapper(feat_column_id=1, id_num=10000, embedding_dim=64)(input) innerproduct_output = ElementwiseInteraction(elementwise_type="innerporduct")( [user_emb_gmf, item_emb_gmf]) mlp_output = MLPInteraction()([user_emb_mlp, item_emb_mlp]) output = PointWiseOptimizer()([innerproduct_output, mlp_output])
test_X, test_y = data.test_X, data.test_y user_num, item_num = data.user_num, data.item_num logger.info('train_X size: {}'.format(train_X.shape)) logger.info('train_y size: {}'.format(train_y.shape)) logger.info('val_X size: {}'.format(val_X.shape)) logger.info('val_y size: {}'.format(val_y.shape)) logger.info('test_X size: {}'.format(test_X.shape)) logger.info('test_y size: {}'.format(test_y.shape)) logger.info('user total number: {}'.format(user_num)) logger.info('item total number: {}'.format(item_num)) # build the pipeline. input = Input(shape=[2]) user_emb = LatentFactorMapper(feat_column_id=0, id_num=user_num, embedding_dim=64)(input) item_emb = LatentFactorMapper(feat_column_id=1, id_num=item_num, embedding_dim=64)(input) output1 = HyperInteraction()([user_emb, item_emb]) output2 = HyperInteraction()([output1, user_emb, item_emb]) output3 = HyperInteraction()([output1, output2, user_emb, item_emb]) output4 = HyperInteraction()([output1, output2, output3, user_emb, item_emb]) output = RatingPredictionOptimizer()(output4) model = RPRecommender(inputs=input, outputs=output) # AutoML search and predict. searcher = Search(model=model, tuner='random', ## hyperband, bayesian tuner_params={'max_trials': 100, 'overwrite': True},)