Inferensys

Glossary

Positional Encoding

Positional encoding is a technique that maps low-dimensional input coordinates into a higher-dimensional space using sinusoidal functions, enabling neural networks to learn high-frequency details in signals like images and 3D scenes.
Finance professional using AI FP&A copilot on laptop, board presentation visible on screen, home office work session.
NEURAL SCENE REPRESENTATIONS

What is Positional Encoding?

Positional encoding is a foundational technique in neural scene representation and transformer architectures that enables models to process positional information from continuous input coordinates.

Positional encoding is a deterministic, fixed function that maps low-dimensional, continuous input coordinates—such as a 3D location (x, y, z) or a 1D sequence position—into a higher-dimensional space using a set of sinusoidal functions. This transformation is critical because standard coordinate-based MLPs are biased towards learning low-frequency functions, a phenomenon known as spectral bias. By projecting inputs into a higher-dimensional space with explicit frequency components, positional encoding allows the network to more easily model the high-frequency details present in signals like images, audio, and 3D geometry.

In the context of Neural Radiance Fields (NeRF), positional encoding is applied to the 3D spatial coordinates and 2D viewing direction before they are fed into the MLP. This enables the network to represent fine details like texture and sharp edges. The technique is also fundamental to transformer models, where it provides sequence order information to an otherwise permutation-invariant architecture. Common variants include the sinusoidal encoding from the original transformer paper and learned, parametric encodings used in models like BERT.

MECHANISM

Key Characteristics of Positional Encoding

Positional encoding is a deterministic, non-learned function that maps low-dimensional coordinates into a higher-dimensional space to provide sequence or spatial order information to models that lack an inherent sense of position.

01

Sinusoidal Basis Functions

The original formulation, introduced in the Transformer architecture 'Attention Is All You Need,' uses a set of sine and cosine functions at geometrically increasing frequencies. For a position pos and dimension i, the encoding is:

  • Even indices: sin(pos / 10000^(2i/d_model))
  • Odd indices: cos(pos / 10000^(2i/d_model)) This design ensures that each position has a unique encoding and that the model can learn to attend to relative positions through linear transformations of these sinusoidal patterns.
02

High-Frequency Signal Learning

A core motivation in neural graphics is to overcome spectral bias or the 'frequency principle,' where standard MLPs preferentially learn low-frequency components of a target signal. By projecting coordinates into a high-dimensional space with explicit high-frequency components, positional encoding enables the MLP to approximate fine details like sharp edges, textures, and high-frequency color variations in images and 3D scenes that it would otherwise smooth over.

03

Non-Learned vs. Learned Embeddings

Non-learned (Fixed) Encoding: Uses a deterministic function (e.g., sinusoids, random Fourier features). It is simple, generalizes to any sequence length, and has theoretical properties for representing relative position.

Learned (Positional) Embeddings: Treats each position index as a token and learns a dense embedding vector, as in BERT's initial token embeddings. While flexible, it is limited to a predefined maximum sequence length and lacks inherent structural biases for extrapolation.

In neural scene representations like NeRF, fixed encodings are standard as they must handle continuous, unseen 3D coordinates at inference.

04

Generalization to Higher Dimensions

For 3D neural fields (NeRF, SDFs), positional encoding is applied independently to each coordinate (x, y, z). A 3D point (x, y, z) is encoded by concatenating the sinusoidal encodings for each axis. This allows the network to resolve high-frequency spatial structure in all dimensions. Viewing direction (θ, φ) is often encoded separately at a different frequency band to capture view-dependent effects like specular highlights.

05

Relation to Fourier Features & Kernel Regression

Sinusoidal positional encoding is a specific case of random Fourier feature mapping. According to the neural tangent kernel theory, passing inputs through a random Fourier feature layer shifts the network's effective kernel towards a stationary kernel, improving convergence for learning high-frequency functions. This formalizes why the technique is so effective: it pre-conditiones the model's inductive bias to better fit complex signals.

06

Advanced Parametric Encodings

Modern neural graphics primitives often replace pure sinusoidal encoding with more efficient parametric mappings:

  • Hash Encoding (InstantNGP): Uses a multi-resolution hash table of learnable feature vectors. Provides extremely fast lookup and high-quality reconstruction.
  • Spherical Harmonics: Used for encoding viewing directions to compactly represent low-frequency, view-dependent appearance.
  • Integrated Positional Encoding (IPE): Used in Mip-NeRF, it encodes not a point but the expected statistics of a conical frustum, enabling anti-aliased rendering by modeling volumetric sampling. These methods retain the core goal of mapping coordinates to a richer feature space but do so with learned, memory-efficient data structures.
INPUT ENCODING COMPARISON

Positional Encoding vs. Alternative Input Encoding Techniques

A comparison of techniques for mapping low-dimensional coordinates into a feature space suitable for neural networks in 3D scene representation and graphics.

Encoding FeaturePositional Encoding (Fourier Features)Hash Encoding (Instant NGP)Learned Feature Grid (Plenoxels, TensoRF)Parametric Encoding (SIREN)

Core Mechanism

Predefined sinusoidal projection: γ(p) = [sin(2^0πp), cos(2^0πp), ..., sin(2^{L-1}πp), cos(2^{L-1}πp)]

Multi-resolution hash table lookup with spatial hashing and learnable feature vectors

Explicit, multi-resolution voxel grid storing learnable feature vectors or basis coefficients

Neural network with periodic sine activations: φ(p) = sin(ωWp + b)

Representation Type

Implicit, functional mapping

Hybrid (explicit hash table + implicit MLP)

Explicit, grid-based

Implicit, parametric network

Primary Use Case

Enabling MLPs to learn high-frequency details in signals (original NeRF, INR)

Real-time training and rendering of complex neural graphics primitives

Fast, grid-based optimization for view synthesis and reconstruction

Accurate modeling of signals and their derivatives (e.g., SDFs, wave functions)

Memory Efficiency

High (no stored parameters beyond MLP weights)

Very High (compact hash table, controlled size)

Low to Medium (scales with grid resolution^3)

High (only network parameters)

Training Speed

Slow (requires many MLP evaluations)

Very Fast (fast feature lookup, small MLP)

Fast (explicit gradients from grid)

Slow (requires careful initialization and training)

Rendering Speed (Inference)

Slow (full MLP forward pass per sample)

Very Fast (real-time capable)

Fast (pre-computed, can be baked)

Slow (full MLP forward pass per sample)

Inductive Bias

Band-limited spectral bias; promotes learning smooth interpolations

Local, multi-scale feature bias; excels at detail

Local, piecewise-constant/piecewise-linear bias

Strong prior for representing natural signals and derivatives

Handles Unbounded Scenes

Yes (coordinates are projected directly)

Requires spatial decomposition (e.g., octrees) for large scenes

Poor (grid must cover entire volume)

Yes (coordinates are input directly)

Gradient Quality

Explicit, smooth gradients

Good, but hash collisions can introduce noise

Explicit, grid-based gradients

High-quality, analytically defined derivatives

Parameter Count

Fixed by encoding dimension L

Fixed by hash table size and MLP

Grows with grid resolution and feature channels

Fixed by network architecture

Compression Potential

Low (MLP is already compact)

High (hash table is efficient, can be quantized)

Medium (grids can be sparse or factorized)

Low (network weights are dense)

POSITIONAL ENCODING

Frequently Asked Questions

Positional encoding is a critical technique in neural scene representation and modern transformer architectures. These questions address its core mechanisms, applications, and relationship to other concepts in 3D deep learning and spatial computing.

Positional encoding is a technique that transforms low-dimensional, continuous input coordinates (like a 3D location (x, y, z) or a 1D sequence position) into a higher-dimensional feature vector using a set of predefined, typically sinusoidal, functions. It works by applying a set of sine and cosine waves at different frequencies to each input dimension. For a scalar input p, the encoding for frequency i is: [sin(2π * p * base^(-2i/d)), cos(2π * p * base^(-2i/d))], where d is the output dimension and base is a scaling constant (often 10000). This creates a unique, structured code for every distinct position that a neural network can easily attend to and differentiate.

In neural scene representations like NeRF, positional encoding is applied to the 3D coordinates before they are fed into the coordinate-based MLP. This mapping is crucial because standard multilayer perceptrons (MLPs) are notoriously poor at learning high-frequency details in signals—a phenomenon known as spectral bias. By lifting coordinates into a higher-dimensional space rich with periodic structures, positional encoding provides the network with the necessary basis functions to represent fine details like texture, sharp edges, and complex geometry.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.