Skip to content

Instantly share code, notes, and snippets.

import sys
sys.path.append('..')
import os
import json
from time import time
import numpy as np
from tqdm import tqdm
from matplotlib import pyplot as plt
from sklearn.externals import joblib
@Newmu
Newmu / simple_gan.py
Created July 10, 2015 20:39
Simple Generative Adversarial Network Demo
import os
import numpy as np
from matplotlib import pyplot as plt
from time import time
from foxhound import activations
from foxhound import updates
from foxhound import inits
from foxhound.theano_utils import floatX, sharedX
@Newmu
Newmu / yelp_lr_tufs.py
Last active August 29, 2015 14:19
95.05% on yelp
import json
import numpy as np
from time import time
from matplotlib import pyplot as plt
import random
from sklearn import metrics
from sklearn.linear_model import LogisticRegression as LR
from sklearn.feature_extraction.text import TfidfVectorizer
@Newmu
Newmu / dbpedia_lr_tufs.py
Last active August 29, 2015 14:19
98.76% on dbpedia - TUFS dataset
import os
import pandas as pd
import numpy as np
from sklearn import metrics
from sklearn.linear_model import LogisticRegression as LR
from sklearn.feature_extraction.text import TfidfVectorizer
from time import time
def len_filter(text, max_len=1014):
@Newmu
Newmu / conv_deconv_variational_autoencoder.py
Last active November 13, 2023 16:35
Prototype code of conv/deconv variational autoencoder, probably not runable, lots of inter-dependencies with local codebase =/
import theano
import theano.tensor as T
from theano.sandbox.rng_mrg import MRG_RandomStreams as RandomStreams
from theano.tensor.signal.downsample import max_pool_2d
from theano.tensor.extra_ops import repeat
from theano.sandbox.cuda.dnn import dnn_conv
from time import time
import numpy as np
from matplotlib import pyplot as plt
@Newmu
Newmu / adam.py
Last active August 11, 2019 22:24
Adam Optimizer
"""
The MIT License (MIT)
Copyright (c) 2015 Alec Radford
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
@Newmu
Newmu / model.py
Created December 11, 2014 01:14
~0.96 on Kaggle IMDB using stupid learning instead of "deep learning"
import numpy as np
import pandas as pd
from lxml import html
from sklearn import metrics
from sklearn.cross_validation import train_test_split
from sklearn.linear_model import LogisticRegression as LR
from sklearn.feature_extraction.text import TfidfVectorizer
def clean(text):
return html.fromstring(text).text_content().lower().strip()
@Newmu
Newmu / nearest_neighbor.py
Last active August 29, 2015 13:57
Given a training dataset as a 2d array where rows are examples and columns are features, values associated with those training examples, and some new examples to be predicted, return the value associated with the closest nearest neighbor using a scipy distance metric.
import numpy as np
from scipy.spatial.distance import cdist
def nearest_neighbor(samples, targets, samples_to_classify, metric='euclidean'):
return targets[np.argmin(cdist(samples_to_classify, samples, metric=metric), axis=1)]