<commit_before># coding: utf-8
import os, sys, re
import cPickle
from collections import OrderedDict

import matplotlib as mpl
mpl.use('pdf')
import seaborn as sns
import numpy as np
import matplotlib.pyplot as plt

import theano.sandbox.cuda
theano.sandbox.cuda.use('gpu0')
import theano
import theano.tensor as T
from theano.tensor.shared_randomstreams import RandomStreams
from theano import shared

from SdA import SdA
from dA.AutoEncoder import AutoEncoder, BernoulliAutoEncoder, GaussianAutoEncoder, ReluAutoEncoder

# pass the directory with models, number of layers
try:
    pkl_dir = sys.argv[1]
    num_layers = int(sys.argv[2])
    layers = re.compile(".*/([\d])\_layers/.*")
    match = layers.match(pkl_dir)
    pkl_dir_layers = int(match.groups()[0])
    assert pkl_dir_layers == num_layers
except:
    print "usage: python bias_hists.py <pkl_dir> <num_layers>"
    sys.exit()
    
pkl_files = os.listdir(pkl_dir)
os.chdir("/scratch/z/zhaolei/lzamparo/figures")

b_vis = OrderedDict((k, []) for k in xrange(num_layers))
b_hid = OrderedDict((k, []) for k in xrange(num_layers))

### Grab the data from each pickled model ###
for pkl in pkl_files:
    path = os.path.join(pkl_dir,pkl)
    print "processing " + pkl + " ..."
    f = file(path,'rb')
    sda = cPickle.load(f)
    f.close()
    
    for i,layer in enumerate(sda.dA_layers):
        W,bhid,bvis = layer.get_params()
        b_vis[i].append(bvis.get_value(borrow=True))
        b_hid[i].append(bhid.get_value(borrow=True))
    print "done "
            
### Plot the visible, hidden layer histograms ###
sns.set_palette("deep", desat=.6)
sns.set_context(rc={"figure.figsize": (12, 8)})

b_fig = plt.figure()<commit_msg>covering UnpicklingError exceptions, but to what end?<commit_after># coding: utf-8
import os, sys, re
import pickle
from collections import OrderedDict

import matplotlib as mpl
mpl.use('pdf')
import seaborn as sns
import numpy as np
import matplotlib.pyplot as plt

import theano.sandbox.cuda
theano.sandbox.cuda.use('gpu0')
import theano
import theano.tensor as T
from theano.tensor.shared_randomstreams import RandomStreams
from theano import shared

from SdA import SdA
from dA.AutoEncoder import AutoEncoder, BernoulliAutoEncoder, GaussianAutoEncoder, ReluAutoEncoder

# pass the directory with models, number of layers
try:
    pkl_dir = sys.argv[1]
    num_layers = int(sys.argv[2])
    layers = re.compile(".*/([\d])\_layers/.*")
    match = layers.match(pkl_dir)
    pkl_dir_layers = int(match.groups()[0])
    assert pkl_dir_layers == num_layers
except:
    print "usage: python bias_hists.py <pkl_dir> <num_layers>"
    sys.exit()
    
pkl_files = os.listdir(pkl_dir)
os.chdir("/scratch/z/zhaolei/lzamparo/figures")

b_vis = OrderedDict((k, []) for k in xrange(num_layers))
b_hid = OrderedDict((k, []) for k in xrange(num_layers))

### Grab the data from each pickled model ###
for pkl in pkl_files:
    path = os.path.join(pkl_dir,pkl)
    print "processing " + pkl + " ..."
    try:
        f = file(path,'rb')
        sda = pickle.load(f)
        f.close()
        
        for i,layer in enumerate(sda.dA_layers):
            W,bhid,bvis = layer.get_params()
            b_vis[i].append(bvis.get_value(borrow=True))
            b_hid[i].append(bhid.get_value(borrow=True))
    except UnpicklingError:
        print "Caught UnpicklingError trying to unpickle from " + path
    print "done "

# bail if I could not unpickle *any* models
num_items = np.asarray([len(b_vis[k]) for k in b_vis.keys()])
assert num_items.sum() > 0            

### Plot the visible, hidden layer histograms ###
sns.set_palette("deep", desat=.6)
sns.set_context(rc={"figure.figsize": (12, 8)})

b_fig = plt.figure()
{'fraction_non_alphanumeric': 0.125743645213629, 'fraction_numerical': 0.005137912385073012, 'mean_word_length': 3.828981723237598, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1186988', 'n_tokens_mistral': 1356, 'n_tokens_neox': 1342, 'n_words': 327}