Esempio n. 1
0
        'negative_item_input': negative_item_features
    })['triplet_loss']

    return (loss > 0).mean()


if __name__ == '__main__':

    num_epochs = 5

    # Read data
    train, test = data.get_movielens_data()
    num_users, num_items = train.shape

    # Prepare the test triplets
    test_uid, test_pid, test_nid = data.get_triplets(test)
    test_user_features, test_positive_item_features, test_negative_item_features = data.get_dense_triplets(
        test_uid, test_pid, test_nid, num_users, num_items)

    # Sample triplets from the training data
    uid, pid, nid = data.get_triplets(train)
    user_features, positive_item_features, negative_item_features = data.get_dense_triplets(
        uid, pid, nid, num_users, num_items)

    model = get_graph(num_users, num_items, 256)

    # Print the model structure
    print(model.summary())

    # Sanity check, should be around 0.5
    print('AUC before training %s' % metrics.full_auc(model, test))
    model.compile(loss=identity_loss, optimizer=Adam())

    return model


if __name__ == '__main__':

    latent_dim = 100
    num_epochs = 10

    # Read data
    train, test = data.get_movielens_data()
    num_users, num_items = train.shape

    # Prepare the test triplets
    test_uid, test_pid, test_nid = data.get_triplets(test)

    model = build_model(num_users, num_items, latent_dim)

    # Print the model structure
    print(model.summary())

    # Sanity check, should be around 0.5
    print('AUC before training %s' % metrics.full_auc(model, test))

    for epoch in range(num_epochs):

        print('Epoch %s' % epoch)

        # Sample triplets from the training data
        uid, pid, nid = data.get_triplets(train)
Esempio n. 3
0
from lightfm import LightFM
import data
import sys
import numpy as np

train, test = data.get_movielens_positive_data('/data/sidana/recnet_draft/' +
                                               sys.argv[1] + '/lightfm')
uid_train, pid_train, nid_train = data.get_triplets(train)
uid_test, pid_test, nid_test = data.get_triplets(test)

model = LightFM(no_components=14,
                loss='logistic',
                learning_rate=0.01,
                item_alpha=0.0001,
                user_alpha=0.0001)
model.fit(train, epochs=10, num_threads=1)

train_all, test_all = data.get_movielens_data('/data/sidana/recnet_draft/' +
                                              sys.argv[1] + '/lightfm')
uid_all_train, pid_all_train, nid_all_train = data.get_triplets(train_all)
uid_all_test, pid_all_test, nid_all_test = data.get_triplets(test_all)

export_basename = '/data/sidana/recnet_draft/' + sys.argv[
    1] + '/lightfm_all' + '/vectors/'
export_pred = open(export_basename + 'pr', 'w')
#export_pred = open(export_basename + 'pr', 'w')
export_true = open(export_basename + 'gt', 'w')
#export_true = open(export_basename + 'gt', 'w')

for u in uid_test:
    #num_items_all_test_u = test_all.getrow(u).indices.shape[0]