Tensor sketch explained

In statistics, machine learning and algorithms, a tensor sketch is a type of dimensionality reduction that is particularly efficient when applied to vectors that have tensor structure.[1] [2] Such a sketch can be used to speed up explicit kernel methods, bilinear pooling in neural networks and is a cornerstone in many numerical linear algebra algorithms.[3]

Mathematical definition

Mathematically, a dimensionality reduction or sketching matrix is a matrix

M\inRk

, where

k<d

, such that for any vector

x\inRd

|\|Mx\|2-\|x\|2|<\varepsilon\|x\|2

with high probability.In other words,

M

preserves the norm of vectors up to a small error.

A tensor sketch has the extra property that if

x=yz

for some vectors
d1
y\inR

,

d2
z\inR
such that

d1d2=d

, the transformation

M(yz)

can be computed more efficiently. Here

denotes the Kronecker product, rather than the outer product, though the two are related by a flattening.

The speedup is achieved by first rewriting

M(yz)=M'y\circM''z

, where

\circ

denotes the elementwise (Hadamard) product.Each of

M'y

and

M''z

can be computed in time

O(kd1)

and

O(kd2)

, respectively; including the Hadamard product gives overall time

O(d1d2+kd1+kd2)

. In most use cases this method is significantly faster than the full

M(yz)

requiring

O(kd)=O(kd1d2)

time.

For higher-order tensors, such as

x=yzt

, the savings are even more impressive.

History

The term tensor sketch was coined in 2013[4] describing a technique by Rasmus Pagh[5] from the same year.Originally it was understood using the fast Fourier transform to do fast convolution of count sketches.Later research works generalized it to a much larger class of dimensionality reductions via Tensor random embeddings.

Tensor random embeddings were introduced in 2010 in a paper[6] on differential privacy and were first analyzed by Rudelson et al. in 2012 in the context of sparse recovery.[7]

Avron et al.[8] were the first to study the subspace embedding properties of tensor sketches, particularly focused on applications to polynomial kernels.In this context, the sketch is required not only to preserve the norm of each individual vector with a certain probability but to preserve the norm of all vectors in each individual linear subspace.This is a much stronger property, and it requires larger sketch sizes, but it allows the kernel methods to be used very broadly as explored in the book by David Woodruff.

Tensor random projections

The face-splitting product is defined as the tensor products of the rows (was proposed by V. Slyusar[9] in 1996[10] [11] [12] [13] [14] for radar and digital antenna array applications).More directly, let

C\inR3 x

and

D\inR3 x

be two matrices.Then the face-splitting product

C\bulletD

is

C\bullD =\left[ \begin{array}{c} C1D1\\\hlineC2D2\\\hline C3D3\\ \end{array} \right] = \left[ \begin{array}{ccccccccc} C1,1D1,1&C1,1D1,2&C1,1D1,3&C1,2D1,1&C1,2D1,2&C1,2D1,3&C1,3D1,1&C1,3D1,2&C1,3D1,3\\\hline C2,1D2,1&C2,1D2,2&C2,1D2,3&C2,2D2,1&C2,2D2,2&C2,2D2,3&C2,3D2,1&C2,3D2,2&C2,3D2,3\\\hline C3,1D3,1&C3,1D3,2&C3,1D3,3&C3,2D3,1&C3,2D3,2&C3,2D3,3&C3,3D3,1&C3,3D3,2&C3,3D3,3\end{array} \right].

The reason this product is useful is the following identity:

(C\bullD)(xy)=Cx\circDy =\left[ \begin{array}{c} (Cx)1(Dy)1\\ (Cx)2(Dy)2\\ \vdots \end{array}\right],

where

\circ

is the element-wise (Hadamard) product.Since this operation can be computed in linear time,

C\bullD

can be multiplied on vectors with tensor structure much faster than normal matrices.

Construction with fast Fourier transform

The tensor sketch of Pham and Pagh[4] computes

