Skip to content

Instantly share code, notes, and snippets.

View pskrunner14's full-sized avatar

Prabhsimran Singh pskrunner14

View GitHub Profile
@pskrunner14
pskrunner14 / beam_search.py
Last active May 30, 2019 14:40
Beam Search example script from scratch in NumPy
import time
import numpy as np
def topk(a, k):
# idx = a.argsort()[-k:][::-1] # slower (runs in O(n logn) time)
idx = np.argpartition(a, -k)[-k:] # faster (runs in linear O(n) time)
return a[idx], idx
def decode(n):
return np.random.rand(n)