Skip to content

Instantly share code, notes, and snippets.

@victorkohler
Last active June 12, 2019 20:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save victorkohler/de8e31ac349550d7110c69ab7109d95f to your computer and use it in GitHub Desktop.
Save victorkohler/de8e31ac349550d7110c69ab7109d95f to your computer and use it in GitHub Desktop.
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