Пример #1
0
def build_dlrm(emb_dict):
    if 'user' in emb_dict or 'item' in emb_dict:
        emb_list = [emb for _, emb in emb_dict.items()]
        output = MLPInteraction(num_layers=2)(emb_list)
    else:
        sparse_feat_mlp_output = [MLPInteraction()( [emb_dict['sparse']] )] if 'sparse' in emb_dict else []
        dense_feat_mlp_output = [MLPInteraction()( [emb_dict['dense']] )] if 'dense' in emb_dict else []
        output = MLPInteraction(num_layers=2)(sparse_feat_mlp_output + dense_feat_mlp_output)
    return output
Пример #2
0
def test_input_missing():
    input_node1 = Input()
    input_node2 = Input()
    output_node1 = MLPInteraction()(input_node1)
    output_node2 = MLPInteraction()(input_node2)
    output_node = ConcatenateInteraction()([output_node1, output_node2])
    output_node = RatingPredictionOptimizer()(output_node)

    with pytest.raises(ValueError) as info:
        graph_module.HyperGraph(input_node1, output_node)
    assert 'A required input is missing for HyperModel' in str(info.value)
Пример #3
0
def build_autoint(emb_dict):
    if 'user' in emb_dict or 'item' in emb_dict:
        emb_list = [emb for _, emb in emb_dict.items()]
        fm_output = [SelfAttentionInteraction()(emb_list)]
        bottom_mlp_output = [MLPInteraction(num_layers=2)(emb_list)]
        output = MLPInteraction(num_layers=2)(fm_output + bottom_mlp_output)
    else:
        fm_output = [SelfAttentionInteraction()( [emb_dict['sparse']] )] if 'sparse' in emb_dict else []
        bottom_mlp_output = [MLPInteraction()( [emb_dict['dense']] )] if 'dense' in emb_dict else []
        output = MLPInteraction(num_layers=2)(fm_output + bottom_mlp_output)
    return output
Пример #4
0
def test_input_output_disconnect():
    input_node1 = Input()
    output_node = input_node1
    _ = MLPInteraction()(output_node)

    input_node = Input()
    output_node = input_node
    output_node = MLPInteraction()(output_node)
    output_node = RatingPredictionOptimizer()(output_node)

    with pytest.raises(ValueError) as info:
        graph_module.HyperGraph(input_node1, output_node)
    assert 'Inputs and outputs not connected.' in str(info.value)
Пример #5
0
def build_neumf(emb_dict):
    emb_list = [emb for _, emb in emb_dict.items()]
    innerproduct_output = [
        ElementwiseInteraction(elementwise_type="innerporduct")(emb_list)
    ]
    mlp_output = [MLPInteraction(num_layers=2)(emb_list)]
    output = innerproduct_output + mlp_output
    return output
Пример #6
0
def test_graph_basics():
    input_node = Input(shape=(30, ))
    output_node = input_node
    output_node = MLPInteraction()(output_node)
    output_node = RatingPredictionOptimizer()(output_node)

    graph = graph_module.PlainGraph(input_node, output_node)
    model = graph.build_keras_graph().build(hp_module.HyperParameters())
    assert model.input_shape == (None, 30)
    assert model.output_shape == (None, )
Пример #7
0
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
Пример #8
0
def build_neumf(user_num, item_num):
    input = Input(shape=[2])
    user_emb_gmf = LatentFactorMapper(feat_column_id=0,
                                      id_num=user_num,
                                      embedding_dim=64)(input)
    item_emb_gmf = LatentFactorMapper(feat_column_id=1,
                                      id_num=item_num,
                                      embedding_dim=64)(input)
    innerproduct_output = ElementwiseInteraction(
        elementwise_type="innerporduct")([user_emb_gmf, item_emb_gmf])

    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=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
Пример #9
0
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
Пример #10
0
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])

# Step 2.3: Setup optimizer to handle the target task
output = RatingPredictionOptimizer()([innerproduct_output, mlp_output])
model = RPRecommender(inputs=input, outputs=output)

# Step 3: Build the searcher, which provides search algorithm
searcher = Search(model=model,
                  tuner='greedy',  # random, greedy
                  tuner_params={"max_trials": 5, 'overwrite': True}
                  )

# Step 4: Use the searcher to search the recommender
searcher.search(x=[train_X_categorical],
                y=train_y,
                x_val=[val_X_categorical],
Пример #11
0
hash_size = criteo.get_hash_size()

# Step 2: Build the recommender, which provides search space
# Step 2.1: Setup mappers to handle inputs
dense_input_node = Input(shape=[numerical_count])
sparse_input_node = Input(shape=[categorical_count])
dense_feat_emb = DenseFeatureMapper(num_of_fields=numerical_count,
                                    embedding_dim=2)(dense_input_node)
sparse_feat_emb = SparseFeatureMapper(num_of_fields=categorical_count,
                                      hash_size=hash_size,
                                      embedding_dim=2)(sparse_input_node)

# Step 2.2: Setup interactors to handle models
attention_output = SelfAttentionInteraction()(
    [dense_feat_emb, sparse_feat_emb])
bottom_mlp_output = MLPInteraction()([dense_feat_emb])
top_mlp_output = MLPInteraction()([attention_output, bottom_mlp_output])

# Step 2.3: Setup optimizer to handle the target task
output = CTRPredictionOptimizer()(top_mlp_output)
model = CTRRecommender(inputs=[dense_input_node, sparse_input_node],
                       outputs=output)

# Step 3: Build the searcher, which provides search algorithm
searcher = Search(
    model=model,
    tuner='random',
    tuner_params={
        'max_trials': 2,
        'overwrite': True
    },
Пример #12
0
dense_feat_emb = DenseFeatureMapper(num_of_fields=13,
                                    embedding_dim=2)(dense_input_node)

# TODO: preprocess data to get sparse hash_size
sparse_feat_emb = SparseFeatureMapper(num_of_fields=26,
                                      hash_size=[
                                          1444, 555, 175781, 128509, 306, 19,
                                          11931, 630, 4, 93146, 5161, 174835,
                                          3176, 28, 11255, 165206, 11, 4606,
                                          2017, 4, 172322, 18, 16, 56456, 86,
                                          43356
                                      ],
                                      embedding_dim=2)(sparse_input_node)

crossnet_output = CrossNetInteraction()([dense_feat_emb, sparse_feat_emb])
bottom_mlp_output = MLPInteraction()([dense_feat_emb])
top_mlp_output = MLPInteraction()([crossnet_output, bottom_mlp_output])

output = PointWiseOptimizer()(top_mlp_output)
model = CTRRecommender(inputs=[dense_input_node, sparse_input_node],
                       outputs=output)

# AutoML search and predict.
searcher = Search(
    model=model,
    tuner='random',
    tuner_params={
        'max_trials': 2,
        'overwrite': True
    },
)
Пример #13
0
    num_of_fields=13,
    embedding_dim=16)(dense_input_node)

# TODO: preprocess data to get sparse hash_size
sparse_feat_emb = SparseFeatureMapper(
    num_of_fields=26,
    hash_size=[
        1444, 555, 175781, 128509, 306, 19,
        11931, 630, 4, 93146, 5161, 174835,
        3176, 28, 11255, 165206, 11, 4606,
        2017, 4, 172322, 18, 16, 56456,
        86, 43356
    ],
    embedding_dim=16)(sparse_input_node)

sparse_feat_mlp_output = MLPInteraction()([sparse_feat_emb])
dense_feat_mlp_output = MLPInteraction()([dense_feat_emb])
top_mlp_output = MLPInteraction(num_layers=2)([sparse_feat_mlp_output, dense_feat_mlp_output])

output = PointWiseOptimizer()(top_mlp_output)
model = CTRRecommender(inputs=[dense_input_node, sparse_input_node], outputs=output)

# AutoML search and predict.
searcher = Search(model=model,
                  tuner='random',
                  tuner_params={'max_trials': 2, 'overwrite': True},
                  )
searcher.search(x=train_X,
                y=train_y,
                x_val=val_X,
                y_val=val_y,
Пример #14
0
def build_neumf(emb_dict):
    emb_list = [emb for _, emb in emb_dict.items()]
    innerproduct_output = [InnerProductInteraction()(emb_list)]
    mlp_output = [MLPInteraction(num_layers=2)(emb_list)]
    output = innerproduct_output + mlp_output
    return output