import torch


def append_bias_ones(tensor):
    """Appends vector of ones to last dimension of tensor.

    For examples, if the input is of shape [4, 6], then the outputs has shape
    [4, 7] where the slice [:, -1] is a tensor of all ones.
    """
    shape = list(tensor.shape[:-1]) + [1]
    return torch.cat([tensor, tensor.new_ones(shape)], dim=-1)