Last active
June 12, 2019 20:42
-
-
Save victorkohler/de8e31ac349550d7110c69ab7109d95f 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
for epoch in range(epochs): | |
# Get our training input. | |
user_input, item_input, labels = get_train_instances() | |
# Generate a list of minibatches. | |
minibatches = random_mini_batches(user_input, item_input, labels) | |
# This has noting to do with tensorflow but gives | |
# us a nice progress bar for the training | |
progress = tqdm(total=len(minibatches)) | |
# Loop over each batch and feed our users, items and labels | |
# into our graph. | |
for minibatch in minibatches: | |
feed_dict = {user: np.array(minibatch[0]).reshape(-1,1), | |
item: np.array(minibatch[1]).reshape(-1,1), | |
label: np.array(minibatch[2]).reshape(-1,1)} | |
# Execute the graph. | |
_, l = session.run([step, loss], feed_dict) | |
# Update the progress | |
progress.update(1) | |
progress.set_description('Epoch: %d - Loss: %.3f' % (epoch+1, l)) | |
progress.close() | |
# Calculate top@K | |
hits = evaluate(df_neg) | |
print(np.array(hits).mean()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment