def unbroadcast_tfe_to(tensor, shape):
  """Reverse the broadcasting operation.

  See utils.py.

  Args:
    tensor: A Tensor.
    shape: A shape that could have been broadcasted to the shape of tensor.

  Returns:
    Tensor with dimensions summed to match `shape`.
  """
  axis = utils.create_unbroadcast_axis(shape, shape_as_list(tensor))
  return tf.reshape(tf.reduce_sum(tensor, axis=axis), shape)