<jupyter_start><jupyter_text>Introduction to LasagneThere are various libaries building on top of Theano to provide easy buidling blocks for designing deep neural networks. Some of them are:- Lasagne (https://github.com/Lasagne/Lasagne)- Blocks (https://github.com/mila-udem/blocks)- Keras (http://keras.io/)- OpenDeep (http://www.opendeep.org/)All libaries are kind of similar but different in the details, for example in the design philosophy. I chose (after too little research) Lasagne as it will allow you to interact with Theano and the computation graph. Keep an eye onto this evolving area.For a great example how to use Lasagne for MNIST see the Lasagne Tutorial: http://lasagne.readthedocs.org/en/latest/user/tutorial.html  BascisLasagne provides you with several basic components to build your neural networks. Instead of defining your HiddenLayer and SoftmaxLayer as in the previous example, you can use existent implementations from the library and easily plug them together.In the following we will reimplement the MLP for the MNIST-dataset using Lasagne. For more information on Lasagne see http://lasagne.readthedocs.org/en/latest/  Load your datasetAs before we load our dataset. See 2_MNIST for more details.<jupyter_code>import gzip
import cPickle
import numpy as np
import theano
import theano.tensor as T

import lasagne

# Load the pickle file for the MNIST dataset.
dataset = 'data/mnist.pkl.gz'

f = gzip.open(dataset, 'rb')
train_set, dev_set, test_set = cPickle.load(f)
f.close()

#train_set contains 2 entries, first the X values, second the Y values
train_x, train_y = train_set
dev_x, dev_y = dev_set
test_x, test_y = test_set<jupyter_output><empty_output><jupyter_text>Build the MLPNow we use the provided layers from Lasagne to build our MLP<jupyter_code>def build_mlp(n_in, n_hidden, n_out, input_var=None):
    # Put your code here to build the MLP using Lasagne<jupyter_output><empty_output><jupyter_text>Create the Train FunctionAfter loading the data and defining the MLP, we can now create the train function.<jupyter_code># Parameters
n_in = 28*28
n_hidden = 50
n_out = 10

# Create the necessary training and predict labels function<jupyter_output><empty_output><jupyter_text>Train the modelWe run the training for some epochs and output the accurarcy of our network<jupyter_code>#Put your code here to train the model using mini batches<jupyter_output>10 epochs
0 epoch: Accurarcy on dev: 0.971800, accurarcy on test: 0.969500
1 epoch: Accurarcy on dev: 0.972100, accurarcy on test: 0.970900
2 epoch: Accurarcy on dev: 0.972500, accurarcy on test: 0.970800
3 epoch: Accurarcy on dev: 0.972600, accurarcy on test: 0.969700
4 epoch: Accurarcy on dev: 0.973700, accurarcy on test: 0.970600
5 epoch: Accurarcy on dev: 0.972600, accurarcy on test: 0.970200
6 epoch: Accurarcy on dev: 0.973300, accurarcy on test: 0.970900
7 epoch: Accurarcy on dev: 0.972900, accurarcy on test: 0.969900
8 epoch: Accurarcy on dev: 0.973000, accurarcy on test: 0.969500
9 epoch: Accurarcy on dev: 0.972900, accurarcy on test: 0.970400
DONE
{'fraction_non_alphanumeric': 0.06969895287958115, 'fraction_numerical': 0.05301047120418848, 'mean_word_length': 5.1017964071856285, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 2, 'lorem ipsum': 0, 'www.': 1, '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}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '295671', 'license': 'Apache-2.0', 'n_tokens_mistral': 1096, 'n_tokens_neox': 975, 'n_words': 399, 'path': '2015-10_Lecture/Lecture2/code/3_Intro_Lasagne.ipynb', 'repo_name': 'hlin117/deeplearning4nlp-tutorial', 'size': '3056'}