2015-12-27 22:25:19 +08:00
{
" cells " : [
{
" cell_type " : " markdown " ,
" metadata " : { } ,
" source " : [
" # Introduction to Theano \n " ,
" \n " ,
" Credits: Forked from [summerschool2015](https://github.com/mila-udem/summerschool2015) by mila-udem \n " ,
" \n " ,
2015-12-30 18:56:49 +08:00
" ## Slides \n " ,
" \n " ,
" Refer to the associated [Introduction to Theano slides](http://nbviewer.ipython.org/github/donnemartin/data-science-ipython-notebooks/blob/master/deep-learning/theano-tutorial/intro_theano/intro_theano.pdf) and use this notebook for hands-on practice of the concepts. \n " ,
2015-12-27 22:25:19 +08:00
" \n " ,
" ## Basic usage \n " ,
" \n " ,
" ### Defining an expression "
]
} ,
{
" cell_type " : " code " ,
" execution_count " : 1 ,
" metadata " : {
" collapsed " : false
} ,
" outputs " : [ ] ,
" source " : [
" import theano \n " ,
" from theano import tensor as T \n " ,
" x = T.vector( ' x ' ) \n " ,
" W = T.matrix( ' W ' ) \n " ,
" b = T.vector( ' b ' ) "
]
} ,
{
" cell_type " : " code " ,
" execution_count " : 2 ,
" metadata " : {
" collapsed " : false
} ,
" outputs " : [ ] ,
" source " : [
" dot = T.dot(x, W) \n " ,
" out = T.nnet.sigmoid(dot + b) "
]
} ,
{
" cell_type " : " markdown " ,
" metadata " : { } ,
" source " : [
" ### Graph visualization "
]
} ,
{
" cell_type " : " code " ,
" execution_count " : 3 ,
" metadata " : {
" collapsed " : false
} ,
" outputs " : [
{
" name " : " stdout " ,
" output_type " : " stream " ,
" text " : [
" dot [@A] ' ' \n " ,
" |x [@B] \n " ,
" |W [@C] \n "
]
}
] ,
" source " : [
" from theano.printing import debugprint \n " ,
" debugprint(dot) "
]
} ,
{
" cell_type " : " code " ,
" execution_count " : 4 ,
" metadata " : {
" collapsed " : false
} ,
" outputs " : [
{
" name " : " stdout " ,
" output_type " : " stream " ,
" text " : [
" sigmoid [@A] ' ' \n " ,
" |Elemwise { add,no_inplace} [@B] ' ' \n " ,
" |dot [@C] ' ' \n " ,
" | |x [@D] \n " ,
" | |W [@E] \n " ,
" |b [@F] \n "
]
}
] ,
" source " : [
" debugprint(out) "
]
} ,
{
" cell_type " : " markdown " ,
" metadata " : { } ,
" source " : [
" ### Compiling a Theano function "
]
} ,
{
" cell_type " : " code " ,
" execution_count " : 5 ,
" metadata " : {
" collapsed " : false
} ,
" outputs " : [ ] ,
" source " : [
" f = theano.function(inputs=[x, W], outputs=dot) \n " ,
" g = theano.function([x, W, b], out) \n " ,
" h = theano.function([x, W, b], [dot, out]) \n " ,
" i = theano.function([x, W, b], [dot + b, out]) "
]
} ,
{
" cell_type " : " markdown " ,
" metadata " : { } ,
" source " : [
" ### Graph visualization "
]
} ,
{
" cell_type " : " code " ,
" execution_count " : 6 ,
" metadata " : {
" collapsed " : false
} ,
" outputs " : [
{
" name " : " stdout " ,
" output_type " : " stream " ,
" text " : [
" CGemv {inplace} [@A] ' ' 3 \n " ,
" |AllocEmpty { dtype= ' float64 ' } [@B] ' ' 2 \n " ,
" | |Shape_i {1} [@C] ' ' 1 \n " ,
" | |W [@D] \n " ,
" |TensorConstant {1.0} [@E] \n " ,
" |InplaceDimShuffle { 1,0} [@F] ' W.T ' 0 \n " ,
" | |W [@D] \n " ,
" |x [@G] \n " ,
" |TensorConstant {0.0} [@H] \n "
]
}
] ,
" source " : [
" debugprint(f) "
]
} ,
{
" cell_type " : " code " ,
" execution_count " : 7 ,
" metadata " : {
" collapsed " : false
} ,
" outputs " : [
{
" name " : " stdout " ,
" output_type " : " stream " ,
" text " : [
" Elemwise {ScalarSigmoid} [(0, 0)] [@A] ' ' 2 \n " ,
" |CGemv {no_inplace} [@B] ' ' 1 \n " ,
" |b [@C] \n " ,
" |TensorConstant {1.0} [@D] \n " ,
" |InplaceDimShuffle { 1,0} [@E] ' W.T ' 0 \n " ,
" | |W [@F] \n " ,
" |x [@G] \n " ,
" |TensorConstant {1.0} [@D] \n "
]
}
] ,
" source " : [
" debugprint(g) "
]
} ,
{
" cell_type " : " code " ,
" execution_count " : 8 ,
" metadata " : {
" collapsed " : false
} ,
" outputs " : [
{
" name " : " stdout " ,
" output_type " : " stream " ,
" text " : [
" The output file is available at pydotprint_f.png \n "
]
}
] ,
" source " : [
" from theano.printing import pydotprint \n " ,
" pydotprint(f, outfile= ' pydotprint_f.png ' ) "
]
} ,
{
" cell_type " : " code " ,
" execution_count " : 9 ,
" metadata " : {
" collapsed " : false
} ,
" outputs " : [
{
" data " : {
" image/png " : " iVBORw0KGgoAAAANSUhEUgAABlgAAAH9CAIAAAD55ObJAAAABmJLR0QA/wD/AP+gvaeTAAAgAElE \n QVR4nOzdd3RUZf4G8OdOJpMy6ZUkhECIhNC7SiiCkp9UQaQtLSJKkVVBVlB0dVFQEQERCxZgEVR0 \n FUWKgnSwAKFJCpAQ0itpk8kkU39/3J3ZkEYSMrkpz+fkcGbu3Hnv996Z5Bye833fK5hMJhARERER \n EREREbV0MqkLICIiIiIiIiIiagwMwoiIiIiIiIiIqFVgEEZERERERERERK2CXOoCiOrmk08+kboE \n Ivqfhx56KDg4WOoqiIiIiIiIakXgYvnUvAiCIHUJRPQ/u3btmjx5stRVEBERERER1Qo7wqgZ2gXw \n /91ETQFzaSIiIiIiala4RhgREREREREREbUKDMKIiIiIiIiIiKhVYBBGREREREREREStAoMwIiIi \n IiIiIiJqFRiEERERERERERFRq8AgjIiIiIiIiIiIWgUGYURERERERERE1CowCCMiIiIiIiIiolaB \n QRgREREREREREbUKDMKIiIiIiIiIiKhVYBBGREREREREREStAoMwIiIiIiIiIiJqFRiEERERERER \n ERFRqyCXugAiIuu4BZwAYoGXrDD4deB7wAYYD4RYYXwiIiIiIiKyAnaEETWWdYAjIABjgN+AdOBl \n QAAEYCZwwrzbKeBBQA68AOgqDXIUEAA3oA9wLyAA9sC9QC9ACQhARqOek/RVRQPrzY9NwBrgRWAw \n IAdmA48C2xv6iCrgSWA8MBhYWlUK9j4gNPRB715XYN6d9tEDrwCpjVEOERERERGRJNgRRtRYlgA6 \n YDnQDRgIAHgDSAJ2AA8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" : [
" <IPython.core.display.Image object> "
]
} ,
" execution_count " : 9 ,
" metadata " : {
" image/png " : {
" width " : 1000
}
} ,
" output_type " : " execute_result "
}
] ,
" source " : [
" from IPython.display import Image \n " ,
" Image( ' pydotprint_f.png ' , width=1000) "
]
} ,
{
" cell_type " : " code " ,
" execution_count " : 10 ,
" metadata " : {
" collapsed " : false
} ,
" outputs " : [
{
" name " : " stdout " ,
" output_type " : " stream " ,
" text " : [
" The output file is available at pydotprint_g.png \n "
]
} ,
{
" data " : {
" image/png " : " iVBORw0KGgoAAAANSUhEUgAABScAAAJ4CAIAAAAY0cErAAAABmJLR0QA/wD/AP+gvaeTAAAgAElE \n QVR4nOzdaXgUZd7+/bOzmwAJkbAEghC2RBhWFZGAOCgiICBMQJFNBUHl9hYHQR3cQR1kwL/ggoPo \n jeijqDgyCKIMSAwwgkRQMEFlJwtJyN5Zu9PPi5ruabKRkHQ6hO/n6MOj6+rqq35V3UU866qqNtls \n NgEAAAAAABfwcHcBAAAAAAA0WqRuAAAAAABchdQNAAAAAICreLm7AAAAAKDB2bZt27Fjx9xdBYD/ \n CA8Pv/nmm91dxUUidQMAAABlvf3225988om7qwDwH9HR0aRuAAAAoHGJlta7uwYAkia4u4Da4bpu \n AAAAAABchdQNAAAAAICrkLoBAAAAAHAVUjcAAAAAAK5C6gYAAAAAwFVI3QAAAAAAuAqpGwAAAAAA \n VyF1AwAAAADgKqRuAAAAAABchdQNAAAAAICrkLoBAAAAAHAVUjcAAAAAAK5C6gYAAAAAwFW83F0A \n AAAAAFzKzkkxUrz0pAs6/03aIHlKY6XOLugfrsdYNwAAANC4LJP8JZM0StotJUkLJZNkkqZIMfbZ \n YqWhkpc0Xyop18kOySQFSX2l/pJJ8pP6S72lAMkkJdfrOrm/qsPScvtzm7REekIaJHlJ06Rx0tq6 \n XmKuNFMaKw2S5lUUuVdIprpeaO11l2ZdaB6L9JR0pj7KaQgY6wYAAAAal0elEulxqYd0gyRpkXRS \n WicNlwbbZ4uSpkidp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F4x1AwAAAGgs/iAlVdQeIC2UFtai5y7SvFq8Hc68pcfd \n XUM9YqwbAAAAAABXIXU
" text/plain " : [
" <IPython.core.display.Image object> "
]
} ,
" execution_count " : 10 ,
" metadata " : {
" image/png " : {
" width " : 1000
}
} ,
" output_type " : " execute_result "
}
] ,
" source " : [
" pydotprint(g, outfile= ' pydotprint_g.png ' ) \n " ,
" Image( ' pydotprint_g.png ' , width=1000) "
]
} ,
{
" cell_type " : " code " ,
" execution_count " : 11 ,
" metadata " : {
" collapsed " : false
} ,
" outputs " : [
{
" name " : " stdout " ,
" output_type " : " stream " ,
" text " : [
" The output file is available at pydotprint_h.png \n "
]
} ,
{
" data " : {
" image/png " : " iVBORw0KGgoAAAANSUhEUgAABlgAAALdCAIAAADPoPliAAAABmJLR0QA/wD/AP+gvaeTAAAgAElE \n QVR4nOzdd3RUZf4G8OdOJpMy6ZUkhECIhNC7SiiCkp9UQaQtLSJKkVVBVlB0dVFQEQERCxZgEVR0 \n FUWKgnSwAKFJCpAQ0itpk8kkU39/3J3ZkEYSMrkpz+fkcGbu3Hnv996Z5Bye833fK5hMJhARERER \n EREREbV0MqkLICIiIiIiIiIiagwMwoiIiIiIiIiIqFVgEEZERERERERERK2CXOoCiOrmk08+kboE \n Ivqfhx56KDg4WOoqiIiIiIiIakXgYvnUvAiCIHUJRPQ/u3btmjx5stRVEBERERER1Qo7wqgZ2gXw \n /91ETQFzaSIiIiIiala4RhgREREREREREbUKDMKIiIiIiIiIiKhVYBBGREREREREREStAoMwIiIi \n IiIiIiJqFRiEERERERERERFRq8AgjIiIiIiIiIiIWgUGYURERERERERE1CowCCMiIiIiIiIiolaB \n QRgREREREREREbUKDMKIiIiIiIiIiKhVYBBGREREREREREStAoMwIiIiIiIiIiJqFRiEERERERER \n ERFRqyCXugAiIuu4BZwAYoGXrDD4deB7wAYYD4RYYXwiIiIiIiKyAnaEETWWdYAjIABjgN+AdOBl \n QAAEYCZwwrzbKeBBQA68AOgqDXIUEAA3oA9w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INmUa4EXgU6nLqL3LQLS5iYyIiIiIiKhl \n qe62bUREDecXYDGgB/KA2EqviquV6ev4B6kt8AXwHPAZoGiYMq3iGrAaCJS6jFrKBVYAB8z3xCQi \n IiIiImpZ2BFGRNbnDxQ
" text/plain " : [
" <IPython.core.display.Image object> "
]
} ,
" execution_count " : 11 ,
" metadata " : {
" image/png " : {
" width " : 1000
}
} ,
" output_type " : " execute_result "
}
] ,
" source " : [
" pydotprint(h, outfile= ' pydotprint_h.png ' ) \n " ,
" Image( ' pydotprint_h.png ' , width=1000) "
]
} ,
{
" cell_type " : " markdown " ,
" metadata " : { } ,
" source " : [
" ### Executing a Theano function "
]
} ,
{
" cell_type " : " code " ,
" execution_count " : 12 ,
" metadata " : {
" collapsed " : false
} ,
" outputs " : [
{
" data " : {
" text/plain " : [
" array([ 1.79048354, 0.03158954, -0.26423186]) "
]
} ,
" execution_count " : 12 ,
" metadata " : { } ,
" output_type " : " execute_result "
}
] ,
" source " : [
" import numpy as np \n " ,
" np.random.seed(42) \n " ,
" W_val = np.random.randn(4, 3) \n " ,
" x_val = np.random.rand(4) \n " ,
" b_val = np.ones(3) \n " ,
" \n " ,
" f(x_val, W_val) "
]
} ,
{
" cell_type " : " code " ,
" execution_count " : 13 ,
" metadata " : {
" collapsed " : false
} ,
" outputs " : [
{
" data " : {
" text/plain " : [
" array([ 0.9421594 , 0.73722395, 0.67606977]) "
]
} ,
" execution_count " : 13 ,
" metadata " : { } ,
" output_type " : " execute_result "
}
] ,
" source " : [
" g(x_val, W_val, b_val) "
]
} ,
{
" cell_type " : " code " ,
" execution_count " : 14 ,
" metadata " : {
" collapsed " : false
} ,
" outputs " : [
{
" data " : {
" text/plain " : [
" [array([ 1.79048354, 0.03158954, -0.26423186]), \n " ,
" array([ 0.9421594 , 0.73722395, 0.67606977])] "
]
} ,
" execution_count " : 14 ,
" metadata " : { } ,
" output_type " : " execute_result "
}
] ,
" source " : [
" h(x_val, W_val, b_val) "
]
} ,
{
" cell_type " : " code " ,
" execution_count " : 15 ,
" metadata " : {
" collapsed " : false
} ,
" outputs " : [
{
" data " : {
" text/plain " : [
" [array([ 2.79048354, 1.03158954, 0.73576814]), \n " ,
" array([ 0.9421594 , 0.73722395, 0.67606977])] "
]
} ,
" execution_count " : 15 ,
" metadata " : { } ,
" output_type " : " execute_result "
}
] ,
" source " : [
" i(x_val, W_val, b_val) "
]
} ,
{
" cell_type " : " markdown " ,
" metadata " : { } ,
" source " : [
" # Graph definition and Syntax \n " ,
" ## Graph structure "
]
} ,
{
" cell_type " : " code " ,
" execution_count " : 16 ,
" metadata " : {
" collapsed " : false
} ,
" outputs " : [
{
" name " : " stdout " ,
" output_type " : " stream " ,
" text " : [
" The output file is available at pydotprint_f_notcompact.png \n "
]
} ,
{
" data " : {
" image/png " : " iVBORw0KGgoAAAANSUhEUgAABXwAAALwCAIAAACrxiohAAAABmJLR0QA/wD/AP+gvaeTAAAgAElE \n QVR4nOzdd3hTZd8H8G9GkzbdpS0dQG1B2soqCCh7KMhQWQIiMkQEVEBBHkT0caCPAxy8ggguQEQF \n BZRVlF2mlFEeWihQoKWD0t2kSZs0yXn/OG/yhi4KNE3H93NxeSUnJ/f5ndPTXp7vue/7SARBABER \n ERERERFRTZM6ugAiIiIiIiIiapgYOhARERERERGRXTB0ICIiIiIiIiK7kDu6AKp5V69e3bNnj6Or \n IKL/N23aNEeXQERERETkABJOJNnwbNy4cezYsY6ugoj+H//SEhEREVHjxJ4ODRevcYjqgo0AM0Ai \n IiIiaqw4pwMRERERERER2QVDByIiIiIiIiKyC4YORERERERERGQXDB2IiIiIiIiIyC4YOhARERER \n ERGRXTB0ICIiIiIiIiK7YOhARERERERERHbB0IGIiIiIiIiI7IKhAxERERERERHZBUMHIiIiIiIi \n IrILhg5EREREREREZBcMHYiIiIiIiIjILhg6EBEREREREZFdyB1dABE5VC4QA1wAFtqh8cvAZkAG \n DAda2aF9IiIiIiKq29jTgeqYzwEVIAEeB44CGcBbgASQABOAGMtqh4FHADkwHyg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iKiSlQ2Mz4R1bq/gDmAEcgDLpT7VJxdwniHv7XNgHXAq8B35Z40WadcAj4E \n mju6jGrKAd4Eoi3P5iAiIiIiokqwpwNRnREEFAB6YBPgZ7NcC3wAXAUAvA6cusNmOwL/Br6ssTLt \n okP9SRxKge+AdUCYoys
" text/plain " : [
" <IPython.core.display.Image object> "
]
} ,
" execution_count " : 16 ,
" metadata " : {
" image/png " : {
" width " : 1000
}
} ,
" output_type " : " execute_result "
}
] ,
" source " : [
" pydotprint(f, compact=False, outfile= ' pydotprint_f_notcompact.png ' ) \n " ,
" Image( ' pydotprint_f_notcompact.png ' , width=1000) "
]
} ,
{
" cell_type " : " markdown " ,
" metadata " : { } ,
" source " : [
" ## Strong typing \n " ,
" ### Broadcasting tensors "
]
} ,
{
" cell_type " : " code " ,
" execution_count " : 17 ,
" metadata " : {
" collapsed " : false
} ,
" outputs " : [
{
" name " : " stdout " ,
" output_type " : " stream " ,
" text " : [
" (True, False) \n "
]
}
] ,
" source " : [
" r = T.row( ' r ' ) \n " ,
" print(r.broadcastable) "
]
} ,
{
" cell_type " : " code " ,
" execution_count " : 18 ,
" metadata " : {
" collapsed " : false
} ,
" outputs " : [
{
" name " : " stdout " ,
" output_type " : " stream " ,
" text " : [
" (False, True) \n "
]
}
] ,
" source " : [
" c = T.col( ' c ' ) \n " ,
" print(c.broadcastable) "
]
} ,
{
" cell_type " : " code " ,
" execution_count " : 19 ,
" metadata " : {
" collapsed " : false
} ,
" outputs " : [
{
" name " : " stdout " ,
" output_type " : " stream " ,
" text " : [
" [[ 1.1 2.1 3.1] \n " ,
" [ 1.2 2.2 3.2]] \n "
]
}
] ,
" source " : [
" f = theano.function([r, c], r + c) \n " ,
" print(f([[1, 2, 3]], [[.1], [.2]])) "
]
} ,
{
" cell_type " : " markdown " ,
" metadata " : { } ,
" source " : [
" # Graph Transformations \n " ,
" ## Substitution and Cloning \n " ,
" ### The `givens` keyword "
]
} ,
{
" cell_type " : " code " ,
" execution_count " : 20 ,
" metadata " : {
" collapsed " : false
} ,
" outputs " : [
{
" data " : {
" text/plain " : [
" array([ 1.90651511, 0.60431744, -0.64253361]) "
]
} ,
" execution_count " : 20 ,
" metadata " : { } ,
" output_type " : " execute_result "
}
] ,
" source " : [
" x_ = T.vector( ' x_ ' ) \n " ,
" x_n = (x_ - x_.mean()) / x_.std() \n " ,
" f_n = theano.function([x_, W], dot, givens= { x: x_n}) \n " ,
" f_n(x_val, W_val) "
]
} ,
{
" cell_type " : " markdown " ,
" metadata " : { } ,
" source " : [
" ### Cloning with replacement "
]
} ,
{
" cell_type " : " code " ,
" execution_count " : 21 ,
" metadata " : {
" collapsed " : false
} ,
" outputs " : [
{
" data " : {
" text/plain " : [
" array([ 1.90651511, 0.60431744, -0.64253361]) "
]
} ,
" execution_count " : 21 ,
" metadata " : { } ,
" output_type " : " execute_result "
}
] ,
" source " : [
" dot_n, out_n = theano.clone([dot, out], replace= { x: (x - x.mean()) / x.std()}) \n " ,
" f_n = theano.function([x, W], dot_n) \n " ,
" f_n(x_val, W_val) "
]
} ,
{
" cell_type " : " markdown " ,
" metadata " : { } ,
" source " : [
" ## Gradient \n " ,
" ### Using `theano.grad` "
]
} ,
{
" cell_type " : " code " ,
" execution_count " : 22 ,
" metadata " : {
" collapsed " : false
} ,
" outputs " : [ ] ,
" source " : [
" y = T.vector( ' y ' ) \n " ,
" C = ((out - y) ** 2).sum() \n " ,
" dC_dW = theano.grad(C, W) \n " ,
" dC_db = theano.grad(C, b) \n " ,
" # dC_dW, dC_db = theano.grad(C, [W, b]) "
]
} ,
{
" cell_type " : " markdown " ,
" metadata " : { } ,
" source " : [
" ### Using the gradients "
]
} ,
{
" cell_type " : " code " ,
" execution_count " : 23 ,
" metadata " : {
" collapsed " : false
} ,
" outputs " : [
{
" name " : " stdout " ,
" output_type " : " stream " ,
" text " : [
" [array(0.6137821438190066), array([[ 0.01095277, 0.07045955, 0.051161 ], \n " ,
" [ 0.01889131, 0.12152849, 0.0882424 ], \n " ,
" [ 0.01555008, 0.10003427, 0.07263534], \n " ,
" [ 0.01048429, 0.06744584, 0.04897273]]), array([ 0.03600015, 0.23159028, 0.16815877])] \n "
]
}
] ,
" source " : [
" cost_and_grads = theano.function([x, W, b, y], [C, dC_dW, dC_db]) \n " ,
" y_val = np.random.uniform(size=3) \n " ,
" print(cost_and_grads(x_val, W_val, b_val, y_val)) "
]
} ,
{
" cell_type " : " code " ,
" execution_count " : 24 ,
" metadata " : {
" collapsed " : false
} ,
" outputs " : [
{
" name " : " stdout " ,
" output_type " : " stream " ,
" text " : [
" [array(0.6137821438190066), array([[ 0.49561888, -0.14531026, 0.64257244], \n " ,
" [ 1.52114073, -0.24630622, -0.2429612 ], \n " ,
" [ 1.57765781, 0.7574313 , -0.47673792], \n " ,
" [ 0.54151161, -0.47016228, -0.47062703]]), array([ 0.99639999, 0.97684097, 0.98318412])] \n "
]
}
] ,
" source " : [
" upd_W = W - 0.1 * dC_dW \n " ,
" upd_b = b - 0.1 * dC_db \n " ,
" cost_and_upd = theano.function([x, W, b, y], [C, upd_W, upd_b]) \n " ,
" print(cost_and_upd(x_val, W_val, b_val, y_val)) "
]
} ,
{
" cell_type " : " code " ,
" execution_count " : 25 ,
" metadata " : {
" collapsed " : false
} ,
" outputs " : [
{
" name " : " stdout " ,
" output_type " : " stream " ,
" text " : [
" The output file is available at pydotprint_cost_and_upd.png \n "
]
} ,
{
" data " : {
" image/png " : " iVBORw0KGgoAAAANSUhEUgAACVMAAAPwCAIAAAC5/esPAAAABmJLR0QA/wD/AP+gvaeTAAAgAElE \n QVR4nOzdeVxVdeL/8fdlVVDBBcUNFUwwzH1JuWqW46SZS6a2QTqZWt++NVajLbaM7U3LTIvtZpBN \n Llmj/rTSXCFLQ7OUpRQQlUUMZd8u3N8fZ+CLIgoKHJbX8+FjHveee/ic9zkczAfv+XyOxW63CwAA \n AAAAAAAAAEAD52B2AAAAAAAAAAAAAAA1gOYPAAAAAAAAAAAAaAxo/gAAAAAAAAAAAIDGwMnsAA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JftKCC55LkJR29kqYhWcPUhbP2HLh06nsrmgnpUonSr/kPqlruUcVrpPaSg9WcqZlFkrd \n pI8r+bTqN17Vc1b87tjO3vKjtE+6RbpOulf6R4Vb1Bjq6oudGoAaRfMHAAAAAAAAABWElS7q+KaU \n KX1cuvri81Ke9IrkJs2QvKQFkos0T/pDekmSdELaJe2QjkmSnpPSpWWlA74jnZLcpc3Sn6T3pFnS \n PukzyaOaIdtKIWcv7Okl3Vmd9SG3SH+VJCVIT0o/lG6vLN6FL0uaNFx6Qfqb1FdaI7WRdkuTpInS \n ImmB5CBtk+zSa1K8JOlJ6WDVUpXpLt0g3XW+M1oqZUrJ0mEpQmp9wUttlKb7Sr82RnpGkhQvvVu6 \n wupzkqSj0jLJUsnpGDMsz3tXOEjPSnbpH6VH8ZR2Smek26VF0ndSuNTlIt8oJUmJpZflHGnVufGq \n kjPnfN+dHOn10kuxXPpUmiJ1LF0B1UsqkaZIK8oF2ydZpFsvdmoAapTFbr+0uegAAAAAAAAA0CDN \n mDFjtVZrldk5cMmKpeH
" text/plain " : [
" <IPython.core.display.Image object> "
]
} ,
" execution_count " : 25 ,
" metadata " : {
" image/png " : {
" width " : 1000
}
} ,
" output_type " : " execute_result "
}
] ,
" source " : [
" pydotprint(cost_and_upd, outfile= ' pydotprint_cost_and_upd.png ' ) \n " ,
" Image( ' pydotprint_cost_and_upd.png ' , width=1000) "
]
} ,
{
" cell_type " : " markdown " ,
" metadata " : { } ,
" source " : [
" ## Shared variables \n " ,
" ### Update values "
]
} ,
{
" cell_type " : " code " ,
" execution_count " : 26 ,
" metadata " : {
" collapsed " : false
} ,
" outputs " : [ ] ,
" source " : [
" C_val, dC_dW_val, dC_db_val = cost_and_grads(x_val, W_val, b_val, y_val) \n " ,
" W_val -= 0.1 * dC_dW_val \n " ,
" b_val -= 0.1 * dC_db_val \n " ,
" \n " ,
" C_val, W_val, b_val = cost_and_upd(x_val, W_val, b_val, y_val) "
]
} ,
{
" cell_type " : " markdown " ,
" metadata " : { } ,
" source " : [
" ### Using shared variables "
]
} ,
{
" cell_type " : " code " ,
" execution_count " : 27 ,
" metadata " : {
" collapsed " : false
} ,
" outputs " : [
{
" name " : " stdout " ,
" output_type " : " stream " ,
" text " : [
" [ 1.78587062 0.00189954 -0.28566499] \n "
]
}
] ,
" source " : [
" x = T.vector( ' x ' ) \n " ,
" y = T.vector( ' y ' ) \n " ,
" W = theano.shared(W_val) \n " ,
" b = theano.shared(b_val) \n " ,
" dot = T.dot(x, W) \n " ,
" out = T.nnet.sigmoid(dot + b) \n " ,
" f = theano.function([x], dot) # W is an implicit input \n " ,
" g = theano.function([x], out) # W and b are implicit inputs \n " ,
" print(f(x_val)) "
]
} ,
{
" cell_type " : " code " ,
" execution_count " : 28 ,
" metadata " : {
" collapsed " : false
} ,
" outputs " : [
{
" name " : " stdout " ,
" output_type " : " stream " ,
" text " : [
" [ 0.94151144 0.72221187 0.66391952] \n "
]
}
] ,
" source " : [
" print(g(x_val)) "
]
} ,
{
" cell_type " : " markdown " ,
" metadata " : { } ,
" source " : [
" ### Updating shared variables "
]
} ,
{
" cell_type " : " code " ,
" execution_count " : 29 ,
" metadata " : {
" collapsed " : false
} ,
" outputs " : [ ] ,
" source " : [
" C = ((out - y) ** 2).sum() \n " ,
" dC_dW, dC_db = theano.grad(C, [W, b]) \n " ,
" upd_W = W - 0.1 * dC_dW \n " ,
" upd_b = b - 0.1 * dC_db \n " ,
" \n " ,
" cost_and_perform_updates = theano.function( \n " ,
" inputs=[x, y], \n " ,
" outputs=C, \n " ,
" updates=[(W, upd_W), \n " ,
" (b, upd_b)]) "
]
} ,
{
" cell_type " : " code " ,
" execution_count " : 30 ,
" metadata " : {
" collapsed " : false
} ,
" outputs " : [
{
" name " : " stdout " ,
" output_type " : " stream " ,
" text " : [
" The output file is available at pydotprint_cost_and_perform_updates.png \n "
]
} ,
{
" data " : {
" image/png " : " iVBORw0KGgoAAAANSUhEUgAAB90AAAOlCAIAAABPBGD/AAAABmJLR0QA/wD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Z+yUyho2NTVRUVFRUlLhYU1MTHx9/5MiRuLi4P//5z1VVVY6O \n jsOHDx8xYsSIESMGDRoklUpNGzARERERERERERF1Jx2Zly8vL//xxx9jY2MPHDhQVFRkZ2cXFRW1 \n ePHikSNHRkREsEA8macePXqMHDly5MiRABoaGhISEuLi4uLi4latWlVWVta3b98JEyZMnDhx7Nix \n PXv2NHWwREREREREREREdNfrgFz51atXY2NjY2Nj4+Li1Gr1wIED58+fP2HChMGDB3OgMd1dFArF \n 0KFDhw4dunjxYo1GEx8ff+DAgQMHDvz73/9WKBSjRo2aNGnSo48+qlKpTB0pERERERERERER3a0k \n giDc3juLi4u//PLL//znP/Hx8XZ2dmPHjp0wYcK4ceP69evXsSESmdz169cPHjx44MCBn376qbS0 \n dMiQIdOnT582bZqDg4OpQ/s/U6dO3Y3diDF1HETdSQzwFG77f0kiIiJqk0QiwdfAVFPHQdSNsU9L \n RGSu2j2eva6u7ptvvpk8ebKLi8tf//pXf3////73v0VFRV9//fXMmTOZlKduqV+/frNmzYqJiSkq \n Kjp48KCvr++SJUtcXV0ff/zxvXv31tXVmTpAIiIiIiIiIiIiumu0Iy9fXFy8Zs0aDw+PqVOnVlZW \n fvrppwUFBTt37nzkkUdYO57uEXK5fNy4cbt27SooKNiyZUt5eXl0dLSHh8fatWtv3Lhh6uiIiIiI \n iIiIiIjoLmBUXj4/P/+ll17y8PB4//33586dm5mZ+b///W/WrFmcBpPuWT179pw1a9Yvv/ySkZEx \n Z86cDRs2eHh4LFiw4Nq1a6YOjYiIiIiIiIiIiMxaG3n5ysrKpUuX+vn57du3b926ddnZ2atXr3Z3 \n d++a4DrPjRs3vv3227Vr15o6kI5XXl7eGc1240/sDnl4eKxZsyY7O/vdd9/du3evn5/fm2++WVVV \n Zeq4Os4N4FuAZ/6u0KknKw34B7AOuNI57bcLfyyJiIiIup97pzdLRETUel7+4MGDwcHBW7Zseeut \n t9LS0l566aUePXp0WWRNHTt27G9/+5tEIpFIJHPmzPn+++9vr52UlJR33nlnypQpO3bs6MDw4uLi \n pk+fLoYnzoI7ZMiQ8ePHf/zxxzU1NQYbh4SEvPjii7exF0EQPv3009DQ0P79+/v4+Ii7++WXXwBs \n 3Lhx9OjRtzcTqSAI77777tKlS0eMGBEaGpqcnKy/Ri6Xz5w50/hPLCMjY/z48WPGjDl9+rT++ry8 \n vO3bt0+dOnXYsGGtB/Phhx9GR0cvX7582rRpW7Zs0Z+j5vTp0w899NC4ceOysrJu40g7iVKpfPnl \n l9PS0t54442PP/44JCTkxx9/NHVQHSEFeAeYArTrdyUP2A5MBVo7z4AAfAhEA8uBacAWoNm5iH4F \n JIAdMBC4H5AAVsD9QH/AGpAAJrlFwYRRJQEbG58LwLvAUmAEIAdmtv9kGaMCmAs8DowAXgN8m2yw \n CZB09E5bcXs/lgDUwFtAbqcERURERNQ89mYNsDd759itJSLqHoTmaLXalStXSqXSp556qqCgoNlt \n TMXLywtAbW3tnTSiVqsBBAQEdFRUIjH/7uvrKy5qtdrDhw/7+Ph4enqeO3dOf8sHH3zwr3/9623s \n YtOmTQC++eYbcfHgwYO2trY7duwQBKG+vt7Jyamlc9q6devWOTo6ajSakpKSCRMmHDt2zGDNkSNH \n jP/EpkyZAiA1NbXpS+Jw/tbbWbFihZ+fX1VVlSAIVVVVfn5+q1at0t8gJSUFwNSpU9tziF3n2rVr \n 0dHRUql09erVWq22a3Y
" text/plain " : [
" <IPython.core.display.Image object> "
]
} ,
" execution_count " : 30 ,
" metadata " : {
" image/png " : {
" width " : 1000
}
} ,
" output_type " : " execute_result "
}
] ,
" source " : [
" pydotprint(cost_and_perform_updates, outfile= ' pydotprint_cost_and_perform_updates.png ' ) \n " ,
" Image( ' pydotprint_cost_and_perform_updates.png ' , width=1000) "
]
} ,
{
" cell_type " : " markdown " ,
" metadata " : { } ,
" source " : [
" # Advanced Topics \n " ,
" ## Extending Theano \n " ,
" ### The easy way: Python "
]
} ,
{
" cell_type " : " code " ,
" execution_count " : 31 ,
" metadata " : {
" collapsed " : false
} ,
" outputs " : [ ] ,
" source " : [
" import theano \n " ,
" import numpy \n " ,
" from theano.compile.ops import as_op \n " ,
" \n " ,
" def infer_shape_numpy_dot(node, input_shapes): \n " ,
" ashp, bshp = input_shapes \n " ,
" return [ashp[:-1] + bshp[-1:]] \n " ,
" \n " ,
" @as_op(itypes=[theano.tensor.fmatrix, theano.tensor.fmatrix], \n " ,
" otypes=[theano.tensor.fmatrix], infer_shape=infer_shape_numpy_dot) \n " ,
" def numpy_dot(a, b): \n " ,
" return numpy.dot(a, b) "
]
}
] ,
" metadata " : {
" kernelspec " : {
" display_name " : " Python 3 " ,
" language " : " python " ,
" name " : " python3 "
} ,
" language_info " : {
" codemirror_mode " : {
" name " : " ipython " ,
" version " : 3
} ,
" file_extension " : " .py " ,
" mimetype " : " text/x-python " ,
" name " : " python " ,
" nbconvert_exporter " : " python " ,
" pygments_lexer " : " ipython3 " ,
" version " : " 3.4.3 "
}
} ,
" nbformat " : 4 ,
" nbformat_minor " : 0
}