Skip to content

Instantly share code, notes, and snippets.

View minhlab's full-sized avatar

Minh Le minhlab

  • FPT Software
  • Vietanm
View GitHub Profile
@minhlab
minhlab / theano-test-gpu.py
Last active July 17, 2017 07:18
A wget-able copy of the test script from Theano. For the most recent version, please see http://deeplearning.net/software/theano/tutorial/using_gpu.html#testing-theano-with-gpu
from theano import function, config, shared, tensor
import numpy
import time
vlen = 10 * 30 * 768 # 10 x #cores x # threads per core
iters = 1000
rng = numpy.random.RandomState(22)
x = shared(numpy.asarray(rng.rand(vlen), config.floatX))
f = function([], tensor.exp(x))
{
"loss":{
"y":"summed_cross_entropy",
"anaphoricities":"summed_cross_entropy"
},
"theano_mode":null,
"name":"Graph",
"output_config":[
{
"inputs":[
@minhlab
minhlab / count-wiki-cat.py
Created April 14, 2017 09:43
An attempt to count the number of pages (recursively) in a category in Wikipedia. It wasn't successful because the category of Vietnamese Wikipedia is cyclic and confusing.
# -*- coding: utf-8 -*-
import pywikibot
import sys
from collections import Counter
from random import randint
wiki = 'wikipedia'
lang = 'vi'
import numpy as np
import sys
def zero_safe_normalization(a):
norms = np.sum(a*a, axis=1)
zero_indices = np.nonzero(norms == 0)[0].tolist()
if zero_indices:
sys.stderr.write('Detect %d zero norms: %s\n' %(len(zero_indices), str(zero_indices)))
norms[zero_indices] = 1.0 # don't worry, 0/1 = 0
a /= norms[:,np.newaxis]
import numpy as np
# from deep-coref project: https://github.com/clarkkev/deep-coref
# download w2v_50d.txt from here: https://drive.google.com/file/d/0B5Y5rz_RUKRmdEFPcGIwZ2xLRW8/view
with open('w2v_50d.txt') as f:
word2id = {}
vectors = []
words = []
for line in f:
parts = line.strip().split()
from collections import Counter
import numpy as np
from scipy.stats import pearsonr
train = 'output/dep/penntree.jk.sd/train.mrg.dep'
ref = 'output/dep/penntree.jk.sd/valid.mrg.dep'
sys = 'output/dep/sd_parse-published-model_valid.conll'
out_path = 'output/occurrence-performance.npy'
count_path = 'output/occurrence-counts.npy'
@minhlab
minhlab / sanity-check.py
Last active July 17, 2017 07:48
Testing the validity of sanity check proposed in Batchkarov et al. (2016)
import numpy as np
from scipy.stats import spearmanr, pearsonr
from matplotlib import pyplot as pl
import sys
if __name__ == '__main__':
repeats = int(sys.argv[1]) if len(sys.argv) >= 2 else 5 # change this and see what happens
dim = 50
#sizes = {'simlex': 999, 'men': 3000, 'mc': 30, 'rg': 65, 'ws353': 353}
sizes = {'men': (3000, '#0066ff', '#4d94ff'), 'mc': (30, '#ff3300', '#ffd6cc80'), 'rg': (65, '#00ff00', '#ccffcc80')}
@minhlab
minhlab / count-ontonotes-event.py
Created July 15, 2017 07:41
Use this code to count events in OntoNotes 5.0
import os
import re
from collections import defaultdict
import sys
import ptb
ontonotes_root = '/Users/cumeo/corpora/ontonotes-release-5.0'
ontonotes_en = os.path.join(ontonotes_root, 'data/files/data/english/annotations')
assert os.path.exists(ontonotes_root), 'please link/put ontonotes into data directory'
from collections import defaultdict
import re
s=open('/Users/cumeo/Downloads/dup-docs.txt').read()
pairs = [re.sub(' +', ' ', line).strip().split(' ') for line in s.strip().split('\n')]
clusters = defaultdict(set)
for doc1, doc2 in pairs:
c = clusters[doc1]
c.update(clusters[doc2])
c.update({doc1, doc2})
Tuanminh01 (thảo luận · đóng góp): 439 điểm, Điểm thi tháng 9 năm 2017
Phương Huy (thảo luận · đóng góp): 324 điểm, Điểm thi tháng 9 năm 2017
Bluetpp (thảo luận · đóng góp): 287 điểm, Điểm thi tháng 9/2017
Buileducanh (thảo luận · đóng góp): 265 điểm, Điểm thi tháng 9/2017
Anhkhang234 (thảo luận · đóng góp): 223 điểm, Điểm thi tháng 9 năm 2017
Nguyenphanuyennhi (thảo luận · đóng góp): 194 điểm, Điểm thi tháng 9 2017
Mintu Martin (thảo luận · đóng góp): 128 điểm
Atnastr (thảo luận · đóng góp): 127 điểm, Điểm thi viết bài khoa học tháng 9/2017
Hoanglongmit (thảo luận · đóng góp): 104 điểm, Điểm thi tháng 9 năm 2017
A.Einstein05 (thảo luận · đóng góp): 78 điểm, Điểm thi tháng 9 năm 2017