def itertrain(self, train, valid=None, **kwargs):
net = self.network<EOL>original = list(net.layers)<EOL>output_name = original[-<NUM_LIT:1>].output_name<EOL>tied = any(isinstance(l, layers.Tied) for l in original)<EOL>L = <NUM_LIT:1> + len(original) // <NUM_LIT:2> if tied else len(original) - <NUM_LIT:1><EOL>for i in range(<NUM_LIT:1>, L):<EOL><INDENT>tail = []<EOL>if i == L - <NUM_LIT:1>:<EOL><INDENT>net.layers = original<EOL><DEDENT>elif tied:<EOL><INDENT>net.layers = original[:i+<NUM_LIT:1>]<EOL>for j in range(i):<EOL><INDENT>prev = tail[-<NUM_LIT:1>] if tail else net.layers[-<NUM_LIT:1>]<EOL>tail.append(layers.Layer.build(<EOL>'<STR_LIT>', partner=original[i-j].name, inputs=prev.name))<EOL><DEDENT>net.layers = original[:i+<NUM_LIT:1>] + tail<EOL><DEDENT>else:<EOL><INDENT>tail.append(layers.Layer.build(<EOL>'<STR_LIT>',<EOL>name='<STR_LIT>',<EOL>inputs=original[i].output_name,<EOL>size=original[-<NUM_LIT:1>].output_size,<EOL>activation=original[-<NUM_LIT:1>].kwargs['<STR_LIT>']))<EOL>net.layers = original[:i+<NUM_LIT:1>] + tail<EOL><DEDENT>util.log('<STR_LIT>',<EOL>'<STR_LIT>'.join(l.name for l in net.layers))<EOL>[l.bind(net, initialize=False) for l in net.layers]<EOL>[l.setup() for l in tail]<EOL>net.losses[<NUM_LIT:0>].output_name = net.layers[-<NUM_LIT:1>].output_name<EOL>trainer = DownhillTrainer(self.algo, net)<EOL>for monitors in trainer.itertrain(train, valid, **kwargs):<EOL><INDENT>yield monitors<EOL><DEDENT><DEDENT>net.layers = original<EOL>net.losses[<NUM_LIT:0>].output_name = output_name<EOL>
Train a model using a training and validation set.

        This method yields a series of monitor values to the caller. After every
        iteration, a pair of monitor dictionaries is generated: one evaluated on
        the training dataset, and another evaluated on the validation dataset.
        The validation monitors might not be updated during every training
        iteration; in this case, the most recent validation monitors will be
        yielded along with the training monitors.

        Parameters
        ----------
        train : :class:`Dataset <theanets.dataset.Dataset>`
            A set of training data for computing updates to model parameters.
        valid : :class:`Dataset <theanets.dataset.Dataset>`
            A set of validation data for computing monitor values and
            determining when the loss has stopped improving.

        Yields
        ------
        training : dict
            A dictionary mapping monitor names to values, evaluated on the
            training dataset.
        validation : dict
            A dictionary containing monitor values evaluated on the validation
            dataset.