Created
March 14, 2019 21:43
-
-
Save victorkohler/306637f133531138ed4d6983fdcd3d78 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#------------------ | |
# GRAPH EXECUTION | |
#------------------ | |
# Run the session. | |
session = tf.Session(config=None, graph=graph) | |
session.run(init) | |
# This has noting to do with tensorflow but gives | |
# us a nice progress bar for the training. | |
progress = tqdm(total=batches*epochs) | |
for _ in range(epochs): | |
for _ in range(batches): | |
# We want to sample one known and one unknown | |
# item for each user. | |
# First we sample 15000 uniform indices. | |
idx = np.random.randint(low=0, high=len(uids), size=samples) | |
# We then grab the users matching those indices. | |
batch_u = uids[idx].reshape(-1, 1) | |
# Then the known items for those users. | |
batch_i = iids[idx].reshape(-1, 1) | |
# Lastly we randomly sample one unknown item for each user. | |
batch_j = np.random.randint( | |
low=0, high=len(artists), size=(samples, 1), dtype='int32') | |
# Feed our users, known and unknown items to | |
# our tensorflow graph. | |
feed_dict = { u: batch_u, i: batch_i, j: batch_j } | |
# We run the session. | |
_, l, auc = session.run([step, loss, u_auc], feed_dict) | |
progress.update(batches) | |
progress.set_description('Loss: %.3f | AUC: %.3f' % (l, auc)) | |
progress.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment