Sinusoidal Position Encoding › Key Parameters

Michael BrenndoerferUpdated June 6, 20252 min read
Language AI HandbookAll chapters
Part 14 of 67Positional Encoding
Chapter 97Sinusoidal Position Encoding › Key Parameters
Reading section 13 of 15 · Key Parameters · 2 minSection 13 of 15 · 2 min

Book contents

Section 13 of 15 · 2 min read

Sinusoidal Position Encoding › Key ParametersOne section · Sections in this chapter13 / 15 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

When implementing sinusoidal position encoding, the following parameters control the encoding behavior:

  • d_model: The dimension of the position encoding vectors, which must match the token embedding dimension. Larger values provide finer-grained positional discrimination because more dimension pairs are available to cover the full wavelength range. Common values range from 256 to 1024. If you use a model with d_model = 512, your position encodings have 256 dimension pairs, each contributing unique positional information at its own scale.

  • max_len: The maximum sequence length to pre-compute encodings for. Setting this higher than your longest expected sequence avoids runtime recomputation but increases memory usage. Typical values range from 512 to 8192 depending on the task. For inference on unexpectedly long inputs, the SinusoidalPositionEncoding class above will recompute encodings on demand.

  • Base constant (10000): The frequency scaling constant in the denominator. This value controls the range of wavelengths, from 2π2\pi at the fastest end to 2π×100002\pi \times 10000 at the slowest. The original transformer paper uses 10000, but some implementations experiment with different values. A smaller base compresses the wavelength range and may suit shorter sequences; a larger base spreads it out and may help with very long sequences. The value 10000 was chosen empirically to work well for typical NLP sequence lengths at the time.