{"_id":"5654d9dc055aa40d006f0c29","project":"5503ea178c5e913700362c70","__v":5,"user":"5503e897e508a017002013bd","version":{"_id":"563fc7631594380d009c1a5c","project":"5503ea178c5e913700362c70","__v":2,"createdAt":"2015-11-08T22:06:27.279Z","releaseDate":"2015-11-08T22:06:27.278Z","categories":["563fc7641594380d009c1a5d","563fc7641594380d009c1a5e","563fc7641594380d009c1a5f","5654ff257b89070d00f96386"],"is_deprecated":false,"is_hidden":false,"is_beta":true,"is_stable":true,"codename":"","version_clean":"0.0.9","version":"0.0.9"},"category":{"_id":"5654ff257b89070d00f96386","version":"563fc7631594380d009c1a5c","pages":[],"__v":0,"project":"5503ea178c5e913700362c70","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-11-25T00:21:57.507Z","from_sync":false,"order":1,"slug":"core-concepts","title":"Core Concepts"},"githubsync":"","metadata":{"title":"","description":"","image":[]},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-11-24T21:42:52.874Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":1,"body":"The second component necessary for building a deep learning model. Variables need to be appropriate for the data you expect to input for the model.\n\nVariables are used as inputs to models and loss functions - they are placeholders for what you dataset inputs and targets will look like. The variables are passed with the form Tuple(shape_monad, theano_variable):\n\n## Shape monad\nThe first element in the tuple when passing variables or expressions around Model inputs is the shape monad. This is a tuple whose length is equal to the number of dimensions, and each element corresponds to that dimension's size. If any size is unknown, simply put None as the element. Here is an example shape for minibatch processing on MNIST 2D images:\n\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"# mnist images are greyscale i.e. there is only 1 color channel\\nh, w = 28, 28\\nchannels = 1\\nbatch_size = None\\nshape_monad = (batch_size, channels, h, w)\",\n \"language\": \"python\"\n }\n ]\n}\n[/block]\n## Theano tensor\nNow that we have the shape we expect our input to be, we have to create a Theano tensor variable to represent it. Use the appropriate constructor from [Theano's documentation](http://deeplearning.net/software/theano/library/tensor/basic.html#creation), and be sure that the type of the variable is appropriate for the type of the input. To continue our MNIST example, here is the appropriate Theano tensor to initialize:\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"# initialize the 4D tensor that represents batches of images\\nimages = theano.tensor.tensor4(name=\\\"images\\\", dtype='float32')\",\n \"language\": \"python\"\n }\n ]\n}\n[/block]\n## Putting it together\nWhenever we pass this new variable representing batches of images, we construct it with a tuple as follows:\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"# variable tuple to pass as input to model\\ninput = (shape_monad, images)\",\n \"language\": \"python\"\n }\n ]\n}\n[/block]","excerpt":"","slug":"basics-variables","type":"basic","title":"Variables"}