Skip to content

Instantly share code, notes, and snippets.

@BalazsHoranyi
Last active June 15, 2018 21:13
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 BalazsHoranyi/ebded76128fcb8e77efb53dead093ec2 to your computer and use it in GitHub Desktop.
Save BalazsHoranyi/ebded76128fcb8e77efb53dead093ec2 to your computer and use it in GitHub Desktop.
from github import Github
import itertools
import numpy as np
user_id='BalazsHoranyi' # hardcoded for demo purposes
def get_github_events(user_name):
github_token = "superdupersecret"
urls = [f'https://api.github.com/users/{user_name}/events?page={i}&access_token={github_token}' for i in range(11)]
headers = {}
headers['Authorization'] = f'token {github_token}'
with FuturesSession(max_workers=4) as session:
futures = [session.get(u, headers=headers) for u in urls]
rs = [f.result() for f in futures]
if rs[0].status_code == 404:
return None
rs = [r.json() for r in rs]
rs = [item for sublist in rs for item in sublist]
repo_names = [repo['repo']['name'] for repo in rs]
return repo_names
repos = get_github_events(user_id)
total_item_embeddings = np.zeros(32)
count = 0
for repo_name in repos:
item_id = name_id_norm.get(repo_name, -1) + 1
item_embedding = item_embedding_map.get(item_id, np.zeros(32))
if item_id > 0:
count += 1
seq_to_predict.append(item_id)
repo_names.append(repo_name)
total_item_embeddings += item_embedding
avg_item_embeddings = total_item_embeddings / count
seq_to_predict = seq_to_predict[::-1]
repo_names = repo_names[::-1]
print(f'user interacted with {repo_names}')
seq_to_predict = seq_to_predict[::-1] # oldest first
repo_names = repo_names[::-1] . # what the user has already interacted with
# Generate Candidates
candidate_ind = np.array(t.get_nns_by_vector(avg_item_embeddings, 1000))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment