Abstract
In many modern data science applications, we encounter matrices so large they cannot be stored in memory. These matrices are often presented as data streams or stored on disk, requiring space-efficient processing. A significant challenge arises when we need to compute a matrix decomposition not of the raw matrix $A$, but of an entry-wise transformed version $f(A) := (f(a_{i,j}))$. Such transformations, like the Pointwise Mutual Information (PMI) used in word embeddings, break the linearity required by standard sketching tools. This paper introduces a space-efficient sketching algorithm for computing the product of a transformed matrix with a smaller matrix. We demonstrate its utility by developing a low-rank approximation method that achieves high accuracy with minimal memory, validated through experiments on synthetic data and a multi-billion token Wikipedia corpus.
Introduction
In Natural Language Processing (NLP), algorithms often build word embeddings by analyzing a "co-occurrence matrix" that tracks the frequency of word pairs across massive datasets. Because these matrices are too large to fit in memory, they are typically processed as a stream of updates. However, standard linear algebraic tools like random projections fail when the objective is to factorize a transformed version of the data. For instance, calculating metrics like PMI requires applying a non-linear transformation—such as $\log(|x| + 1)$—to every entry.
Historically, researchers faced a binary choice: store the entire massive matrix in memory (often impossible) or design application-specific workarounds. This paper proposes a third way: a foundational sketching primitive that allows for complex linear algebra on a transformed matrix without ever storing the matrix itself.
Methodology
The Sketching Primitive
The core contribution is an algorithm that computes the matrix product $f(A)B$, where $A$ is a massive streaming matrix, $f$ is a non-linear transformation, and $B$ is a smaller, known matrix. The authors build this from the ground up:
- Vector Sketching: The problem is first addressed at the vector level by estimating the inner product of a known vector and a streaming, transformed vector. For logarithmic transformations, the authors design an algorithm acting as an $\ell_0$-sampler. Using a "K-set" data structure and hash functions with geometrically decreasing probabilities, the algorithm maintains a uniform sample of the non-zero elements of the vector as it is updated.
- Matrix Sketching: Since a matrix product is a series of vector inner products, the authors run these vector sketches in parallel to compute $f(A)B$.
Low-Rank Approximation
To find the top singular vectors of the massive matrix, the authors integrate their matrix sketch into a "generalized leverage score sampling" pipeline. The process involves:
- Using CountSketch to approximate the importance (leverage scores) of the columns.
- Sampling a subset of columns based on these scores.
- Applying adaptive sampling to refine the selection.
- Computing the singular vectors on this significantly reduced representation.
Experimental Evaluation
Datasets
The methodology was tested on both synthetic and real-world data:
- Synthetic Data (
LogDataandSqrtData): Matrices up to 50,000 x 50,000 were generated with Gaussian entries and transformed to test the limits of the sketching accuracy. - Real Data (Wikipedia Corpus): The authors processed the entire English Wikipedia dump (approximately 3 billion tokens) to build streaming word co-occurrence matrices for the top 10,000 to 50,000 most frequent words, mimicking a production NLP pipeline.
Key Results
The results demonstrate that non-linearities do not have to be a barrier to efficient sketching. By dynamically sampling only from the support (non-zero elements), the algorithm maintains low variance and high accuracy while using minimal memory.
- Memory Efficiency: On a 50,000 x 50,000 matrix, using memory equivalent to only 5% of the full matrix size yielded an error within 5% of the optimal singular vectors.
- Performance vs. Baselines: The method significantly outperformed uniform column sampling. The "error ratio" (the algorithm's error divided by the optimal possible error) remained near 1.0, while the uniform sampling baseline hovered around 4.0.
- Theoretical Soundness: The authors proved that their algorithm requires space proportional to $O(nk/\epsilon^2)$, a massive improvement over the $O(n^2)$ required to store the full matrix.
Conclusion and Future Work
By framing the solution as a way to compute $f(A)B$, the authors created a versatile, "black-box" tool. Any downstream algorithm that interacts with a massive matrix via matrix multiplication can now be made space-efficient.
While the sketching primitive operates in a single pass, the full low-rank approximation algorithm currently requires multiple passes to compute leverage scores and perform adaptive sampling. A primary direction for future research is the development of a strictly one-pass algorithm for the low-rank approximation of transformed matrices.
Summary updated