C(1)x\astC(2)y

, where

C(1)

and

C(2)

are independent count sketch matrices and

\ast

is vector convolution.They show that, amazingly, this equals

C(xy)

– a count sketch of the tensor product!

It turns out that this relation can be seen in terms of the face-splitting product as

C(1)x\astC(2)y=lF-1(lFC(1)x\circlFC(2)y)

, where

lF

is the Fourier transform matrix.Since

lF

is an orthonormal matrix,

lF-1

doesn't impact the norm of

Cx

and may be ignored.What's left is that

C\simlC(1)\bulletlC(2)

.

On the other hand,

lF(C(1)x\astC(2)y)=lFC(1)x\circlFC(2)y=(lFC(1)\bulllFC(2))(xy)

.

Application to general matrices

The problem with the original tensor sketch algorithm was that it used count sketch matrices, which aren't always very good dimensionality reductions.

In 2020 it was shown that any matrices with random enough independent rows suffice to create a tensor sketch.This allows using matrices with stronger guarantees, such as real Gaussian Johnson Lindenstrauss matrices.

In particular, we get the following theorem

Consider a matrix

T

with i.i.d. rows

T1,...,Tm\inRd

, such that
2
E[(T
2
and
p]
E[(T
1x)

1/p\le\sqrt{ap}\|x\|2

. Let

T(1),...,T(c)

be independent consisting of

T

and

M=T(1)\bullet...\bulletT(c)

.

Then

|\|Mx\|2-\|x\|2|<\varepsilon\|x\|2

with probability

1-\delta

for any vector

x

if

m=(4a)2c\varepsilon-2log1/\delta+(2ae)\varepsilon-1(log1/\delta)c

.

In particular, if the entries of

T

are

\pm1

we get

m=O(\varepsilon-2log1/\delta+\varepsilon-1(\tfrac1clog1/\delta)c)

which matches the normal Johnson Lindenstrauss theorem of

m=O(\varepsilon-2log1/\delta)

when

\varepsilon

is small.

The paper also shows that the dependency on

\varepsilon-1(\tfrac1clog1/\delta)c

is necessary for constructions using tensor randomized projections with Gaussian entries.

Variations

Recursive construction

Because of the exponential dependency on

c

in tensor sketches based on the face-splitting product, a different approach was developed in 2020 which applies

M(xy ⊗ … ) =M(1)(x(M(2)y))

We can achieve such an

M

by letting

M=M(c)(M(c-1)

(c-2)
I
d)(M

I
d2

)(M(1)

I
dc-1

)

.

With this method, we only apply the general tensor sketch method to order 2 tensors, which avoids the exponential dependency in the number of rows.

It can be proved that combining

c

dimensionality reductions like this only increases

\varepsilon

by a factor

\sqrt{c}

.

Fast constructions

The fast Johnson–Lindenstrauss transform is a dimensionality reduction matrix

Given a matrix

M\inRk x

, computing the matrix vector product

Mx

takes

kd

time.The Fast Johnson Lindenstrauss Transform (FJLT),[15] was introduced by Ailon and Chazelle in 2006.

A version of this method takes

M=\operatorname{SHD}

where

D

is a diagonal matrix where each diagonal entry

Di,i

is

\pm1

independently.The matrix-vector multiplication

Dx

can be computed in

O(d)

time.

H

is a Hadamard matrix, which allows matrix-vector multiplication in time

O(dlogd)

S

is a

k x d

sampling matrix which is all zeros, except a single 1 in each row.

If the diagonal matrix is replaced by one which has a tensor product of

\pm1

values on the diagonal, instead of being fully independent, it is possible to compute

\operatorname{SHD}(xy)

fast.

For an example of this, let

\rho,\sigma\in\{-1,1\}2

be two independent

\pm1

vectors and let

D

be a diagonal matrix with

\rho\sigma

on the diagonal.We can then split up

\operatorname{SHD}(xy)

as follows:

\begin{align} &\operatorname{SHD}(xy) \\ &   = \begin{bmatrix} 1&0&0&0\\ 0&0&1&0\\ 0&1&0&0 \end{bmatrix} \begin{bmatrix} 1&1&1&1\\ 1&-1&1&-1\\ 1&1&-1&-1\\ 1&-1&-1&1 \end{bmatrix} \begin{bmatrix} \sigma1\rho1&0&0&0\\ 0&\sigma1\rho2&0&0\\ 0&0&\sigma2\rho1&0\\ 0&0&0&\sigma2\rho2\\ \end{bmatrix} \begin{bmatrix} x1y1\\ x2y1\\ x1y2\\ x2y2 \end{bmatrix} \\[5pt] &   = \left(\begin{bmatrix} 1&0\\ 0&1\\ 1&0 \end{bmatrix} \bullet \begin{bmatrix} 1&0\\ 1&0\\ 0&1 \end{bmatrix} \right) \left(\begin{bmatrix} 1&1\\ 1&-1 \end{bmatrix} \begin{bmatrix} 1&1\\ 1&-1 \end{bmatrix} \right) \left(\begin{bmatrix} \sigma1&0\\ 0&\sigma2\\ \end{bmatrix} \begin{bmatrix} \rho1&0\\ 0&\rho2\\ \end{bmatrix} \right) \left(\begin{bmatrix} x1\\ x2 \end{bmatrix} \begin{bmatrix} y1\\ y2 \end{bmatrix} \right) \\[5pt] &   = \left(\begin{bmatrix} 1&0\\ 0&1\\ 1&0 \end{bmatrix} \bullet \begin{bmatrix} 1&0\\ 1&0\\ 0&1 \end{bmatrix} \right) \left(\begin{bmatrix} 1&1\\ 1&-1 \end{bmatrix} \begin{bmatrix} \sigma1&0\\ 0&\sigma2\\ \end{bmatrix} \begin{bmatrix} x1\\ x2 \end{bmatrix} \begin{bmatrix} 1&1\\ 1&-1 \end{bmatrix} \begin{bmatrix} \rho1&0\\ 0&\rho2\\ \end{bmatrix} \begin{bmatrix} y1\\ y2 \end{bmatrix} \right) \\[5pt] &   = \begin{bmatrix} 1&0\\ 0&1\\ 1&0 \end{bmatrix} \begin{bmatrix} 1&1\\ 1&-1 \end{bmatrix} \begin{bmatrix} \sigma1&0\\ 0&\sigma2\\ \end{bmatrix} \begin{bmatrix} x1\\ x2 \end{bmatrix} \circ \begin{bmatrix} 1&0\\ 1&0\\ 0&1 \end{bmatrix} \begin{bmatrix} 1&1\\ 1&-1 \end{bmatrix} \begin{bmatrix} \rho1&0\\ 0&\rho2\\ \end{bmatrix} \begin{bmatrix} y1\\ y2 \end{bmatrix} . \end{align}

In other words,

\operatorname{SHD}=S(1)HD(1)\bulletS(2)HD(2)

, splits up into two Fast Johnson–Lindenstrauss transformations, and the total reduction takes time

O(d1logd1+d2logd2)

rather than

d1d2log(d1d2)

as with the direct approach.

The same approach can be extended to compute higher degree products, such as

\operatorname{SHD}(xyz)

Ahle et al. shows that if

\operatorname{SHD}

has

\varepsilon-2(log1/\delta)c+1

rows, then

|\|\operatorname{SHD}x\|2-\|x\||\le\varepsilon\|x\|2

for any vector
dc
x\inR
with probability

1-\delta

, while allowing fast multiplication with degree

c

tensors.

Jin et al.,[16] the same year, showed a similar result for the more general class of matrices call RIP, which includes the subsampled Hadamard matrices.They showed that these matrices allow splitting into tensors provided the number of rows is

\varepsilon-2(log1/\delta)2c-1logd

.In the case

c=2

this matches the previous result.

These fast constructions can again be combined with the recursion approach mentioned above, giving the fastest overall tensor sketch.

Data aware sketching

It is also possible to do so-called "data aware" tensor sketching.Instead of multiplying a random matrix on the data, the data points are sampled independently with a certain probability depending on the norm of the point.[17]

Applications

Explicit polynomial kernels

Kernel methods are popular in machine learning as they give the algorithm designed the freedom to design a "feature space" in which to measure the similarity of their data points.A simple kernel-based binary classifier is based on the following computation:

\hat{y}(x')=sgn

n
\sum
i=1

yik(xi,x'),

where

d
x
i\inR
are the data points,

yi

is the label of the

i

th point (either −1 or +1), and

\hat{y}(x')

is the prediction of the class of

x'

.The function

k:Rd x Rd\toR

is the kernel.Typical examples are the radial basis function kernel,

k(x,x')=

2)
\exp(-\|x-x'\|
2
, and polynomial kernels such as

k(x,x')=(1+\langlex,x'\rangle)2

.

When used this way, the kernel method is called "implicit".Sometimes it is faster to do an "explicit" kernel method, in which a pair of functions

f,g:Rd\toRD

are found, such that

k(x,x')=\langlef(x),g(x')\rangle

.This allows the above computation to be expressed as

\hat{y}(x') =sgn

n
\sum
i=1

yi\langlef(xi),g(x')\rangle =sgn

n
\left\langle\left(\sum
i=1

yif(xi)\right),g(x')\right\rangle,

where the value

n
\sum
i=1

yif(xi)

can be computed in advance.

The problem with this method is that the feature space can be very large. That is

D>>d

.For example, for the polynomial kernel

k(x,x')=\langlex,x'\rangle3

we get

f(x)=xxx

and

g(x')=x'x'x'

, where

is the tensor product and

f(x),g(x')\inRD

where

D=d3

.If

d

is already large,

D

can be much larger than the number of data points (

n

) and so the explicit method is inefficient.

The idea of tensor sketch is that we can compute approximate functions

f',g':Rd\toRt

where

t

can even be smaller than

d

, and which still have the property that

\langlef'(x),g'(x')\ranglek(x,x')

.

This method was shown in 2020[18] to work even for high degree polynomials and radial basis function kernels.

Compressed matrix multiplication

Assume we have two large datasets, represented as matrices

X,Y\inRn

, and we want to find the rows

i,j

with the largest inner products

\langleXi,Yj\rangle

.We could compute

Z=XYT\inRn x

and simply look at all

n2

possibilities.However, this would take at least

n2

time, and probably closer to

n2d

using standard matrix multiplication techniques.

The idea of Compressed Matrix Multiplication is the general identity

XYT=

d
\sum
i=1

XiYi

where

is the tensor product.Since we can compute a (linear) approximation to

XiYi

efficiently, we can sum those up to get an approximation for the complete product.

Compact multilinear pooling

Bilinear pooling is the technique of taking two input vectors,

x,y

from different sources, and using the tensor product

xy

as the input layer to a neural network.

In[19] the authors considered using tensor sketch to reduce the number of variables needed.

In 2017 another paper[20] takes the FFT of the input features, before they are combined using the element-wise product.This again corresponds to the original tensor sketch.

Further reading

Notes and References

  1. Web site: Low-rank Tucker decomposition of large tensors using: Tensor Sketch . amath.colorado.edu . . Boulder, Colorado.
  2. Web site: Ahle . Thomas . Knudsen . Jakob . 2019-09-03 . Almost Optimal Tensor Sketch . 2020-07-11 . ResearchGate.
  3. Woodruff, David P. "Sketching as a Tool for Numerical Linear Algebra ." Theoretical Computer Science 10.1-2 (2014): 1–157.
  4. Fast and scalable polynomial kernels via explicit feature maps. Ninh. Pham. Rasmus. Pagh . Rasmus Pagh. 2013. Association for Computing Machinery. SIGKDD international conference on Knowledge discovery and data mining. 10.1145/2487575.2487591.
  5. Compressed matrix multiplication. Rasmus. Pagh . Rasmus Pagh. 2013. Association for Computing Machinery. ACM Transactions on Computation Theory. 5. 3. 1–17. 10.1145/2493252.2493254. 1108.1320. 47560654.
  6. Kasiviswanathan, Shiva Prasad, et al. "The price of privately releasing contingency tables and the spectra of random matrices with correlated rows ." Proceedings of the forty-second ACM symposium on Theory of computing. 2010.
  7. Rudelson, Mark, and Shuheng Zhou. "Reconstruction from anisotropic random measurements ." Conference on Learning Theory. 2012.
  8. Avron . Haim . Nguyen . Huy . Woodruff . David . 2014 . Subspace embeddings for the polynomial kernel . Advances in Neural Information Processing Systems . 16658740.
  9. Anna Esteve, Eva Boj & Josep Fortiana (2009): Interaction Terms in Distance-Based Regression, Communications in Statistics – Theory and Methods, 38:19, P. 3501 http://dx.doi.org/10.1080/03610920802592860
  10. Slyusar . V. I. . 1998 . End products in matrices in radar applications. . Radioelectronics and Communications Systems . 41 . 3. 50–53.
  11. Slyusar. V. I.. 1997-05-20. Analytical model of the digital antenna array on a basis of face-splitting matrix products. . Proc. ICATT-97, Kyiv. 108–109.
  12. Slyusar. V. I.. 1997-09-15. New operations of matrices product for applications of radars. Proc. Direct and Inverse Problems of Electromagnetic and Acoustic Wave Theory (DIPED-97), Lviv.. 73–74.
  13. Slyusar. V. I.. March 13, 1998. A Family of Face Products of Matrices and its Properties. Cybernetics and Systems Analysis C/C of Kibernetika I Sistemnyi Analiz. – 1999.. 35. 3. 379–384. 10.1007/BF02733426. 119661450 .
  14. Slyusar. V. I.. 2003. Generalized face-products of matrices in models of digital antenna arrays with nonidentical channels. Radioelectronics and Communications Systems. 46. 10. 9–17.
  15. Encyclopedia: Ailon . Nir . Chazelle . Bernard . Approximate nearest neighbors and the fast Johnson–Lindenstrauss transform . Proceedings of the 38th Annual ACM Symposium on Theory of Computing . 2006 . 2277181 . 10.1145/1132516.1132597 . 557–563 . ACM Press . New York . 1-59593-134-1. 490517 .
  16. Jin, Ruhui, Tamara G. Kolda, and Rachel Ward. "Faster Johnson–Lindenstrauss Transforms via Kronecker Products." arXiv preprint arXiv:1909.04801 (2019).
  17. Fast and Guaranteed Tensor Decomposition via Sketching. Yining. Wang. Hsiao-Yu. Tung. Alexander. Smola. Anima. Anandkumar. 1506.04448. Advances in Neural Information Processing Systems 28 (NIPS 2015).
  18. Oblivious Sketching of High-Degree Polynomial Kernels. Thomas. Ahle. Michael. Kapralov. Jakob. Knudsen. Rasmus. Pagh . Rasmus Pagh. Ameya. Velingker. David. Woodruff. Amir. Zandieh. 2020. Association for Computing Machinery. ACM-SIAM Symposium on Discrete Algorithms. 10.1137/1.9781611975994.9. free. 1909.01410.
  19. Gao, Yang, et al. "Compact bilinear pooling ." Proceedings of the IEEE conference on computer vision and pattern recognition. 2016.
  20. Algashaam, Faisal M., et al. "Multispectral periocular classification with multimodal compact multi-linear pooling ." IEEE Access 5 (2017): 14572–14578.