From 9ff3d163609707c0138c0de731eec40449bd1815 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Wed, 13 May 2015 16:29:25 -0400 Subject: Add support for dropout in joint model --- model/joint_simple_mlp_tgtcls.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/model/joint_simple_mlp_tgtcls.py b/model/joint_simple_mlp_tgtcls.py index dd1242e..834afbf 100644 --- a/model/joint_simple_mlp_tgtcls.py +++ b/model/joint_simple_mlp_tgtcls.py @@ -1,6 +1,9 @@ from blocks.bricks import MLP, Rectifier, Linear, Sigmoid, Identity, Softmax from blocks.bricks.lookup import LookupTable +from blocks.filter import VariableFilter +from blocks.graph import ComputationGraph, apply_dropout + import numpy import theano from theano import tensor @@ -74,6 +77,18 @@ class Model(object): time_scost.name = 'time_scost' cost = dest_cost + time_scost + + if hasattr(config, 'dropout_p'): + cg = ComputationGraph(cost) + dropout_inputs = VariableFilter( + bricks=[b for b in list(common_mlp.children) + + list(dest_mlp.children) + + list(time_mlp.children) + if isinstance(b, Rectifier)], + name='output')(cg) + cg = apply_dropout(cg, dropout_inputs, config.dropout_p) + cost = cg.outputs[0] + cost.name = 'cost' # Initialization -- cgit v1.2.3