Skip to content

Instantly share code, notes, and snippets.

Avatar

Christopher Fox cdfox

View GitHub Profile
@cdfox
cdfox / reproduce_roblox_distilbert.py
Last active Aug 9, 2020
Reproducing Roblox DistilBERT Medium Post
View reproduce_roblox_distilbert.py
# Reproducing Roblox DistilBERT Medium Post
# https://blog.roblox.com/2020/05/scaled-bert-serve-1-billion-daily-requests-cpus/
#
# 1. Launch C5 12xlarge with Deep Learning AMI (Ubuntu 18.04) Version 32.0 (ami-0dc2264cd927ca9eb)
# 2. pip install transformers[torch]
# 3. python reproduce_roblox_distilbert.py
import timeit
from transformers import DistilBertTokenizerFast, \
DistilBertForSequenceClassification
View tuple_equality.py
class foo:
def __eq__(self, o):
return False
t = (foo(),)
t2 = (t[0],)
t == t2 # True
t[0] == t2[0] # False
t[0] is t2[0] # True
View out_of_memory_in_web_server.go
package main
import (
"fmt"
"log"
"net/http"
)
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
@cdfox
cdfox / numba_lda.py
Last active Aug 29, 2015
Gibbs sampling for latent Dirichlet allocation using Numba.
View numba_lda.py
import re
import sys
import numpy as np
import numba
file_name = sys.argv[1] # one document per line
num_topics = int(sys.argv[2])
num_iterations = int(sys.argv[3])
alpha = float(sys.argv[4])
alpha0 = float(sys.argv[5])
View sqrt_floating_point.py
import math
def sqrt(x, high, low, e):
mid = (high + low) / 2.0
square = mid * mid
if (square >= x and square - x <= e) or (square < x and x - square <= e):
return mid
elif square > x:
return sqrt(x, high, mid, e)
else:
@cdfox
cdfox / gist:6857081
Created Oct 6, 2013
Counting the possible orderings of distinct elements [a,b,c,d,e,f] given that a < d, b < e, c < b, c < f, d < f, d < e.
View gist:6857081
from itertools import permutations
perms = permutations(range(6))
def check(p):
i1 = p.index(0) < p.index(3)
i2 = p.index(1) < p.index(4)
i3 = p.index(2) < p.index(1)
i4 = p.index(2) < p.index(5)
i5 = p.index(3) < p.index(4)
@cdfox
cdfox / preprocess.go
Last active Dec 15, 2015
Preprocess a set of documents, one on each line of the input file, for LDA inference.
View preprocess.go
// For each line of the input file, remove nonalphanumeric characters,
// lowercase all letters, remove stopwords, and write the result to the output
// file. I used the answer here as a template for reading/writing files:
// http://stackoverflow.com/questions/1821811/how-to-read-write-from-to-file/9739903#9739903
package main
import (
"bufio"
"fmt"
View gist:2910560
sentences = [s for rev in reviews for s in rev.split(".")]
View gist:2830517
print 'hello world'
@cdfox
cdfox / gist:2560930
Created Apr 30, 2012
Using the Requests library
View gist:2560930
import requests
import codecs
url = 'http://www.instapaper.com/m'
params = {'u': 'http://techcrunch.com/2012/04/30/bn-8-k-microsoft-paying-180m-advance-on-nook-for-windows-8-125m-for-content-tech-acquisition/'}
r = requests.get(url, params=params)
# r.text holds the response from the server. It appears to be unicode in this case.
f = codecs.open("foo.html", mode="w", encoding="UTF-8")
f.write(r.text)