def tag_dropout(self, variables, rng=None, **hyperparameters): from blocks.roles import INPUT from blocks.filter import VariableFilter bricks_ = [brick for brick in util.all_bricks([self.mlp]) if isinstance(brick, bricks.Linear)] variables = (VariableFilter(roles=[INPUT], bricks=bricks_) (theano.gof.graph.ancestors(variables))) graph.add_transform( variables, graph.DropoutTransform("classifier_dropout", rng=rng), reason="regularization")
def tag_dropout(self, variables, rng=None, **hyperparameters): from blocks.roles import INPUT from blocks.filter import VariableFilter rng = util.get_rng(seed=1) bricks_ = [brick for brick in util.all_bricks(self.emitters) if isinstance(brick, bricks.Linear)] variables = (VariableFilter(roles=[INPUT], bricks=bricks_) (theano.gof.graph.ancestors(variables))) graph.add_transform( variables, graph.DropoutTransform("classifier_dropout", rng=rng), reason="regularization")
def tag_attention_dropout(self, variables, rng=None, **hyperparameters): from blocks.roles import INPUT, has_roles bricks_ = [ brick for brick in util.all_bricks([self.patch_transform]) if isinstance(brick, (bricks.Linear, conv2d.Convolutional, conv3d.Convolutional)) ] variables = [ var for var in graph.deep_ancestors(variables) if (has_roles(var, [INPUT]) and any(brick in var.tag.annotations for brick in bricks_)) ] graph.add_transform(variables, graph.DropoutTransform("attention_dropout", rng=rng), reason="regularization")