Programming, Artificial Intelligence, Machine Learning, Data Science, Python.
torch.exp(torch.arange(0, embedding_dimension, 2).float() * (-math.log(10000.0) / embedding_dimension)) positional_encodings[:, 0::2] = torch.sin(positions * div_term) positional_encodings[:, 1::2] = torch.cos(positions * div_term) positional_encodings =