Feature hashing, also known as the hashing trick, is a dimensionality reduction technique that maps arbitrary categorical features to a fixed-size vector using a hash function. It eliminates the need for a vocabulary dictionary by deterministically assigning each feature value to a column index, trading potential hash collisions for a bounded, predictable memory footprint during both training and inference.
Glossary
Feature Hashing

What is Feature Hashing?
A technique for mapping high-cardinality categorical variables to a fixed-size vector space without maintaining a vocabulary lookup table.
In streaming or online learning environments where new categories appear continuously, feature hashing prevents the memory blowup associated with one-hot encoding. The MurmurHash or xxHash functions are commonly used for their speed and uniform distribution properties. While collisions introduce a small amount of noise, signed hash functions can mitigate this by subtracting counts for negative assignments, preserving the expected dot product between vectors.
Key Characteristics of Feature Hashing
Feature hashing, also known as the hashing trick, is a fast and space-efficient method for vectorizing high-cardinality categorical features without maintaining a vocabulary. It maps an arbitrary number of features to a fixed-size vector using a hash function, trading potential collisions for a bounded memory footprint.
Vocabulary-Free Vectorization
Unlike one-hot encoding, feature hashing does not require a pre-built vocabulary or dictionary mapping string values to indices. The hash function computes the index directly from the raw feature value. This eliminates the memory overhead of storing a vocabulary and the engineering complexity of handling out-of-vocabulary (OOV) inputs during inference. Any new categorical value encountered in production is immediately mapped to a bucket without model updates.
Dimensionality Control via Modulo
The output dimensionality is fixed and user-defined by specifying the number of hash buckets (e.g., 2^18). The hash function maps an input to an integer, and the modulo operation (hash(x) % D) constrains it to the pre-allocated vector size. This guarantees a strict, predictable memory budget regardless of the cardinality of the input feature, making it ideal for streaming and online learning environments where feature cardinality is unbounded.
Collision Handling
Multiple distinct input features can map to the same hash bucket, creating a collision. This is the primary trade-off of feature hashing. The signed hash trick mitigates this by using a second hash function to determine the sign (+1 or -1) of the feature value, allowing collisions to partially cancel out in linear models. While collisions introduce noise, the impact is often negligible in high-dimensional settings with sparse features.
Stateless and Parallelizable
The transformation is stateless—each feature is hashed independently without requiring global aggregation or coordination. This makes feature hashing embarrassingly parallelizable across distributed computing frameworks like Apache Spark. There is no need to synchronize a shared vocabulary across worker nodes, significantly simplifying distributed feature engineering pipelines.
Common Hash Functions
The MurmurHash3 algorithm is the most widely used non-cryptographic hash function for feature hashing due to its excellent distribution properties and speed. In practice, many implementations use a 32-bit or 64-bit variant. The signed hash trick often employs a second hash function, such as the Jenkins hash, to determine the sign bit, ensuring that collisions are not purely additive.
Applications in Text and Categorical Data
Feature hashing is a cornerstone of the Vowpal Wabbit online learning system and is widely used in:
- Text classification: Hashing n-gram features to avoid storing a massive term dictionary.
- Ad click prediction: Handling high-cardinality categorical features like ad IDs and user agents.
- Email spam filtering: Efficiently representing tokenized email content in a fixed-size feature space.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Frequently Asked Questions
Clear, technical answers to the most common questions about the hashing trick for high-cardinality categorical data in machine learning pipelines.
Feature hashing, also known as the hashing trick, is a dimensionality reduction technique that maps an arbitrary number of categorical features or tokens into a fixed-size vector of dimension D using a deterministic hash function. The mechanism works by applying a hash function h(x) → {1, 2, ..., D} to each feature name-value pair (e.g., city=London), computing the modulo of the hash with the target dimension, and incrementing the corresponding index in the output vector. A signed hash function is often employed, where a second hash determines the sign (+1 or -1) to mitigate collision bias through cancellation. This eliminates the need to maintain a vocabulary mapping in memory, making it ideal for streaming and online learning scenarios where the full feature space is unknown a priori. The trade-off is the introduction of hash collisions, where distinct features map to the same index, introducing a controlled amount of noise proportional to the inverse of the output dimension.
Related Terms
Core techniques and infrastructure components that interact with feature hashing in modern machine learning pipelines.
Dimensionality Reduction
The process of projecting high-dimensional data into a lower-dimensional space. Feature hashing is a stateless dimensionality reduction technique specifically for categorical variables, contrasting with data-driven methods like PCA or t-SNE which require learning a projection matrix from data. Hashing achieves reduction without any training phase, making it ideal for streaming contexts where the full feature vocabulary is unknown upfront.
Embedding Table
A parameter matrix storing dense vectors for each categorical feature value, enabling GPU-accelerated lookup. Feature hashing eliminates the need for an explicit embedding table by using a hash function to directly index into a fixed-size vector, avoiding the memory overhead of storing a vocabulary-to-index mapping. This is critical when dealing with high-cardinality features like user IDs or search queries where a full table would exceed memory budgets.
Cold-Start Embedding
A representation strategy for new entities with no historical data. Feature hashing naturally handles the cold-start problem for categorical features because the hash function can map any unseen string to a valid index without retraining. Unlike one-hot encoding, which fails on out-of-vocabulary values, hashing gracefully assigns new categories to existing slots, accepting potential collisions as a trade-off for universal coverage.
Streaming Data Pipelines
Event-driven architectures for ingesting real-time data. Feature hashing is a cornerstone of online feature engineering in streaming pipelines because it requires no vocabulary pre-computation or state maintenance. As raw events arrive, categorical fields can be immediately hashed into fixed-size vectors without consulting a feature store, enabling sub-millisecond transformation in Apache Kafka or Apache Flink workflows.
Negative Sampling
An efficient training approximation that updates only a small subset of negative examples. In recommendation systems using feature hashing, the hash collision property can inadvertently create shared representations between distinct items, acting as a form of implicit regularization. When combined with in-batch negative sampling, the collision-induced noise can improve generalization by preventing the model from memorizing rare feature combinations.
Product Quantization (PQ)
A vector compression technique that decomposes embedding space into quantized subspaces. While feature hashing reduces dimensionality at the input feature level, PQ operates at the learned representation level, compressing dense embeddings for efficient ANN retrieval. A complete pipeline often uses hashing to bound input feature size, then applies PQ to the resulting user or item embeddings for billion-scale similarity search.

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.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us