This file contains 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
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): |
This file contains 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
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): |
This file contains 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
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], |