Skip to content

Instantly share code, notes, and snippets.

View kedarbellare's full-sized avatar

Kedar Bellare kedarbellare

View GitHub Profile
@kedarbellare
kedarbellare / flare bilstm CLI output
Created December 21, 2017 16:03
Output of training a bilstm model on movie review sentiment data using GloVe vectors
$ lein with-profile main-sentclass run --model-type bilstm --num-data 8000 --embed-file data/glove.6B.300d.txt --emb-size 300
Reflection warning, /private/var/folders/cg/mm4fc_4j3_96tm1fpqkm4v5w0000gn/T/form-init2811519414259970652.clj:1:1201 - call to static method invokeStaticMethod on clojure.lang.Reflector can't be resolved (argument types: unknown, java.lang.String, unknown).
WARNING: any? already refers to: #'clojure.core/any? in namespace: vertigo.core, being replaced by: #'vertigo.core/any?
{:train-file data/sentiment-train10k.txt, :test-file data/sentiment-test10k.txt, :embed-file data/glove.6B.300d.txt, :num-classes 2, :emb-size 300, :model-type :bilstm, :lstm-size 25, :num-data 8000}
Params ([lstm/input->gates/b [200]] [hidden->logits/W [2 50]] [lstm/input->gates/W [200 650]] [hidden->logits/b [2]])
Total # params 130302
Optimizing with flare.optimize.Adadelta
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See
import sys
# HACK: keras prints to stdout which messes with halite
stdout = sys.stdout
stderr = sys.stderr
sys.stdout = open('/dev/null', 'w')
sys.stderr = open('/dev/null', 'w')
from keras import models
from keras.callbacks import ModelCheckpoint
@kedarbellare
kedarbellare / dijkstra.py
Created August 7, 2012 00:36
Fast dijkstra
import csv
import heapq
from random import randint
# no heapq implementation
def up_heapify(length, P, L, i):
idx, ix = L[i]
while i:
pi = (i-1) >> 1 #(i-1)/2
pidx, pix = L[pi]
@kedarbellare
kedarbellare / dijkstra_fast.py
Created August 1, 2012 22:43
dijkstra implementations
import heapq
import csv
# no heapq implementation
def up_heapify(L, i):
while i:
pi = (i-1)/2
if L[pi] > L[i]:
L[i], L[pi] = L[pi], L[i]
i = pi
@kedarbellare
kedarbellare / rps.py
Created July 24, 2012 06:59
Rock paper scissors
def match(player1, player2):
moves1 = []
moves2 = []
wins1 = 0
wins2 = 0
for i in xrange(1000):
move1 = player1(moves1, moves2)
move2 = player2(moves2, moves1)
#print move1, move2
moves1.append(move1)
@kedarbellare
kedarbellare / sage_terminal_velocity.py
Created July 22, 2012 21:41
Sage (terminal velocity of different objects)
## Credits:
##
## Collaborative effort:
## - Michel Dusseault wrote the code.
## - I worked out some of the differential equations.
##
var('t')
g = 9.81 # m/s^2
rho = 1.2 # Rho: Density of air at sea level @ 25C
@kedarbellare
kedarbellare / pdf_fuzz.py
Created July 20, 2012 02:26
PDF Fuzzer
file_list = ["10.1.1.111.1781.pdf", "10.1.1.111.5264.pdf", "10.1.1.39.1596.pdf", "10.1.1.41.8589.pdf", "10.1.1.42.5619.pdf"]
apps = [
"/Applications/Adobe Reader 9/Adobe Reader.app/Contents/MacOS/AdobeReader",
"/Applications/Adobe Reader.app/Contents/MacOS/AdobeReader",
"/Applications/Preview.app/Contents/MacOS/Preview"]
fuzz_output = "fuzz.pdf"
FuzzFactor = 250
@kedarbellare
kedarbellare / centrality.py
Created July 18, 2012 03:11
Finding the max and average centrality in a graph
#
# Write centrality_max to return the maximum distance
# from a node to all the other nodes it can reach
#
from collections import deque
def centrality_max(G, v):
open_list = deque([v])
distance = {v: 0}
@kedarbellare
kedarbellare / sudoku_utils.py
Created July 13, 2012 14:37
Utility for sudoku
## Tests
import time, random
def from_file(filename, sep='\n'):
"Parse a file into a list of strings, separated by sep."
return file(filename).read().strip().split(sep)
def parse_grid(gridstr):
gridstr = gridstr.replace('\n', '')
return [[int(gridstr[i+9*j]) for i in range(9)] for j in range(9)]
@kedarbellare
kedarbellare / sudoku_solve.py
Created July 13, 2012 13:57
Sudoku solver/checker
def times(A, B):
return [(i,j) for i in A for j in B]
dims = range(9)
subdims = ([0,1,2],[3,4,5],[6,7,8])
squares = times(dims, dims)
unitlist = ([times(dims, [c]) for c in dims] +
[times([r], dims) for r in dims] +
[times(rs, cs) for rs in subdims for cs in subdims])
units = dict((s, [u for u in unitlist if s in u])