This file contains hidden or 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 torch | |
import torch.nn as nn | |
import torch.nn.functional as F | |
# helpers | |
def make_unit_length(x, epsilon=1e-6): | |
norm = x.norm(p=2, dim=-1, keepdim=True) | |
return x.div(norm + epsilon) |
This file contains hidden or 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
def main(text_file, out_file): | |
with open(text_file) as f: | |
temp = f.readlines() | |
content = [x.strip() for x in temp] | |
with open(out_file, 'w') as f: | |
for i in content: | |
if i.split()[4] == 'bonafide': | |
f.write('%s %s\n' % (i.split()[0] + '-' + i.split()[1], i.split()[4])) | |
else: |
This file contains hidden or 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 torch | |
from torch.autograd import Function | |
class GELS(Function): | |
""" Efficient implementation of gels from | |
Nanxin Chen | |
[email protected] | |
""" | |
@staticmethod | |
def forward(ctx, A, b): |
This file contains hidden or 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 | |
#from sklearn.discriminant_analysis import _class_cov,LinearDiscriminantAnalysis | |
from discriminant_analysis import _class_cov,LinearDiscriminantAnalysis | |
X = np.random.rand(1000000, 100) | |
y = np.random.randint(0, 20000, (1000000, )) | |
print len(np.unique(y)) | |
#model=LinearDiscriminantAnalysis(solver='eigen') | |
#model.fit(X,y) | |
_class_cov(X, y, np.array([1.]*20000)/20000) |
This file contains hidden or 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 keras.backend as K | |
from keras import initializers | |
from keras.engine import InputSpec | |
from keras.layers import Dense, Lambda, Wrapper | |
class ConcreteDropout(Wrapper): | |
def __init__(self, layer, weight_regularizer=1e-6, dropout_regularizer=1e-5, **kwargs): | |
assert 'kernel_regularizer' not in kwargs | |
super(ConcreteDropout, self).__init__(layer, **kwargs) |
This file contains hidden or 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
# The data can be found in https://github.com/tdhopper/topic-modeling-datasets/blob/master/README.md | |
# The stop word lists can be found in https://github.com/stanfordnlp/CoreNLP/blob/master/data/edu/stanford/nlp/patterns/surface/stopwords.txt | |
# Data clean in http://www.mjdenny.com/Text_Processing_In_R.html | |
library(stringr) | |
library(gtools) | |
createDataFile = function(){ | |
processFile = function(filepath) { | |
con = file(filepath, "r") | |
inAbstract = FALSE |
This file contains hidden or 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
from multiprocessing import Pipe, Process, Manager | |
from time import sleep | |
import sharedmem | |
batches = Manager().dict() | |
def train_process(model, num_batches, save_path, q): | |
cnt = 0 | |
while True: |
This file contains hidden or 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
var ldap = require('ldapjs'), | |
mysql = require("mysql"), | |
server = ldap.createServer(), | |
addrbooks = {}, userinfo = {}, | |
ldap_port = 389, | |
basedn = "dc=example, dc=com", | |
company = "Example", | |
db = mysql.createClient({ | |
user: "abook", | |
password: "abook", |