Difficulty: Medium Tags: Transformers, Positional Encoding, Sequence Models
A document transformer must add sinusoidal positional encodings to token embeddings. A refactor mistakenly uses the feature index where the pair index belongs, shifting every frequency and degrading long-document retrieval.
For position pos and embedding dimension index i (0 <= i < d),
with k = i // 2:
PE(pos, 2k) = sin(pos / 10000^(2k/d))
PE(pos, 2k+1) = cos(pos / 10000^(2k/d))
For an odd d, the final even-indexed component is still defined by
the sine formula.
pos (int), d (int).
List of d positional-encoding components in index order (6 decimal
places).
0 <= pos <= 10^9, 1 <= d <= 512.Input
pos = 1, d = 4
Output
[0.841471, 0.540302, 0.010000, 0.999950]
Explanation: For d=4, the first pair uses angle 1; the second
pair uses angle 1/100, so its sine and cosine are approximately
0.010000 and 0.999950.
No results yet
Run your code to check it against the examples, or submit to run every test.