Beispiel #1
0
                    data_info,
                    embed_size=16,
                    n_epochs=2,
                    lr=1e-4,
                    lr_decay=False,
                    reg=None,
                    batch_size=2048,
                    num_neg=1,
                    use_bn=False,
                    dropout_rate=None,
                    hidden_units="128,64,32",
                    tf_sess_config=None)
    deepfm.fit(train_data,
               verbose=2,
               shuffle=True,
               eval_data=eval_data,
               metrics=[
                   "loss", "balanced_accuracy", "roc_auc", "pr_auc",
                   "precision", "recall", "map", "ndcg"
               ])
    print("prediction: ", deepfm.predict(user=1, item=2333))
    print("recommendation: ", deepfm.recommend_user(user=1, n_rec=7))

    reset_state("AutoInt")
    autoint = AutoInt("ranking",
                      data_info,
                      embed_size=16,
                      n_epochs=2,
                      att_embed_size=(8, 8, 8),
                      num_heads=4,
                      use_residual=False,
                      lr=1e-3,
                    n_epochs=2,
                    lr=1e-4,
                    lr_decay=False,
                    reg=None,
                    batch_size=2048,
                    num_neg=1,
                    use_bn=False,
                    dropout_rate=None,
                    hidden_units="128,64,32",
                    tf_sess_config=None)
    deepfm.fit(train_data,
               verbose=2,
               shuffle=True,
               eval_data=test_data,
               metrics=[
                   "loss", "balanced_accuracy", "roc_auc", "pr_auc",
                   "precision", "recall", "map", "ndcg"
               ],
               eval_batch_size=8192,
               k=10,
               sample_user_num=2048)

    data_info.save(path="model_path")
    deepfm.save(path="model_path",
                model_name="deepfm_model",
                manual=True,
                inference_only=True)

    # =========================== load model ==============================
    print("\n", "=" * 50, " after load model ", "=" * 50)
    tf.reset_default_graph()
    deepfm = DeepFM("rating",
                    data_info,
                    embed_size=16,
                    n_epochs=2,
                    lr=1e-4,
                    lr_decay=False,
                    reg=None,
                    batch_size=2048,
                    num_neg=1,
                    use_bn=False,
                    dropout_rate=None,
                    hidden_units="128,64,32",
                    tf_sess_config=None)
    deepfm.fit(train_data,
               verbose=2,
               shuffle=True,
               eval_data=eval_data,
               metrics=["rmse", "mae", "r2"])
    print("prediction: ", deepfm.predict(user=1, item=2333))
    print("recommendation: ", deepfm.recommend_user(user=1, n_rec=7))

    reset_state("AutoInt")
    autoint = AutoInt("rating",
                      data_info,
                      embed_size=16,
                      n_epochs=2,
                      att_embed_size=(8, 8, 8),
                      num_heads=4,
                      use_residual=False,
                      lr=1e-3,
                      lr_decay=False,