def METHOD_NAME(seq_len, dim, pad_token=None):
    half = dim // 2
    sinusoid = torch.outer(
        torch.arange(seq_len, dtype=torch.float32),
        torch.pow(10000,
                  -torch.arange(half, dtype=torch.float32).div(half - 1)))
    x = torch.cat([torch.sin(sinusoid), torch.cos(sinusoid)], dim=1)
    if dim % 2 == 1:
        x = torch.cat([x, torch.zeros_like(x[:, :1])], dim=1)
    if pad_token is not None:
        x[pad_token, :] = 0
    return x