title: What's the purpose of keras.backend.function()
body: <p>The <a href="https://keras.io/backend/#function" rel="noreferrer">Keras manual</a> doesn't say too much:</p>
  
  <pre><code>keras.backend.function(inputs, outputs, updates=None)
  
  Instantiates a Keras function.
  Arguments
  inputs: List of placeholder tensors.
  outputs: List of output tensors.
  updates: List of update ops.
  **kwargs: Passed to tf.Session.run.
  Returns
  </code></pre>
  
  <p><a href="https://github.com/tensorflow/tensorflow/blob/r1.4/tensorflow/python/keras/_impl/keras/backend.py" rel="noreferrer">Tensorflow source code</a>, which is actually quite short, shows that K.function(...) return a Function object which, when called, evaluates the <em>outputs</em> and <em>updates</em> using the <em>inputs</em>. The interesting part is how it handles the updates which I don't follow. Any explanations/examples/pointers to help understanding this K.function(...) is appreciated! Here is the relevant part from <a href="https://github.com/tensorflow/tensorflow/blob/r1.4/tensorflow/python/keras/_impl/keras/backend.py" rel="noreferrer">Tensorflow source code</a></p>
  
  <pre><code>class Function(object):
    """Runs a computation graph.
    Arguments:
        inputs: Feed placeholders to the computation graph.
        outputs: Output tensors to fetch.
        updates: Additional update ops to be run at function call.
        name: a name to help users identify what this function does.
    """
  
    def __init__(self, inputs, outputs, updates=None, name=None,
                 **session_kwargs):
      updates = updates or []
      if not isinstance(inputs, (list, tuple)):
        raise TypeError('`inputs` to a TensorFlow backend function '
                        'should be a list or tuple.')
      if not isinstance(outputs, (list, tuple)):
        raise TypeError('`outputs` of a TensorFlow backend function '
                        'should be a list or tuple.')
      if not isinstance(updates, (list, tuple)):
        raise TypeError('`updates` in a TensorFlow backend function '
                        'should be a list or tuple.')
      self.inputs = list(inputs)
      self.outputs = list(outputs)
      with ops.control_dependencies(self.outputs):
        updates_ops = []
        for update in updates:
          if isinstance(update, tuple):
            p, new_p = update
            updates_ops.append(state_ops.assign(p, new_p))
          else:
            # assumed already an op
            updates_ops.append(update)
        self.updates_op = control_flow_ops.group(*updates_ops)
      self.name = name
      self.session_kwargs = session_kwargs
  
    def __call__(self, inputs):
      if not isinstance(inputs, (list, tuple)):
        raise TypeError('`inputs` should be a list or tuple.')
      feed_dict = {}
      for tensor, value in zip(self.inputs, inputs):
        if is_sparse(tensor):
          sparse_coo = value.tocoo()
          indices = np.concatenate((np.expand_dims(sparse_coo.row, 1),
                                    np.expand_dims(sparse_coo.col, 1)), 1)
          value = (indices, sparse_coo.data, sparse_coo.shape)
        feed_dict[tensor] = value
      session = get_session()
      updated = session.run(
          self.outputs + [self.updates_op],
          feed_dict=feed_dict,
          **self.session_kwargs)
      return updated[:len(self.outputs)]
  
  
  def function(inputs, outputs, updates=None, **kwargs):
    """Instantiates a Keras function.
    Arguments:
        inputs: List of placeholder tensors.
        outputs: List of output tensors.
        updates: List of update ops.
        **kwargs: Passed to `tf.Session.run`.
    Returns:
        Output values as Numpy arrays.
    Raises:
        ValueError: if invalid kwargs are passed in.
    """
    if kwargs:
      for key in kwargs:
        if (key not in tf_inspect.getargspec(session_module.Session.run)[0] and
            key not in tf_inspect.getargspec(Function.__init__)[0]):
          msg = ('Invalid argument "%s" passed to K.function with Tensorflow '
                 'backend') % key
          raise ValueError(msg)
    return Function(inputs, outputs, updates=updates, **kwargs)
  </code></pre>