Skip to content

Instantly share code, notes, and snippets.

@gaphex
Created June 28, 2019 09:54
Show Gist options
  • Save gaphex/03a28de6cf2d882494cd218245df0260 to your computer and use it in GitHub Desktop.
Save gaphex/03a28de6cf2d882494cd218245df0260 to your computer and use it in GitHub Desktop.
def buildMovieRecommender(movie_names, vectorized_plots, top_k=10):
retriever = L2Retriever(vectorized_plots.shape[1], use_norm=True, top_k=top_k, use_gpu=False)
vectorized_norm = np.sum(vectorized_plots**2, axis=1).reshape((-1,1))
def recommend(query):
try:
idx = retriever.predict(vectorized_plots,
vectorized_plots[movie_names.index(query)],
vectorized_norm)[0][1:]
for i in idx:
print(names[i])
except ValueError:
print("{} not found in movie db. Suggestions:")
for i, name in enumerate(movie_names):
if query.lower() in name.lower():
print(i, name)
return recommend
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment