ããã«ã¡ã¯ãã»ãããã§ãã
DeepMindãæ°æ¥åã«ãtensorflowãç¨ããã¢ã¸ã¥ã¼ã«"sonnet"ããªã¼ãã³ã½ã¼ã¹åãã¾ããã
æ®æ®µKerasãã使ã£ã¦ããªãã®ã§ãããã¡ãã£ã¨ã ã触ã£ãã調ã¹ããããã®ã§
- ã¤ã³ã¹ãã¼ã«æ¹æ³
- Exampleã«ã¤ãã¦
- Kerasã¨ã®éããæ³å®ã¦ã¼ã¶
ãªã©ãææã¨ã¨ãã«ã¡ã¢ã¨ãã¦æ®ãã¦ããã¾ãã
- sonnetã¨ã¯
- requirement
- ã¤ã³ã¹ãã¼ã«æ¹æ³
- Exampleã試ã
- ä¸èº«ãã¡ãã£ã¨ã ãè¦ã
- ææ
sonnetã¨ã¯
- DeepMind(ä»ä¸çªãããGoogleåä¸ã®ç 究æ)ã社å ç¨ã«ä½¿ã£ã¦ãã深層å¦ç¿ç¨ã©ã¤ãã©ãª
- tensorflowã®ã©ããã¼çç«ã¡ä½ç½®(tensorflowãå ¥ã£ã¦ãããã¨ãå¿ è¦)
- Linux/MacOSXã§å¯¾å¿
requirement
- python2.7 : 3ç³»ã¯ã¾ã 対å¿ãã¦ããªããã
- tensorflow >= 1.0.1 : Deeplearningç¨ã©ã¤ãã©ãª
- bazel (>= 0.4.5 )ã : Google謹製ã®ãã«ããã¼ã«
- java >= 1.8+
ã¤ã³ã¹ãã¼ã«æ¹æ³
bazelã®ã¤ã³ã¹ãã¼ã«
Documentãã¿ããèªåã®OSã«å¿ãã¦ã(ä»åã¯ãMacOSXã®homebrew)
brew cask install java #javaã®ã¤ã³ã¹ãã¼ã« brew install bazel
sonnetããã¦ã³ãã¼ãããã§ãã¯
git clone --recursive https://github.com/deepmind/sonnet cd sonnet/tensorflow ./configure
ãªããã®ã¯ã¨ã©ã¼ã«å¾ã£ã¦å ¥ãã¦ããã
./configure
ã§è²ã
èããã(ã³ã³ãã¤ã©ãæé©ãªãã¤ä½¿ããã¨ããOpenCL使ããã¨ããpythonã®ãã¹ã¨ã)
å¥ã«ãã ããããªã人ã¯Enteré£æã§(ã§ãä¸å¿ã¡ãã»ã¼ã¸ã¯ã¿ã¦ããã)
ãã¾ãããã¨ãããªã¡ãã»ã¼ã¸ãã
Extracting Bazel installation... .............................................................. INFO: Starting clean (this may take a while). Consider using --expunge_async if the clean takes more than several minutes. ............................................................. INFO: All external dependencies fetched successfully.
ãã«ããã¤ã³ã¹ãã¼ã«
sonnetããã«ã
mkdir /tmp/sonnet bazel build --config=opt :install ./bazel-bin/install /tmp/sonnet
/tmp/sonnet以ä¸ã«pip installã§ãããã¡ã¤ã«ãã§ããã®ã§ã
pip install /tmp/sonnet/*.whl
ã¨ãããããã§å®äº
ãã§ãã¯
pythonãèµ·åãã以ä¸ã®ã³ã¼ããæã¤
import sonnet as snt import tensorflow as tf snt.resampler(tf.constant([0.]), tf.constant([0.]))
ä¸è¨ã®è¡¨ç¤ºã«ãªãã°OK
<tf.Tensor 'resampler/Resampler:0' shape=(1,) dtype=float32>
Exampleã試ã
ã¿ã¹ã¯
使ããããã«ãªã£ãã®ã§ãexampleãå®éã«åããã¦ã¿ãã æ®éããããã®ã¯MNISTã使ã£ã¦åé¡ãå®çªã ããä»åã®exampleã¯RNN(å¤å±¤ã®LSTM)ã使ã£ããã®ãã¾ã exampleã¯ããããç¨æããã¦ããªãããã
ä¸èº«ã®ã³ã¼ããè¦ãªããLSTMãã©ããã£ã¦æ¸ãã®ãçºããã®ã¯ãããããããªããä»åã¯çµæã ãã
ãã¼ã¿ã»ãã
ã·ã§ã¼ã¯ã¹ãã¢ã®“CORIOLANUS”ã使ã£ã¦å¦ç¿ãããããã£ã½ãæç« ãçæããRNNãä½ããã¨ããæãã
Coriolanus (The New Cambridge Shakespeare)
- ä½è : William Shakespeare,Bridget Escolme,Lee Bliss
- åºç社/ã¡ã¼ã«ã¼: Cambridge University Press
- çºå£²æ¥: 2010/01/21
- ã¡ãã£ã¢: ãã¼ãã¼ããã¯
- ãã®ååãå«ãããã°ãè¦ã
çµæ
ä¸èº«ã¯ç½®ãã¦ããã¦ãã¨ããããå®è¡ãã¦ã¿ãã*1
python rnn_shakespear.py
ã¯ããã«WARNINGãããããã§ãå¾ã«ãå¦ç¿ãé²ãã ãWARNINGã¯
ããåããã£ã¨ç°å¢ãæé©åã§ãããã©ããªãã®ï¼ã
ã¨ãããã¤ã
çµæã¯ãã¾ã«æç« ã½ãã®ããããã¡ããã¨ããæç« ã¨ã¯ç¨é ããå¦ç¿ãã¼ã¿ãå°ãªãããï¼
INFO:tensorflow:9999: Training loss 78.764648. Validation loss 100.533051. Sample = b_0: ht this, and we letter my house of Hereford,|Will reason at wailer, I have by found you.||BENVOLIO:| No, therefore, none me thy ear, or we were not a|great-father uncle Edward's right divined soul six with his first,| And then I tear the back of pleasure; and our sword| To bowly me of preceion dubfil-god:|Go well in Aufidius to year:| You may not show thy length.| |PARIS:| His lady.| |POLIXENES:|So Margaret.| |LEONTES:|Hail, sir, too saying!| |NORTHUMBERLAND:|So parentme: call me wench-for my greatest,| Twear have a man; twerver it sorrows I lovely curs you,|Gives me, encorst, for his masters did not myself;| For thy welcome visiting name of your native|hath not all thy desires to run broke us| Yon me--and Phoebus Derby, be said, hast thou no man all, my oaths,|Break not that maids with this nighuls of your life| Will grow themselves: both best in earth! had he were no;| Who adveral with punish made both|To do them, and majesty, Aumelle;|Many to this the coming love marriage|What, lost deny here: h INFO:tensorflow:Reducing learning rate. INFO:tensorflow:Test loss 129.366608
ã¾ããå¦ç¿ããã¢ãã«ã¯ /tmp/sonnet
以ä¸ã«ä¿åãããã
ä¸èº«ãã¡ãã£ã¨ã ãè¦ã
sonnetã§ã¯ãDeeplearningã®ãããã¯ã¼ã¯ããä½ãé¨åãsonnet/python/modules
ã«è²ã
ã¨æã£ã¦ããã
sonnet/sonnet/python/modules at master · deepmind/sonnet · GitHub
ä¾ãã°
- conv : CNNã®convolution層ãä½ããã¨ãã§ãã
- gated_rnn : LSTMãªã©ãRNNã«ç¨ããã²ã¼ããä½ããã¨ãã§ãã
ã¾ããããã«ãããã¤ãã®æ¢è£½ã®ãããã¯ã¼ã¯ãããããã ã
sonnet/mlp.py at master · deepmind/sonnet · GitHub
- Alexnet
- ConvNet
- Multi Layer Perceptron
- Dilation
(ä¾ : AlexNetã®ã¢ã¼ããã¯ãã£(Krizhevsky 2012))
ä¾ãã°ãèªåã§ãããã¯ã¼ã¯ãä½ããããã°âã®ããã«ãããã¯ã¼ã¯ãæ§æãã¦ãã (DeepMindã®Sonnetã触ã£ãã®ã§ãTensorFlowãKerasã¨æ¯è¼ããªãã解説ãã¦ã¿ã ããæå)
def build(inputs): outputs = snt.Conv2D(output_channels=32, kernel_shape=4, stride=2)(inputs) outputs = snt.BatchNorm()(outputs) outputs = tf.nn.relu(outputs) outputs = snt.BatchFlatten()(outputs) # TensorFlow weight = tf.Variable(tf.truncated_normal(shape=[4096,10])) bias = tf.Variable(tf.constant(0.1, shape=[1,10])) outputs = tf.matmul(outputs, weight) + bias outputs = tf.nn.relu(outputs) return outputs model = snt.Module(build)
å¦ç¿ã¯tensorflowã®è¨æ³ã«ãããã£ã¦è¡ãã
ãããKerasã ã¨ã以ä¸ã®ãããªæãã§æ¸ã
model = Sequential() model.add(Conv2D(32, kernel_size=(2,2), activation='relu', input_shape=(28,28,1)) model.add(BatchNormalization()) model.add(Activation('relu')) model.add(Flatten()) model.add(Dense(10)) model.compile(loss='mean_squared_error', optimizer=Adam())
å¦ç¿ã¯model.fit(...)
ã使ãã
æã大ããªéãã¯
- sonnetã¯tensorflowã¨ã³ã¼ãä¸ã§çµã¿åããã¦ä½¿ããã¨ãã§ãã
- Kerasã¯kerasã¨ãã¦éãã¦ãã
ã¨ãããã¨ãããã¯ä¸é·ä¸çã§ãKerasã¯å ¨ã¦Kerasã¨ãã¦ä½¿ããã¨ãã§ããã®ã§ãçµå§ä¸è²«ãã¦ç´æçã«æ±ããã¨ãã§ããããã«æ§æããã¦ããããããå°ãæã®è¾¼ãã ãããã¯ã¼ã¯ã«æ¡å¼µãããã¨ããã¨ãæè»æ§ãä½ãã¨æãããã¨ãããã
ä¸æ¹ã§sonnetã¯é¢åãªã¨ããã ããã¢ã¸ã¥ã¼ã«åãã¦ãç´°ããè¨å®ãããæã«ã¯tensorflowããã®ã¾ã¾ç¨ãããã¨ãã§ããã®ã§ãèªåã§æè»æ§ãèªç±ã«èª¿ç¯ã§ããã ããããtensorflowã使ãã®ã¯ãKerasã«æ¯ã¹ã¦å°ãæ·å± ãé«ãããã«æããããã
ãã¨ã¯ãããã¥ã¡ã³ããtutorialãå§åçã«å°ãªããããã¦ãã¡ããæ¥æ¬èªã¯ãªãã
ææ
sonnetã¯ããã§ã«tensorflowã使ã£ã¦ããå¼·ã人ãã¡ ã対象ãªã®ããªã£ã¦æã£ãã ããããæå³ã§ã¯ã¾ãã«DeepMindã®ç¤¾å¡ã使ããããªã¤ã¡ã¼ã¸ã«è¿ããé¢åãªã¨ããããªãã¹ãçãã¦ãæ¬å½ã«å¤§äºãªã¨ããã ãéä¸ããããã®ãã¼ã«ãã¨ããã¤ã¡ã¼ã¸ã§ãããç 究è ã®éã§ã¯æµè¡ããããããªãã
å人çã«ã¯ãKerasã使ããã°ã¾ãã¯ããã㪅 ããã¡ãã£ã¨tensorflowã«ãªããå¿ è¦ããããªã¨æãã¾ããã
*1:ã¡ããã¨åå¼·ãããã¾ãã¡ã¢ã¨ãã¦è¨äºã«ãããã㪅