Concepts / SPLADE and Sparse Embeddings

SPLADE and Sparse Embeddings

The definition turns on the word majority. A vector does not need every value to be 0 to count as sparse, and it does not need every value to be non-zero to count as dense. What matters is which side holds more of the entries.

  • Programming

Testing a Common Shortcut

When you first meet the words sparse and dense in retrieval, it is tempting to form a quick rule: anything produced by a neural model is dense, and anything built from keywords is sparse. The rule feels reasonable. Embeddings are the famous output of neural models, and keyword matching is the famous older method. But the rule is a misconception, and this article is organized around testing it. You will see that the sparse versus dense question and the term-based versus embedding-based question are two different questions, and that SPLADE is a case where the answers do not line up with the shortcut.

Predicting What SPLADE Produces

Before reading the definitions closely, commit to an answer. SPLADE is described as an embedding-based retrieval algorithm, and embeddings are often assumed to be dense. Make your guess first, then read on.

What do you think happens?

SPLADE is described as an embedding-based retrieval algorithm. Are the vectors it produces dense or sparse?

  • Dense

  • Sparse

Reveal answer
Answer:

Sparse

SPLADE is an embedding-based algorithm that uses sparse embeddings. Its embeddings are pushed by regularization so that most values are 0. Being embedding-based does not force a method to be dense. The rest of this article explains how that works.

Sparse and Dense by the Share of Zeros

Definition

A sparse vector is one where the majority of the values are 0. A dense vector is one where the majority of the values are not 0.

Key point

The definition turns on the word majority. A vector does not need every value to be 0 to count as sparse, and it does not need every value to be non-zero to count as dense. What matters is which side holds more of the entries.

This means two vectors of the same length can land on opposite sides of the line depending only on how many of their entries are zero. Retrieval systems use this distinction in their naming. Sparse retrievers represent data using sparse vectors, and dense retrievers represent data using dense vectors. Each family is therefore described by the kind of vector it relies on.

0sparse vector0.7dense vector1sparse vector0.2dense vector0sparse vector0.9dense vector0sparse vector0dense vector
How do a mostly-zero vector and a mostly-nonzero vector differ when their values are laid out side by side? Both vectors have length four; only the count of zeros changes which side of the line each falls on.

Building a One-Hot Vector

The clearest sparse vector is the one-hot vector. It is defined as a vector that is 0 everywhere except for a single value of 1. Its length equals the size of the vocabulary, and the 1 sits at the index that matches the position of the term in the vocabulary. Term-based retrieval is considered sparse because each term can be represented this way.

Worked example

One-Hot Vector for dog in a Four-Term Vocabulary

A small system knows four terms, indexed as cat at 0, dog at 1, fish at 2, and bird at 3. Write the one-hot vector for dog and decide whether it is sparse.

  1. 1
    Set the length

    The vocabulary has four terms, so the vector has length 4.

  2. 2
    Find the index

    dog is at index 1 in the vocabulary.

  3. 3
    Place the single 1

    Put a 1 at index 1 and 0 everywhere else, giving [0, 1, 0, 0].

  4. 4
    Count the zeros

    Three of the four values are 0, which is $\frac{3}{4}$ of the entries.

  5. 5
    Classify

    Zeros form the majority, so the vector is sparse.

Result

The one-hot vector for dog is [0, 1, 0, 0]. It is sparse because $\frac{3}{4}$ of its values are 0.

catindex 0 holds 0dogindex 1 holds 1fishindex 2 holds 0birdindex 3 holds 0next indexnext indexnext index
Which position in the vector is the 1, and how does that position correspond to a specific word in the vocabulary? Each index matches one term, and only the index for dog holds the 1.

Notice what happens as the vocabulary grows. The vector length rises with the number of terms, but each one-hot vector still contains only one 1. Its share of zeros climbs toward everything, which is why one-hot vectors are a clean illustration of sparsity.

Why Sparse Is Not the Same Question as Term-Based

