AI Glossary / AI and machine learning / Advanced

Feature hashing

Definition

Feature hashing is a trick for turning huge or open-ended sets of values into a fixed number of numeric columns, by passing each value through a hash function that assigns it a slot.

What it means

Some fields have too many values to encode honestly: every word in a language, every user agent string, every product SKU. One column per value means millions of mostly-empty columns, and new values arrive daily.

Feature hashing picks a table size, say a million slots, and hashes each value to a slot number, setting that slot. The vocabulary problem disappears: any value, seen before or not, lands somewhere in the fixed table.

The price is collisions: different values occasionally share a slot, and the model cannot tell them apart. In practice, with a big enough table, collisions are rare enough that their damage is small, and the convenience is enormous.

Hashing needs no stored vocabulary, which makes it stateless: the same value always hashes to the same slot, so training and serving agree without exchanging a dictionary.

For a business, hashing sits inside high-volume text and clickstream systems. You will rarely choose it directly, but it explains how vendors handle open-ended fields at scale without the storage collapsing.

Because the scheme is stateless, it travels well across systems: any machine anywhere can hash the same value to the same slot, which is why hashing suits distributed processing where exchanging dictionaries would be a bottleneck.

How it works

Choose the table size: larger tables mean fewer collisions and more memory, and the right size is found by validation.

Hash each incoming value to a slot index with a stable hash function, the same function everywhere, forever.

Set or increment the slot for each occurrence, producing a fixed-length vector from any amount of input.

Optionally use a second hash for the sign, which makes collisions cancel statistically rather than systematically.

Accept that the representation is one-way: you cannot reliably list which values landed in a slot, so keep the raw data if you will ever need to audit.

Three practical examples

  • Spam filtering: hashing every word and token pair into a fixed table, so new slang works immediately.
  • Ad click prediction: hashing user, page and campaign identifiers into shared slot spaces.
  • Log analysis: hashing open-ended event attributes into fixed-width inputs for anomaly models.

Think of it this way

Think of an enormous post office with exactly one million boxes. Every name that arrives, known or new, is assigned a box by formula. Occasionally two people share a box and their letters mix, but with a million boxes and honest mixing, it rarely matters.

The limit: when it does matter, you cannot unmix the letters. Hashing trades the ability to say exactly which value was seen for the ability to handle any value at all.

Worked example

hashing a clickstream

Suppose an ad platform logs 40 million events a day with millions of distinct page and user identifiers. The figures are illustrative.

A vocabulary-based encoding would need a dictionary that never stops growing and a lookup that must stay consistent between training and serving.

Feature hashing maps every identifier into a four-million-slot table, no dictionary, no lookup, and new identifiers work the moment they appear.

Measured collisions affect a small fraction of events, and held-out accuracy matches the vocabulary approach within noise.

Illustrative case study

A fictional security team hashed server log fields into an anomaly model and was baffled when two specific servers could never be told apart by the alerts.

The two hostnames collided in the hash table: same slot, same pattern, forever conflated.

The invented lesson: collisions are rare and permanent. A collided pair of important values stays collided until the table size or hash changes.

Common misconceptions and mistakes

  • Hashing compresses data losslessly. It is lossy by design; collisions merge values irreversibly, which is the price of the fixed size.
  • Bigger tables eliminate collisions. They reduce the rate; the birthday arithmetic means collisions survive at any practical size.
  • Hashed features are interpretable. Individual slots cannot be traced back to values, so explanation happens at a coarser level.

Business use

Use hashing for open-ended, high-cardinality fields at scale, and vocabulary encodings where auditability matters more.

Keep raw values in the event log even when models see only hashes, so investigations can reconstruct what the slots hid.

When a hashed model misbehaves on specific entities, suspect a collision and test by remapping those values explicitly.

When a vendor mentions hashing for your high-cardinality fields, ask about table size and collision handling; the answers reveal whether the approach was tuned or defaulted.

People also ask

What is a hash collision here?

Two different values assigned to the same slot, after which the model treats them as identical.

Why the signed variant?

Adding a random plus or minus per value makes collision effects cancel out statistically across many examples.

Is hashing used in deep learning?

Yes, for embedding large vocabularies compactly, though learned embeddings with a capped vocabulary are the common alternative.

When is hashing the wrong choice?

When you must explain individual feature contributions or audit exactly which values the model saw; hashing is one-way.

Check your understanding

Why does feature hashing not need a stored vocabulary when one-hot encoding does?

Answer: Because the slot for any value is computed from the value itself by the hash function, so training and serving agree without exchanging any list of known values.

Related terms

  • One-hot encoding
  • Feature engineering
  • Hash function
  • Embedding
  • Sparsity
  • high cardinality

Learn next

AI for Business Owners helps you weigh scale tricks against auditability when your data fields grow without bound: https://aiforbusinessandlife.com/academy/ai-for-business-owners. [C2]

More in AI and machine learning

  • Feature extractor - A feature extractor is the component that converts raw input into feature values: the fixed recipe, pipeline stage or trained network that stands between...
  • Feature Freshness - Feature freshness is how up to date a model's input values are: the gap between what the data says and what is true right now.
  • Feature Function - A feature function is the reusable piece of logic that computes one feature from raw data: given the inputs, here is exactly how this field gets its value.
  • Feature interactions - Feature interactions are the ways two or more input fields affect the outcome jointly, so that the effect of one depends on the value of another.
  • Feature learning - Feature learning is letting a model discover the useful input representations itself from raw data, instead of a person designing the features by hand.
  • Feature map - A feature map is the output produced when a learned detector is applied across an input, such as the grid of responses an edge detector leaves at every...

Sources

[S14] KNIME, Data Science Glossary. Full URLs are in the source ledger. Verified 11 October 2026.

Previous: Feature Function Next: Feature interactions

  • Home
  • Daily AI Updates
  • Blog
  • AIFBL Academy
  • AI Glossary
  • Products and Tools
  • Store
  • Free CFO AI Prompt Pack
  • About Shihan Sheriff
  • Privacy Policy
  • Terms of Use
  • Refund Policy
  • Cookie Policy
  • Earnings Disclaimer