Created
June 28, 2019 09:54
-
-
Save gaphex/03a28de6cf2d882494cd218245df0260 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
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