The contrast becomes clearer when the two kinds of vector sit next to each other. Sparse vectors have a majority of zero values, and the one-hot vector is a concrete case of that pattern. Dense vectors have a majority of non-zero values, and embedding-based retrieval is typically dense because embeddings are generally dense vectors.

There is a second axis, and it is separate from the first. Term-based versus embedding-based describes the family a method belongs to. Sparse versus dense describes the values inside the vectors that method produces. Keyword-based search is the most direct example of term-based retrieval. Given the query AI engineering, the system retrieves all documents that contain AI engineering. The source calls this lexical retrieval, and it belongs to the term-based side, which is why it is treated as a sparse method.

Lexical retrievalkeyword matching, typicallysparseDense retrievalembeddings, typically denseSPLADEembeddings, sparse
Why does a method count as sparse or dense on one axis while being term-based or embedding-based on a different axis, and where do common methods fall? Columns group methods by family; the sublabel shows where each method falls on the sparse versus dense axis.

The two columns describe the typical pattern of each family, and the pattern has exceptions. That exception is the reason SPLADE needs its own discussion.

How SPLADE Ends Up Sparse

SPLADE, which stands for Sparse Lexical and Expansion, is a retrieval algorithm that works using sparse embeddings. It leverages embeddings generated by BERT, but it applies regularization that pushes most embedding values to 0. The sparsity that results makes embedding operations more efficient.

Input texta query or documentBERT embeddingsembeddings generated byBERTRegularizationpushes most values to 0Sparse embeddingmost values are 0encoded byregularizedyields
How does text pass through the model and come out with most of its entries at zero? The embedding is produced first, and regularization then pushes most of its values to 0.

The starting point is an embedding, and embeddings are generally dense. The regularization step is what changes the outcome. Because it pushes most values to 0, the final vector falls on the sparse side of the majority definition. SPLADE is therefore a sparse embedding method even though embeddings are involved.

Mistakes Beginners Make

  • Common mistake

    Treating every neural output as dense

    What it looks like

    Concluding that SPLADE must produce dense vectors because it is an embedding-based method.

    Why it fails

    Sparse versus dense describes the values inside a vector, not the model family that produced it. SPLADE uses embeddings, but regularization pushes most of them to 0.

    Do this instead

    Check the share of zero values in the vector itself before assigning the sparse or dense label.

  • Common mistake

    Assuming a vector must be entirely zeros to be sparse

    What it looks like

    Refusing to call [0, 1, 0, 0] sparse because it contains a 1.

    Why it fails

    The definition uses the word majority. Three of four values being 0 is enough.

    Do this instead

    Count the zeros and ask whether they make up the majority of the entries.

  • Common mistake

    Confusing the sparse-dense axis with the term-based-embedding axis

    What it looks like

    Saying keyword search is sparse, so every sparse method must be term-based.

    Why it fails

    The two axes are independent. SPLADE is sparse but embedding-based.

    Do this instead

    Answer two separate questions: what family the method belongs to, and what kind of vector it produces.

  • Common mistake

    Forgetting that a one-hot vector's length equals the vocabulary size

Practice with a Five-Term Vocabulary

EASY

A system knows five terms indexed as apple at 0, banana at 1, carrot at 2, date at 3, and egg at 4. Write the one-hot vector for egg. Then state how many of its values are 0, and whether it is sparse or dense.

Hints
  • The vector has length 5, one entry per term.
  • egg is at index 4, so the single 1 goes in the last position.
  • Four of the five values are 0, which is the majority.

Key Takeaways

  • A sparse vector has a majority of values equal to 0, and a dense vector has a majority of values that are not 0.
  • A one-hot vector is a sparse vector with a single 1 at the index of a term, and its length equals the vocabulary size.
  • Sparse versus dense describes the values inside a vector, which is a different question from whether a method is term-based or embedding-based.
  • SPLADE is an embedding-based algorithm that uses sparse embeddings, because regularization pushes most of its embedding values to 0.

More concepts starting with S