View source: R/positional-encodings.R
Gets a bunch of sinusoids of different frequencies. Each channel of the input Tensor is incremented by a sinusoid of a different frequency and phase. This allows attention to learn to use absolute and relative positions. Timing signals should be added to some precursors of both the query and the memory inputs to attention. The use of relative position is possible because sin(x+y) and cos(x+y) can be expressed in terms of y, sin(x) and cos(x). In particular, we use a geometric sequence of timescales starting with min_timescale and ending with max_timescale. The number of different timescales is equal to channels / 2. For each timescale, we generate the two sinusoidal signals sin(timestep/timescale) and cos(timestep/timescale). All of these sinusoids are concatenated in the channels dimension.
1 2 3 4 5 6 7 | get_timing_signal_1d(
length,
channels,
min_timescale = 1,
max_timescale = 10000,
start_index = 0
)
|
length |
scalar, length of timing signal sequence. |
channels |
scalar, size of timing embeddings to create. The number of different timescales is equal to channels / 2. |
min_timescale: |
a float |
max_timescale: |
a float |
start_index: |
index of first position |
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.