{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Populating the interactive namespace from numpy and matplotlib\n" ] } ], "source": [ "%pylab inline" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import sys\n", "sys.version\n", "sys.path += [\"/usr/local/lib/python2.7/dist-packages\"]" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import clstm\n", "import numpy" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [], "source": [ "inputs = clstm.Sequence()\n", "outputs = clstm.Sequence()\n", "targets = clstm.Sequence()" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "100 11 7\n" ] } ], "source": [ "a = array(randn(100,11,7),'f')\n", "clstm.sequence_of_array(inputs,a)\n", "print inputs.size(), inputs.depth(), inputs.batchsize()\n", "#clstm.array_of_sequence(b,inputs)\n", "#print b.shape" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [], "source": [ "b = numpy.empty_like(a)\n", "clstm.array_of_sequence(b,inputs)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "(100, 11, 7)" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "b = numpy.empty((1,1,1),'f')\n", "clstm.array_of_sequence(b,inputs)\n", "b.shape" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ " *' at 0x7fbbba8e8c30> >" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "net = clstm.make_net_init(\"bidi\",\"ninput=11:nhidden=20:noutput=13\")\n", "net" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ ".Stacked: 0.000100 0.900000 11 13\n", ".Stacked.Parallel: 0.000100 0.900000 11 40\n", ".Stacked.Parallel.NPLSTM_SigmoidTanhTanh: 0.000100 0.900000 11 20\n", ".Stacked.Parallel.Reversed: 0.000100 0.900000 11 20\n", ".Stacked.Parallel.Reversed.NPLSTM_SigmoidTanhTanh: 0.000100 0.900000 11 20\n", ".Stacked.SoftmaxLayer: 0.000100 0.900000 40 13\n", "\n" ] } ], "source": [ "print clstm.network_info(net)" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": false }, "outputs": [], "source": [ "temp = clstm.make_layer(\"LSTM\")\n", "temp" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "100 11 7\n" ] } ], "source": [ "clstm.sequence_of_array(net.inputs, a)\n", "print net.inputs.size(), net.inputs.depth(), net.inputs.batchsize()" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0 -1 -1\n", "100 13 7\n" ] } ], "source": [ "print net.outputs.size(), net.outputs.depth(), net.outputs.batchsize()\n", "net.forward()\n", "print net.outputs.size(), net.outputs.depth(), net.outputs.batchsize()" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "collapsed": false }, "outputs": [], "source": [ "deltas = zeros(0,'f')\n", "clstm.array_of_sequence(deltas,net.outputs)\n", "deltas *= 0\n", "clstm.sequence_of_array(net.d_outputs,deltas)" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0 -1 -1\n", "100 11 7\n" ] } ], "source": [ "print net.d_inputs.size(), net.d_inputs.depth(), net.d_inputs.batchsize()\n", "net.backward()\n", "print net.d_inputs.size(), net.d_inputs.depth(), net.d_inputs.batchsize()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.6" } }, "nbformat": 4, "nbformat_minor": 0 }