Skip to content

Instantly share code, notes, and snippets.

View santhoshhari's full-sized avatar

Sri Santhosh Hari santhoshhari

  • San Francisco
View GitHub Profile
class LSH:
def __init__(self, num_tables, hash_size, inp_dimensions):
self.num_tables = num_tables
self.hash_size = hash_size
self.inp_dimensions = inp_dimensions
self.hash_tables = list()
for i in range(self.num_tables):
self.hash_tables.append(HashTable(self.hash_size, self.inp_dimensions))
def __setitem__(self, inp_vec, label):
import numpy as np
class HashTable:
def __init__(self, hash_size, inp_dimensions):
self.hash_size = hash_size
self.inp_dimensions = inp_dimensions
self.hash_table = dict()
self.projections = np.random.randn(self.hash_size, inp_dimensions)
def generate_hash(self, inp_vector):
import asyncio
import aiohttp
import requests
async def fetch_url(session, url):
async with session.get(url, timeout=60 * 60) as response:
return await response.text()
async def fetch_all_urls(session, urls, loop):
results = await asyncio.gather(*[fetch_url(session, url) for url in urls],