Python

matplotlib, pylab

要は pylab は matplotlib.pyplot だけでなく numpy や matplotlib.mlab の関数も呼べるようになるらしい。たしかに、 >>> import pylab as pl >>> len(dir(pl)) 948 >>> import numpy as np >>> len(dir(np)) 585 >>> import matplotlib.pyplot as plt >>> …

Show, Attend and Tell の再現をやる

概要 paper: Show, Attend and Tell: Neural Image Caption Generation with Visual Attention arxiv.org/abs/1502.03044 Attention 能力を備えたキャプション生成 CNN で特徴抽出 抽出した特徴からキャプションを生成するように LSTM を学習 論文の著者は2…

pythonのword2vecがインストールできなかった

でも唸っていたらできたのでメモ 環境はOSX(10.10)でgccは(homebrew gcc47)です$ pip install word2vec すると ValueError: 'word2vec/word2vec_noop.pyx' doesn't match any files Command "python setup.py egg_info" failed with error code 1 in ... な…

python, json, unicode

なんでうまくいったのかよくわからないけど、unicodeでいろいろ書いてあるjsonファイルを読み込んでまた書き込みたいときの処理。 import json, codecs ## 読み込み fin = codecs.open(fin_name,'r','utf-8') jdata = json.load(fin) fin.close() ## jdata …

scikit-learn の RandomForest

肝心な部分だけ from sklearn.ensemble import RandomForestClassifier # n_estimatorsはtreeの数, random_stateはseed model = RandomForestClassifier(n_estimators=10, random_state=17) # がくしう model.fit(train_data, train_label) # 出来上がったtr…

theanoでMNISTのnegative log-likelihood

theanoでMNISTを多層パーセプトロンするとき(日本語?)のnegative log-likelihoodをコストとして計算する式であるところの NLL = -T.sum(T.log(p_y_given_x)[T.arange(y.shape[0]), y])]という式について、ただし実用的には、 NLL = -T.mean(T.log(p_y_giv…