'Captures variables created by a function in |self._params|.
Args:
function: Function whose variables should be captured.  The function
should take one argument, its enclosing variable scope.'

def _capture_variables_as_params(self, function):

    created_vars = {}
    def _custom_getter(getter, *args, **kwargs):
        'Calls    the    real    getter    and    captures    its    result    in    |created_vars|.'
        real_variable = getter(*args, **kwargs)
        created_vars[real_variable.name] = real_variable
        return real_variable
    with tf.variable_scope('cell', reuse=None, custom_getter=_custom_getter) as scope:
        function(scope)
    self._params.extend(created_vars.values())
