import torch


def get_padded_tensor(tensor, n_padding, padding_index, special_embedding, front =True):
    """
    Args:
        tensor (torch.Tensor): tensor to be padded
        n_padding (int): padding nums
        padding_index (int): which chars to use:  (0-SOS 1-NULL 2-UNK 3-EOS)
        special_embedding (torch.Tensor): embedding tensor of 4 special chars
        front (bool): pad front or end

    Returns:
         padded_tensor (torch.Tensor)
    """
    if tensor == 'NULL':
        return special_embedding[1].repeat(n_padding,1)

    padding_tensor = special_embedding[padding_index].repeat(n_padding,1)
    padded_tensor = torch.cat((padding_tensor, tensor), dim=0) if front \
        else torch.cat((tensor, padding_tensor), dim = 0)

    return padded_tensor