Skip to content

Instantly share code, notes, and snippets.

@a-agmon
Last active March 31, 2021 06:22
Show Gist options
  • Save a-agmon/bb032ac769435f653c61d1588f541cbf to your computer and use it in GitHub Desktop.
Save a-agmon/bb032ac769435f653c61d1588f541cbf to your computer and use it in GitHub Desktop.
# a dictionary consisting of K:user and V:mean of the user's items
user_means = {}
for user in list(text_parts.keys()):
# get a list of artists the user listens to
# (but only if we have a vec for it)
artists = [artist for artist in text_parts[user] if model.wv.has_index_for(artist)]
if len(artists) == 0:
continue
# take the mean of all the vectors corresponding
# to the artists the users listened to
artists_mean = np.mean(model.wv[artists], axis=0)
# for each user store the mean of the artists they listen to
user_means[user] = artists_mean
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment