コード例 #1
0
def test_xdeepfm_component_definition(deeprec_resource_path):
    data_path = os.path.join(deeprec_resource_path, "xdeepfm")
    yaml_file = os.path.join(data_path, "xDeepFM.yaml")

    if not os.path.exists(yaml_file):
        download_deeprec_resources(
            "https://recodatasets.z20.web.core.windows.net/deeprec/",
            data_path,
            "xdeepfmresources.zip",
        )

    hparams = prepare_hparams(yaml_file)
    model = XDeepFMModel(hparams, FFMTextIterator)

    assert model.logit is not None
    assert model.update is not None
    assert model.iterator is not None
コード例 #2
0
def test_model_xdeepfm(resource_path):
    data_path = os.path.join(resource_path, '../resources/deeprec/xdeepfm')
    yaml_file = os.path.join(data_path, r'xDeepFM.yaml')
    data_file = os.path.join(data_path, r'sample_FFM_data.txt')
    output_file = os.path.join(data_path, r'output.txt')

    if not os.path.exists(yaml_file):
        download_deeprec_resources(
            r'https://recodatasets.blob.core.windows.net/deeprec/', data_path,
            'xdeepfmresources.zip')

    hparams = prepare_hparams(yaml_file, learning_rate=0.01)
    assert hparams is not None

    input_creator = FFMTextIterator
    model = XDeepFMModel(hparams, input_creator)

    assert model.run_eval(data_file) is not None
    assert isinstance(model.fit(data_file, data_file), BaseModel)
    assert model.predict(data_file, output_file) is not None
コード例 #3
0
def test_model_xdeepfm(deeprec_resource_path):
    data_path = os.path.join(deeprec_resource_path, "xdeepfm")
    yaml_file = os.path.join(data_path, "xDeepFM.yaml")
    data_file = os.path.join(data_path, "sample_FFM_data.txt")
    output_file = os.path.join(data_path, "output.txt")

    if not os.path.exists(yaml_file):
        download_deeprec_resources(
            "https://recodatasets.z20.web.core.windows.net/deeprec/",
            data_path,
            "xdeepfmresources.zip",
        )

    hparams = prepare_hparams(yaml_file, learning_rate=0.01)
    assert hparams is not None

    input_creator = FFMTextIterator
    model = XDeepFMModel(hparams, input_creator)

    assert model.run_eval(data_file) is not None
    assert isinstance(model.fit(data_file, data_file), BaseModel)
    assert model.predict(data_file, output_file) is not None
コード例 #4
0
    download_deeprec_resources(
        r'https://recodatasets.blob.core.windows.net/deeprec/', data_path,
        'xdeepfmresources.zip')

# set hyper-parameters
hparams = prepare_hparams(yaml_file,
                          FEATURE_COUNT=2300000,
                          FIELD_COUNT=39,
                          cross_l2=0.01,
                          embed_l2=0.01,
                          layer_l2=0.01,
                          learning_rate=0.002,
                          batch_size=BATCH_SIZE,
                          epochs=EPOCHS,
                          cross_layer_sizes=[20, 10],
                          init_value=0.1,
                          layer_sizes=[20, 20],
                          use_Linear_part=True,
                          use_CIN_part=True,
                          use_DNN_part=True)

# make model
model = XDeepFMModel(hparams, FFMTextIterator, seed=RANDOM_SEED)

# train model
model.fit(train_file, valid_file)
# profiling
model.train_timeliner.save('xDeepFM-timeliner.json')

# inference after training
#print(model.run_eval(test_file))
コード例 #5
0
hparams = prepare_hparams(yaml_file, 
                          FEATURE_COUNT=1000, 
                          FIELD_COUNT=10, 
                          cross_l2=0.0001, 
                          embed_l2=0.0001, 
                          learning_rate=0.001, 
                          epochs=EPOCHS,
                          batch_size=BATCH_SIZE)
print("Hyper-parameters: ")
print(hparams)
# 2. create data loader
# designate a data iterator for xDeepFM model (FFMTextIterator)
input_creator = FFMTextIterator

# 3. create model
model = XDeepFMModel(hparams, input_creator, seed=RANDOM_SEED)
# we can also load a pre-trained model with model.load_model(r'model_path')

# untrained model's performance
print("Untrained model's performance: {}".format(model.run_eval(test_file)))

# 4. train model
print("Begin model training...")
model.fit(train_file, valid_file)
print("End model training...")

# 5. evaluate model
#res_syn = model.run_eval(test_file)
#print("Trained model's performance: {}".format(res_syn))
#pm.record("rest_syn", res_syn)
# we can also get full prediction scores rather than evaluation metrics with model.predict(test_file, output_file)