Similarity of Neural Network Representations Revisited | AGIDaily
AGI Daily
资讯日报词条论文人物新创
返回论文列表
1. 引言问题陈述2. 相似性应对什么保持不变?2.1. 对可逆线性变换的不变性2.2. 对正交变换的不变性2.3. 对各向同性缩放的不变性3. 比较相似性结构基于点积的相似性。Hilbert-Schmidt 独立性准则。中心化核对齐。核的选择。4. 相关的相似性指标线性回归。典型相关分析(CCA)。SVCCA。投影加权 CCA。神经元对齐方法。互信息。5. 线性 CKA 与 CCA、回归的关系6. 结果6.1. 相似性指标的一项健全性检查6.2. 用 CKA 理解网络结构6.3. 跨数据集的相似表示6.4. 共享子空间的分析7. 结论与未来工作AcknowledgementsReferences
返回论文列表
目录

Similarity of Neural Network Representations Revisited

收录于 ICML 2019 会议论文被引 3,124 次
打开论文来源

Similarity of Neural Network Representations Revisited

Simon Kornblith1  Mohammad Norouzi1  Honglak Lee1  Geoffrey Hinton1

1Google Brain. Correspondence to: Simon Kornblith skornblith@google.com.

Proceedings of the 36th International Conference on Machine Learning, Long Beach, California, PMLR 97, 2019. Copyright 2019 by the author(s).

Abstract

摘要

Recent work has sought to understand the behavior of neural networks by comparing representations between layers and between different trained models. We examine methods for comparing neural network representations based on canonical correlation analysis (CCA). We show that CCA belongs to a family of statistics for measuring multivariate similarity, but that neither CCA nor any other statistic that is invariant to invertible linear transformation can measure meaningful similarities between representations of higher dimension than the number of data points. We introduce a similarity index that measures the relationship between representational similarity matrices and does not suffer from this limitation. This similarity index is equivalent to centered kernel alignment (CKA) and is also closely connected to CCA. Unlike CCA, CKA can reliably identify correspondences between representations in networks trained from different initializations.

近期工作试图通过比较各层之间、以及不同已训练模型之间的表示,来理解神经网络的行为。我们考察基于典型相关分析(CCA)的神经网络表示比较方法。我们表明,CCA 属于一族度量多元相似性的统计量,但无论是 CCA,还是任何对可逆线性变换不变的统计量,都无法在维数高于数据点数的表示之间度量出有意义的相似性。我们引入一种相似性指标,它度量表示相似性矩阵之间的关系,并且不受这一限制。该指标等价于中心化核对齐(CKA,centered kernel alignment),并且与 CCA 也有密切联系。与 CCA 不同,CKA 能够可靠地找出从不同初始化训出的网络表示之间的对应关系。

1. Introduction

1. 引言

Across a wide range of machine learning tasks, deep neural networks enable learning powerful feature representations automatically from data. Despite impressive empirical advances of deep neural networks in solving various tasks, the problem of understanding and characterizing the neural network representations learned from data remains relatively under-explored. Previous work (e.g. Advani & Saxe (2017); Amari et al. (2018); Saxe et al. (2014)) has made progress in understanding the theoretical dynamics of the neural network training process. These studies are insightful, but fundamentally limited, because they ignore the complex interaction between the training dynamics and structured data. A window into the network’s representation can provide more information about the interaction between machine learning algorithms and data than the value of the loss function alone.

在范围很广的机器学习任务上,深度神经网络能够从数据中自动学习出有力的特征表示。尽管深度神经网络在解决各类任务上已有令人印象深刻的经验进展,如何理解和刻画从数据中学到的神经网络表示,仍相对探索不足。已有工作(例如 Advani & Saxe (2017); Amari et al. (2018); Saxe et al. (2014))在理解神经网络训练过程的理论动力学方面取得了进展。这些研究很有启发,但有根本局限,因为它们忽略了训练动力学与结构化数据之间复杂的交互。打开一扇观察网络表示的窗口,往往能比只看损失函数的值,提供更多关于机器学习算法与数据如何交互的信息。

This paper investigates the problem of measuring similarities between deep neural network representations. An effective method for measuring representational similarity could help answer many interesting questions, including: (1) Do deep neural networks with the same architecture trained from different random initializations learn similar representations? (2) Can we establish correspondences between layers of different network architectures? (3) How similar are the representations learned using the same network architecture from different datasets?

本文研究如何度量深度神经网络表示之间的相似性。一种有效的表示相似性度量方法,有助于回答许多有意思的问题,包括:(1)结构相同、从不同随机初始化训出的深度神经网络,是否学到相似的表示?(2)能否在不同网络结构的各层之间建立对应?(3)同一网络结构在不同数据集上学到的表示有多相似?

We build upon previous studies investigating similarity between the representations of neural networks (Laakso & Cottrell, 2000; Li et al., 2015; Raghu et al., 2017; Morcos et al., 2018; Wang et al., 2018). We are also inspired by the extensive neuroscience literature that uses representational similarity analysis (Kriegeskorte et al., 2008a; Edelman, 1998) to compare representations across brain areas (Haxby et al., 2001; Freiwald & Tsao, 2010), individuals (Connolly et al., 2012), species (Kriegeskorte et al., 2008b), and behaviors (Elsayed et al., 2016), as well as between brains and neural networks (Yamins et al., 2014; Khaligh-Razavi & Kriegeskorte, 2014; Sussillo et al., 2015).

我们建立在此前考察神经网络表示相似性的研究之上(Laakso & Cottrell, 2000; Li et al., 2015; Raghu et al., 2017; Morcos et al., 2018; Wang et al., 2018)。我们也受到神经科学中大量使用表示相似性分析(Kriegeskorte et al., 2008a; Edelman, 1998)的文献启发:这些工作比较不同脑区(Haxby et al., 2001; Freiwald & Tsao, 2010)、不同个体(Connolly et al., 2012)、不同物种(Kriegeskorte et al., 2008b)和不同行为(Elsayed et al., 2016)中的表示,以及大脑与神经网络之间的表示(Yamins et al., 2014; Khaligh-Razavi & Kriegeskorte, 2014; Sussillo et al., 2015)。

Our key contributions are summarized as follows:

我们的主要贡献概括如下:

• We discuss the invariance properties of similarity indexes and their implications for measuring similarity of neural network representations.

• 我们讨论相似性指标的不变性,以及它们对度量神经网络表示相似性的含义。

• We motivate and introduce centered kernel alignment (CKA) as a similarity index and analyze the relationship between CKA, linear regression, canonical correlation analysis (CCA), and related methods (Raghu et al., 2017; Morcos et al., 2018).

• 我们给出动机,并把中心化核对齐(CKA)作为相似性指标引入,同时分析 CKA 与线性回归、典型相关分析(CCA)以及相关方法(Raghu et al., 2017; Morcos et al., 2018)之间的关系。

• We show that CKA is able to determine the correspondence between the hidden layers of neural networks trained from different random initializations and with different widths, scenarios where previously proposed similarity indexes fail.

• 我们表明,CKA 能够确定从不同随机初始化、以及不同宽度训出的神经网络隐层之间的对应关系;在这些情形下,此前提出的相似性指标会失败。

• We verify that wider networks learn more similar representations, and show that the similarity of early layers saturates at fewer channels than later layers. We demonstrate that early layers, but not later layers, learn similar representations on different datasets.

• 我们验证了更宽的网络会学到更相似的表示,并表明浅层的相似性会在比深层更少的通道数上趋于饱和。我们还表明,浅层(而不是深层)会在不同数据集上学到相似的表示。

Problem Statement

问题陈述

Let X∈Rn×p1X \in \mathbb{R}^{n \times p_1}X∈Rn×p1​ denote a matrix of activations of p1p_1p1​ neurons for nnn examples, and Y∈Rn×p2Y \in \mathbb{R}^{n \times p_2}Y∈Rn×p2​ denote a matrix of activations of p2p_2p2​ neurons for the same nnn examples. We assume that these matrices have been preprocessed to center the columns. Without loss of generality we assume that p1≤p2p_1 \le p_2p1​≤p2​. We are concerned with the design and analysis of a scalar similarity index s(X,Y)s(X, Y)s(X,Y) that can be used to compare representations within and across neural networks, in order to help visualize and understand the effect of different factors of variation in deep learning.

令 X∈Rn×p1X \in \mathbb{R}^{n \times p_1}X∈Rn×p1​ 表示 nnn 个样本上 p1p_1p1​ 个神经元的激活矩阵,Y∈Rn×p2Y \in \mathbb{R}^{n \times p_2}Y∈Rn×p2​ 表示同样 nnn 个样本上 p2p_2p2​ 个神经元的激活矩阵。我们假定这些矩阵已经过预处理,把各列中心化。在不失一般性的前提下,假定 p1≤p2p_1 \le p_2p1​≤p2​。我们关心的是设计并分析一个标量相似性指标 s(X,Y)s(X, Y)s(X,Y),用来比较同一网络内部以及不同网络之间的表示,从而帮助可视化和理解深度学习中各种变异因素的影响。

2. What Should Similarity Be Invariant To?

2. 相似性应对什么保持不变?

This section discusses the invariance properties of similarity indexes and their implications for measuring similarity of neural network representations. We argue that both intuitive notions of similarity and the dynamics of neural network training call for a similarity index that is invariant to orthogonal transformation and isotropic scaling, but not invertible linear transformation.

本节讨论相似性指标的不变性,以及它们对度量神经网络表示相似性的含义。我们认为,无论是对相似性的直觉理解,还是神经网络训练的动力学,都要求相似性指标对正交变换和各向同性缩放不变,但对可逆线性变换不必不变。

2.1. Invariance to Invertible Linear Transformation

2.1. 对可逆线性变换的不变性

A similarity index is invariant to invertible linear transformation if s(X,Y)=s(XA,YB)s(X, Y) = s(XA, YB)s(X,Y)=s(XA,YB) for any full rank AAA and BBB. If activations XXX are followed by a fully-connected layer f(X)=σ(XW+β)f(X) = \sigma(XW + \beta)f(X)=σ(XW+β), then transforming the activations by a full rank matrix AAA as X′=XAX' = XAX′=XA and transforming the weights by the inverse A−1A^{-1}A−1 as W′=A−1WW' = A^{-1}WW′=A−1W preserves the output of f(X)f(X)f(X). This transformation does not appear to change how the network operates, so intuitively, one might prefer a similarity index that is invariant to invertible linear transformation, as argued by Raghu et al. (2017).

若对任意满秩矩阵 AAA 和 BBB 都有 s(X,Y)=s(XA,YB)s(X, Y) = s(XA, YB)s(X,Y)=s(XA,YB),则称该相似性指标对可逆线性变换不变。如果激活 XXX 后面接一个全连接层 f(X)=σ(XW+β)f(X) = \sigma(XW + \beta)f(X)=σ(XW+β),那么用满秩矩阵 AAA 把激活变换为 X′=XAX' = XAX′=XA,同时用逆矩阵把权重变换为 W′=A−1WW' = A^{-1}WW′=A−1W,可以保持 f(X)f(X)f(X) 的输出不变。这一变换看起来并不改变网络的运作方式,因此直觉上,人们可能更希望相似性指标对可逆线性变换不变,正如 Raghu et al. (2017) 所主张的那样。

However, a limitation of invariance to invertible linear transformation is that any invariant similarity index gives the same result for any representation of width greater than or equal to the dataset size, i.e. p2≥np_2 \ge np2​≥n. We provide a simple proof in Appendix A.

然而,对可逆线性变换不变有一个局限:任何具有这一不变性的相似性指标,对宽度大于或等于数据集大小(即 p2≥np_2 \ge np2​≥n)的任意表示,都会给出相同的结果。我们在附录 A 中给出一个简单证明。

Theorem 1. Let XXX and YYY be n×pn \times pn×p matrices. Suppose sss is invariant to invertible linear transformation in the first argument, i.e. s(X,Z)=s(XA,Z)s(X, Z) = s(XA, Z)s(X,Z)=s(XA,Z) for arbitrary ZZZ and any AAA with rank(A)=p\mathrm{rank}(A) = prank(A)=p. If rank(X)=rank(Y)=n\mathrm{rank}(X) = \mathrm{rank}(Y) = nrank(X)=rank(Y)=n, then s(X,Z)=s(Y,Z)s(X, Z) = s(Y, Z)s(X,Z)=s(Y,Z).

定理 1. 设 XXX 和 YYY 为 n×pn \times pn×p 矩阵。假设 sss 在第一个自变量上对可逆线性变换不变,即对任意 ZZZ 以及任意满足 rank(A)=p\mathrm{rank}(A) = prank(A)=p 的 AAA,都有 s(X,Z)=s(XA,Z)s(X, Z) = s(XA, Z)s(X,Z)=s(XA,Z)。若 rank(X)=rank(Y)=n\mathrm{rank}(X) = \mathrm{rank}(Y) = nrank(X)=rank(Y)=n,则 s(X,Z)=s(Y,Z)s(X, Z) = s(Y, Z)s(X,Z)=s(Y,Z)。

There is thus a practical problem with invariance to invertible linear transformation: Some neural networks, especially convolutional networks, have more neurons in some layers than there are examples in the training dataset (Springenberg et al., 2015; Lee et al., 2018; Zagoruyko & Komodakis, 2016). It is somewhat unnatural that a similarity index could require more examples than were used for training.

因此,对可逆线性变换不变会带来一个实际问题:有些神经网络,尤其是卷积网络,某些层的神经元数比训练数据集中的样本还多(Springenberg et al., 2015; Lee et al., 2018; Zagoruyko & Komodakis, 2016)。一个相似性指标可能需要比训练时用过的样本更多的例子,这一点有些不自然。

A deeper issue is that neural network training is not invariant to arbitrary invertible linear transformation of inputs or activations. Even in the linear case, gradient descent converges first along the eigenvectors corresponding to the largest eigenvalues of the input covariance matrix (LeCun et al., 1991), and in cases of overparameterization or early stopping, the solution reached depends on the scale of the input. Similar results hold for gradient descent training of neural networks in the infinite width limit (Jacot et al., 2018). The sensitivity of neural networks training to linear transformation is further demonstrated by the popularity of batch normalization (Ioffe & Szegedy, 2015).

一个更深的问题是:神经网络训练本身并不对输入或激活的任意可逆线性变换保持不变。即使在线性情形下,梯度下降也会先沿着输入协方差矩阵最大特征值所对应的特征向量收敛(LeCun et al., 1991);在过参数化或早停的情形下,最终到达的解还依赖于输入的尺度。类似结果对无限宽极限下用梯度下降训练的神经网络同样成立(Jacot et al., 2018)。batch normalization 的流行,也进一步说明神经网络训练对线性变换是敏感的(Ioffe & Szegedy, 2015)。

Scatter plots of CIFAR-10 examples colored by the first two principal components of the same layer in two networks trained from different initializations.

Figure 1. First principal components of representations of networks trained from different random initializations are similar. Each example from the CIFAR-10 test set is shown as a dot colored according to the value of the first two principal components of an intermediate layer of one network (left) and plotted on the first two principal components of the same layer of an architecturally identical network trained from a different initialization (right).

图 1. 从不同随机初始化训出的网络,其表示的前几个主成分是相似的。CIFAR-10 测试集中的每个样本画成一个点:颜色由一个网络中间层的前两个主成分决定(左),并画在结构相同、从另一初始化训出的网络同一层的前两个主成分上(右)。

Invariance to invertible linear transformation implies that the scale of directions in activation space is irrelevant. Empirically, however, scale information is both consistent across networks and useful across tasks. Neural networks trained from different random initializations develop representations with similar large principal components, as shown in Figure 1. Consequently, Euclidean distances between examples, which depend primarily upon large principal components, are similar across networks. These distances are meaningful, as demonstrated by the success of perceptual loss and style transfer (Gatys et al., 2016; Johnson et al., 2016; Dumoulin et al., 2017). A similarity index that is invariant to invertible linear transformation ignores this aspect of the representation, and assigns the same score to networks that match only in large principal components or networks that match only in small principal components.

对可逆线性变换不变,意味着激活空间中各方向的尺度无关紧要。但经验上,尺度信息既在不同网络之间保持一致,也在不同任务上有用。如图 1 所示,从不同随机初始化训出的神经网络会形成具有相似大主成分的表示。因此,主要依赖大主成分的样本间欧氏距离,在不同网络之间也是相似的。这些距离是有意义的,感知损失和风格迁移的成功就说明了这一点(Gatys et al., 2016; Johnson et al., 2016; Dumoulin et al., 2017)。对可逆线性变换不变的相似性指标会忽略表示的这一方面,从而把“只在大主成分上相配”的网络和“只在小主成分上相配”的网络打成同一分。

2.2. Invariance to Orthogonal Transformation

2.2. 对正交变换的不变性

Rather than requiring invariance to any invertible linear transformation, one could require a weaker condition; invariance to orthogonal transformation, i.e. s(X,Y)=s(XU,YV)s(X, Y) = s(XU, YV)s(X,Y)=s(XU,YV) for full-rank orthonormal matrices UUU and VVV such that U⊤U=IU^{\top}U = IU⊤U=I and V⊤V=IV^{\top}V = IV⊤V=I.

与其要求对任意可逆线性变换都不变,也可以只要求一个更弱的条件:对正交变换不变,即对满足 U⊤U=IU^{\top}U = IU⊤U=I 和 V⊤V=IV^{\top}V = IV⊤V=I 的满秩标准正交矩阵 UUU 和 VVV,有 s(X,Y)=s(XU,YV)s(X, Y) = s(XU, YV)s(X,Y)=s(XU,YV)。

Indexes invariant to orthogonal transformations do not share the limitations of indexes invariant to invertible linear transformation. When p2>np_2 > np2​>n, indexes invariant to orthogonal transformation remain well-defined. Moreover, orthogonal transformations preserve scalar products and Euclidean distances between examples.

对正交变换不变的指标,并不具有对可逆线性变换不变的那些局限。当 p2>np_2 > np2​>n 时,对正交变换不变的指标仍然定义良好。此外,正交变换保持样本之间的内积和欧氏距离。

Invariance to orthogonal transformation seems desirable for neural networks trained by gradient descent. Invariance to orthogonal transformation implies invariance to permutation, which is needed to accommodate symmetries of neural networks (Chen et al., 1993; Orhan & Pitkow, 2018). In the linear case, orthogonal transformation of the input does not affect the dynamics of gradient descent training (LeCun et al., 1991), and for neural networks initialized with rotationally symmetric weight distributions, e.g. i.i.d. Gaussian weight initialization, training with fixed orthogonal transformations of activations yields the same distribution of training trajectories as untransformed activations, whereas an arbitrary linear transformation would not.

对用梯度下降训练的神经网络来说,对正交变换不变看起来是可取的。对正交变换不变蕴含对排列不变,而后者是为了容纳神经网络的对称性所需要的(Chen et al., 1993; Orhan & Pitkow, 2018)。在线性情形下,对输入做正交变换并不影响梯度下降训练的动力学(LeCun et al., 1991);对于用旋转对称的权重分布初始化的神经网络,例如独立同分布的高斯权重初始化,在激活上施加固定的正交变换再训练,得到的训练轨迹分布与未变换的激活相同,而任意线性变换则不会如此。

Given a similarity index s(⋅,⋅)s(\cdot, \cdot)s(⋅,⋅) that is invariant to orthogonal transformation, one can construct a similarity index s′(⋅,⋅)s'(\cdot, \cdot)s′(⋅,⋅) that is invariant to any invertible linear transformation by first orthonormalizing the columns of XXX and YYY, and then applying s(⋅,⋅)s(\cdot, \cdot)s(⋅,⋅). Given thin QR decompositions X=QARAX = Q_A R_AX=QA​RA​ and Y=QBRBY = Q_B R_BY=QB​RB​ one can construct a similarity index s′(X,Y)=s(QX,QY)s'(X, Y) = s(Q_X, Q_Y)s′(X,Y)=s(QX​,QY​), where s′(⋅,⋅)s'(\cdot, \cdot)s′(⋅,⋅) is invariant to invertible linear transformation because orthonormal bases with the same span are related to each other by orthonormal transformation (see Appendix B).

给定一个对正交变换不变的相似性指标 s(⋅,⋅)s(\cdot, \cdot)s(⋅,⋅),可以先把 XXX 和 YYY 的列标准正交化,再应用 s(⋅,⋅)s(\cdot, \cdot)s(⋅,⋅),从而构造出一个对任意可逆线性变换都不变的指标 s′(⋅,⋅)s'(\cdot, \cdot)s′(⋅,⋅)。给定瘦 QR 分解 X=QARAX = Q_A R_AX=QA​RA​ 和 Y=QBRBY = Q_B R_BY=QB​RB​,可以构造 s′(X,Y)=s(QX,QY)s'(X, Y) = s(Q_X, Q_Y)s′(X,Y)=s(QX​,QY​);由于张成同一空间的标准正交基之间只相差一个标准正交变换,s′(⋅,⋅)s'(\cdot, \cdot)s′(⋅,⋅) 对可逆线性变换不变(见附录 B)。

2.3. Invariance to Isotropic Scaling

2.3. 对各向同性缩放的不变性

We expect similarity indexes to be invariant to isotropic scaling, i.e. s(X,Y)=s(αX,βY)s(X, Y) = s(\alpha X, \beta Y)s(X,Y)=s(αX,βY) for any α,β∈R+\alpha, \beta \in \mathbb{R}^{+}α,β∈R+. That said, a similarity index that is invariant to both orthogonal transformation and non-isotropic scaling, i.e. rescaling of individual features, is invariant to any invertible linear transformation. This follows from the existence of the singular value decomposition of the transformation matrix. Generally, we are interested in similarity indexes that are invariant to isotropic but not necessarily non-isotropic scaling.

我们期望相似性指标对各向同性缩放不变,即对任意 α,β∈R+\alpha, \beta \in \mathbb{R}^{+}α,β∈R+ 都有 s(X,Y)=s(αX,βY)s(X, Y) = s(\alpha X, \beta Y)s(X,Y)=s(αX,βY)。不过,若一个指标既对正交变换不变,又对非各向同性缩放(也就是对单个特征分别缩放)不变,那么它就对任意可逆线性变换不变。这是因为变换矩阵存在奇异值分解。一般而言,我们关心的是对各向同性缩放不变、但不一定对非各向同性缩放不变的相似性指标。

3. Comparing Similarity Structures

3. 比较相似性结构

Our key insight is that instead of comparing multivariate features of an example in the two representations (e.g. via regression), one can first measure the similarity between every pair of examples in each representation separately, and then compare the similarity structures. In neuroscience, such matrices representing the similarities between examples are called representational similarity matrices (Kriegeskorte et al., 2008a). We show below that, if we use an inner product to measure similarity, the similarity between representational similarity matrices reduces to another intuitive notion of pairwise feature similarity.

我们的关键见解是:不必直接比较同一个样本在两种表示中的多元特征(例如用回归),可以先在各自的表示里分别度量每对样本之间的相似性,再比较这两张相似性结构。在神经科学中,这种表示样本之间相似性的矩阵叫做表示相似性矩阵(Kriegeskorte et al., 2008a)。我们在下面表明:如果用内积来度量相似性,那么表示相似性矩阵之间的相似性,会归结为另一种直观的成对特征相似性。

Dot Product-Based Similarity.

基于点积的相似性。

A simple formula relates dot products between examples to dot products between features:

一个简单公式把样本之间的点积与特征之间的点积联系起来:

⟨vec(XX⊤),vec(YY⊤)⟩=tr(XX⊤YY⊤)=∥Y⊤X∥F2.(1)\langle \mathrm{vec}(XX^{\top}), \mathrm{vec}(YY^{\top}) \rangle = \mathrm{tr}(XX^{\top} YY^{\top}) = \|Y^{\top} X\|_{F}^{2}. \qquad (1)⟨vec(XX⊤),vec(YY⊤)⟩=tr(XX⊤YY⊤)=∥Y⊤X∥F2​.(1)

The elements of XX⊤XX^{\top}XX⊤ and YY⊤YY^{\top}YY⊤ are dot products between the representations of the ithi^{\mathrm{th}}ith and jthj^{\mathrm{th}}jth examples, and indicate the similarity between these examples according to the respective networks. The left-hand side of (1) thus measures the similarity between the inter-example similarity structures. The right-hand side yields the same result by measuring the similarity between features from XXX and YYY, by summing the squared dot products between every pair.

XX⊤XX^{\top}XX⊤ 和 YY⊤YY^{\top}YY⊤ 的元素是第 iii 个与第 jjj 个样本表示之间的点积,表示相应网络认为这两个样本有多相似。因此,(1) 的左边度量的是样本间相似性结构之间的相似性。右边通过度量 XXX 和 YYY 中特征之间的相似性——把每一对特征的点积平方求和——得到同样的结果。

Hilbert-Schmidt Independence Criterion.

Hilbert-Schmidt 独立性准则。

Equation 1 implies that, for centered XXX and YYY:

公式 1 意味着,对已经中心化的 XXX 和 YYY:

1(n−1)2tr(XX⊤YY⊤)=∥cov(X⊤,Y⊤)∥F2.(2)\frac{1}{(n-1)^{2}} \mathrm{tr}(XX^{\top} YY^{\top}) = \|\mathrm{cov}(X^{\top}, Y^{\top})\|_{F}^{2}. \qquad (2)(n−1)21​tr(XX⊤YY⊤)=∥cov(X⊤,Y⊤)∥F2​.(2)

The Hilbert-Schmidt Independence Criterion (Gretton et al., 2005) generalizes Equations 1 and 2 to inner products from reproducing kernel Hilbert spaces, where the squared Frobenius norm of the cross-covariance matrix becomes the squared Hilbert-Schmidt norm of the cross-covariance operator. Let Kij=k(xi,xj)K_{ij} = k(\mathbf{x}_i, \mathbf{x}_j)Kij​=k(xi​,xj​) and Lij=l(yi,yj)L_{ij} = l(\mathbf{y}_i, \mathbf{y}_j)Lij​=l(yi​,yj​) where kkk and lll are two kernels. The empirical estimator of HSIC is:

Hilbert-Schmidt 独立性准则(Gretton et al., 2005)把公式 1 和 2 推广到再生核 Hilbert 空间中的内积,此时交叉协方差矩阵的 Frobenius 范数平方,变成交叉协方差算子的 Hilbert-Schmidt 范数平方。令 Kij=k(xi,xj)K_{ij} = k(\mathbf{x}_i, \mathbf{x}_j)Kij​=k(xi​,xj​),Lij=l(yi,yj)L_{ij} = l(\mathbf{y}_i, \mathbf{y}_j)Lij​=l(yi​,yj​),其中 kkk 和 lll 是两个核。HSIC 的经验估计为:

HSIC(K,L)=1(n−1)2tr(KHLH),(3)\mathrm{HSIC}(K, L) = \frac{1}{(n-1)^{2}} \mathrm{tr}(KHLH), \qquad (3)HSIC(K,L)=(n−1)21​tr(KHLH),(3)

where HHH is the centering matrix Hn=In−1n11⊤H_n = I_n - \frac{1}{n}\mathbf{1}\mathbf{1}^{\top}Hn​=In​−n1​11⊤. For linear kernels k(x,y)=l(x,y)=x⊤yk(\mathbf{x}, \mathbf{y}) = l(\mathbf{x}, \mathbf{y}) = \mathbf{x}^{\top}\mathbf{y}k(x,y)=l(x,y)=x⊤y, HSIC yields (2).

其中 HHH 是中心化矩阵 Hn=In−1n11⊤H_n = I_n - \frac{1}{n}\mathbf{1}\mathbf{1}^{\top}Hn​=In​−n1​11⊤。对线性核 k(x,y)=l(x,y)=x⊤yk(\mathbf{x}, \mathbf{y}) = l(\mathbf{x}, \mathbf{y}) = \mathbf{x}^{\top}\mathbf{y}k(x,y)=l(x,y)=x⊤y,HSIC 就得到 (2)。

Gretton et al. (2005) originally proposed HSIC as a test statistic for determining whether two sets of variables are independent. They prove that the empirical estimator converges to the population value at a rate of 1/n1/\sqrt{n}1/n​, and Song et al. (2007) provide an unbiased estimator. When kkk and lll are universal kernels, HSIC =0= 0=0 implies independence, but HSIC is not an estimator of mutual information. HSIC is equivalent to maximum mean discrepancy between the joint distribution and the product of the marginal distributions, and HSIC with a specific kernel family is equivalent to distance covariance (Sejdinovic et al., 2013).

Gretton et al. (2005) 最初把 HSIC 作为检验两组变量是否独立的统计量提出。他们证明经验估计以 1/n1/\sqrt{n}1/n​ 的速率收敛到总体值,Song et al. (2007) 还给出了无偏估计。当 kkk 和 lll 是通用核时,HSIC =0= 0=0 意味着独立,但 HSIC 并不是互信息的估计量。HSIC 等价于联合分布与边缘分布乘积之间的最大均值差异;对特定的核族,HSIC 还等价于距离协方差(Sejdinovic et al., 2013)。

Centered Kernel Alignment.

中心化核对齐。

HSIC is not invariant to isotropic scaling, but it can be made invariant through normalization. This normalized index is known as centered kernel alignment (Cortes et al., 2012; Cristianini et al., 2002):

HSIC 对各向同性缩放并不不变,但可以通过归一化使之不变。这一归一化后的指标称为中心化核对齐(Cortes et al., 2012; Cristianini et al., 2002):

CKA(K,L)=HSIC(K,L)HSIC(K,K) HSIC(L,L).(4)\mathrm{CKA}(K, L) = \frac{\mathrm{HSIC}(K, L)}{\sqrt{\mathrm{HSIC}(K, K)\,\mathrm{HSIC}(L, L)}}. \qquad (4)CKA(K,L)=HSIC(K,K)HSIC(L,L)​HSIC(K,L)​.(4)

For a linear kernel, CKA is equivalent to the RV coefficient (Robert & Escoufier, 1976) and to Tucker’s congruence coefficient (Tucker, 1951; Lorenzo-Seva & Ten Berge, 2006).

对线性核而言,CKA 等价于 RV 系数(Robert & Escoufier, 1976),也等价于 Tucker 的一致性系数(Tucker, 1951; Lorenzo-Seva & Ten Berge, 2006)。

Kernel Selection.

核的选择。

Below, we report results of CKA with a linear kernel and the RBF kernel k(xi,xj)=exp⁡(−∥xi−xj∥22/(2σ2))k(\mathbf{x}_i, \mathbf{x}_j) = \exp(-\|\mathbf{x}_i - \mathbf{x}_j\|_{2}^{2}/(2\sigma^{2}))k(xi​,xj​)=exp(−∥xi​−xj​∥22​/(2σ2)). For the RBF kernel, there are several possible strategies for selecting the bandwidth σ\sigmaσ, which controls the extent to which similarity of small distances is emphasized over large distances. We set σ\sigmaσ as a fraction of the median distance between examples. In practice, we find that RBF and linear kernels give similar results across most experiments, so we use linear CKA unless otherwise specified. Our framework extends to any valid kernel, including kernels equivalent to neural networks (Lee et al., 2018; Jacot et al., 2018; Garriga-Alonso et al., 2019; Novak et al., 2019).

下面我们报告线性核以及 RBF 核 k(xi,xj)=exp⁡(−∥xi−xj∥22/(2σ2))k(\mathbf{x}_i, \mathbf{x}_j) = \exp(-\|\mathbf{x}_i - \mathbf{x}_j\|_{2}^{2}/(2\sigma^{2}))k(xi​,xj​)=exp(−∥xi​−xj​∥22​/(2σ2)) 下的 CKA 结果。对 RBF 核,选择带宽 σ\sigmaσ 有几种可能策略,它控制着小距离上的相似性相对于大距离被强调到什么程度。我们把 σ\sigmaσ 取为样本间中位距离的一个分数。实践中我们发现,在多数实验里 RBF 核和线性核给出相近的结果,因此除非另有说明,我们使用线性 CKA。我们的框架适用于任何合法的核,包括与神经网络等价的核(Lee et al., 2018; Jacot et al., 2018; Garriga-Alonso et al., 2019; Novak et al., 2019)。

4. Related Similarity Indexes

4. 相关的相似性指标

In this section, we briefly review linear regression, canonical correlation, and other related methods in the context of measuring similarity between neural network representations. We let QXQ_XQX​ and QYQ_YQY​ represent any orthonormal bases for the columns of XXX and YYY, i.e. QX=X(X⊤X)−1/2Q_X = X(X^{\top}X)^{-1/2}QX​=X(X⊤X)−1/2, QY=Y(Y⊤Y)−1/2Q_Y = Y(Y^{\top}Y)^{-1/2}QY​=Y(Y⊤Y)−1/2 or orthogonal transformations thereof. Table 1 summarizes the formulae and invariance properties of the indexes used in experiments. For a comprehensive general review of linear indexes for measuring multivariate similarity, see Ramsay et al. (1984).

本节我们简要回顾线性回归、典型相关以及其他相关方法,讨论它们在度量神经网络表示相似性中的位置。我们用 QXQ_XQX​ 和 QYQ_YQY​ 表示 XXX 和 YYY 的列的任意标准正交基,即 QX=X(X⊤X)−1/2Q_X = X(X^{\top}X)^{-1/2}QX​=X(X⊤X)−1/2、QY=Y(Y⊤Y)−1/2Q_Y = Y(Y^{\top}Y)^{-1/2}QY​=Y(Y⊤Y)−1/2,或它们的正交变换。表 1 汇总了实验中所用指标的公式和不变性。关于度量多元相似性的线性指标的更全面综述,见 Ramsay et al. (1984)。

Table 1. Summary of similarity methods investigated. QXQ_XQX​ and QYQ_YQY​ are orthonormal bases for the columns of XXX and YYY. UXU_XUX​ and UYU_YUY​ are the left-singular vectors of XXX and YYY sorted in descending order according to the corresponding singular vectors. ∥⋅∥∗\|\cdot\|_*∥⋅∥∗​ denotes the nuclear norm. TXT_XTX​ and TYT_YTY​ are truncated identity matrices that select left-singular vectors such that the cumulative variance explained reaches some threshold. For RBF CKA, KKK and LLL are kernel matrices constructed by evaluating the RBF kernel between the examples as in Section 3, and HHH is the centering matrix Hn=In−1n11⊤H_n = I_n - \frac{1}{n}\mathbf{1}\mathbf{1}^{\top}Hn​=In​−n1​11⊤. See Appendix C for more detail about each technique.

Similarity Index Formula Invertible Linear Transform Orthogonal Transform Isotropic Scaling
Linear Reg. (RLR2R^{2}_{\mathrm{LR}}RLR2​) ∣QY⊤X∣F2/∣X∣F2|Q_Y^{\top} X|_{F}^{2}/|X|_{F}^{2}∣QY⊤​X∣F2​/∣X∣F2​ Y only ✓ ✓
CCA (RCCA2R^{2}_{\mathrm{CCA}}RCCA2​) ∣QY⊤QX∣F2/p1|Q_Y^{\top} Q_X|_{F}^{2}/p_1∣QY⊤​QX​∣F2​/p1​ ✓ ✓ ✓
CCA (ρˉCCA\bar{\rho}_{\mathrm{CCA}}ρˉ​CCA​) ∣QY⊤QX∣∗/p1|Q_Y^{\top} Q_X|_{*}/p_1∣QY⊤​QX​∣∗​/p1​ ✓ ✓ ✓
SVCCA (RSVCCA2R^{2}_{\mathrm{SVCCA}}RSVCCA2​) ∣(UYTY)⊤UXTX∣F2/min⁡(∣TX∣F2,∣TY∣F2)|(U_Y T_Y)^{\top} U_X T_X|_{F}^{2}/\min(|T_X|_{F}^{2},|T_Y|_{F}^{2})∣(UY​TY​)⊤UX​TX​∣F2​/min(∣TX​∣F2​,∣TY​∣F2​) If same subspace kept ✓ ✓
SVCCA (ρˉSVCCA\bar{\rho}_{\mathrm{SVCCA}}ρˉ​SVCCA​) ∣(UYTY)⊤UXTX∣∗/min⁡(∣TX∣F2,∣TY∣F2)|(U_Y T_Y)^{\top} U_X T_X|_{*}/\min(|T_X|_{F}^{2},|T_Y|_{F}^{2})∣(UY​TY​)⊤UX​TX​∣∗​/min(∣TX​∣F2​,∣TY​∣F2​) If same subspace kept ✓ ✓
PWCCA ∑i=1p1αiρi/∣α∣1\sum_{i=1}^{p_1} \alpha_i \rho_i / |\alpha|_1∑i=1p1​​αi​ρi​/∣α∣1​, $\alpha_i = \sum_j \langle \mathbf{h}_i, \mathbf{x}_j \rangle $ ✗
Linear HSIC ∣Y⊤X∣F2/(n−1)2|Y^{\top} X|_{F}^{2}/(n-1)^{2}∣Y⊤X∣F2​/(n−1)2 ✗ ✓ ✗
Linear CKA ∣Y⊤X∣F2/(∣X⊤X∣F ∣Y⊤Y∣F)|Y^{\top} X|_{F}^{2}/(|X^{\top} X|_{F}\,|Y^{\top} Y|_{F})∣Y⊤X∣F2​/(∣X⊤X∣F​∣Y⊤Y∣F​) ✗ ✓ ✓
RBF CKA tr(KHLH)/tr(KHKH) tr(LHLH)\mathrm{tr}(KHLH)/\sqrt{\mathrm{tr}(KHKH)\,\mathrm{tr}(LHLH)}tr(KHLH)/tr(KHKH)tr(LHLH)​ ✗ ✓ ✓*

*Invariance of RBF CKA to isotropic scaling depends on the procedure used to select the RBF kernel bandwidth parameter. In our experiments, we selected the bandwidth as a fraction of the median distance, which ensures that the similarity index is invariant to isotropic scaling.

表 1. 所考察的相似性方法汇总。 QXQ_XQX​ 和 QYQ_YQY​ 是 XXX 和 YYY 的列的标准正交基。UXU_XUX​ 和 UYU_YUY​ 是 XXX 和 YYY 按对应奇异值降序排列的左奇异向量。∥⋅∥∗\|\cdot\|_*∥⋅∥∗​ 表示核范数。TXT_XTX​ 和 TYT_YTY​ 是截断的单位矩阵,用于选出累积解释方差达到某一阈值的左奇异向量。对 RBF CKA,KKK 和 LLL 是按第 3 节在样本之间计算 RBF 核得到的核矩阵,HHH 是中心化矩阵 Hn=In−1n11⊤H_n = I_n - \frac{1}{n}\mathbf{1}\mathbf{1}^{\top}Hn​=In​−n1​11⊤。各方法的更多细节见附录 C。

相似性指标 公式 可逆线性变换 正交变换 各向同性缩放
Linear Reg. (RLR2R^{2}_{\mathrm{LR}}RLR2​) ∣QY⊤X∣F2/∣X∣F2|Q_Y^{\top} X|_{F}^{2}/|X|_{F}^{2}∣QY⊤​X∣F2​/∣X∣F2​ 仅对 Y ✓ ✓
CCA (RCCA2R^{2}_{\mathrm{CCA}}RCCA2​) ∣QY⊤QX∣F2/p1|Q_Y^{\top} Q_X|_{F}^{2}/p_1∣QY⊤​QX​∣F2​/p1​ ✓ ✓ ✓
CCA (ρˉCCA\bar{\rho}_{\mathrm{CCA}}ρˉ​CCA​) ∣QY⊤QX∣∗/p1|Q_Y^{\top} Q_X|_{*}/p_1∣QY⊤​QX​∣∗​/p1​ ✓ ✓ ✓
SVCCA (RSVCCA2R^{2}_{\mathrm{SVCCA}}RSVCCA2​) ∣(UYTY)⊤UXTX∣F2/min⁡(∣TX∣F2,∣TY∣F2)|(U_Y T_Y)^{\top} U_X T_X|_{F}^{2}/\min(|T_X|_{F}^{2},|T_Y|_{F}^{2})∣(UY​TY​)⊤UX​TX​∣F2​/min(∣TX​∣F2​,∣TY​∣F2​) 若保留同一子空间 ✓ ✓
SVCCA (ρˉSVCCA\bar{\rho}_{\mathrm{SVCCA}}ρˉ​SVCCA​) ∣(UYTY)⊤UXTX∣∗/min⁡(∣TX∣F2,∣TY∣F2)|(U_Y T_Y)^{\top} U_X T_X|_{*}/\min(|T_X|_{F}^{2},|T_Y|_{F}^{2})∣(UY​TY​)⊤UX​TX​∣∗​/min(∣TX​∣F2​,∣TY​∣F2​) 若保留同一子空间 ✓ ✓
PWCCA ∑i=1p1αiρi/∣α∣1\sum_{i=1}^{p_1} \alpha_i \rho_i / |\alpha|_1∑i=1p1​​αi​ρi​/∣α∣1​, $\alpha_i = \sum_j \langle \mathbf{h}_i, \mathbf{x}_j \rangle $ ✗
Linear HSIC ∣Y⊤X∣F2/(n−1)2|Y^{\top} X|_{F}^{2}/(n-1)^{2}∣Y⊤X∣F2​/(n−1)2 ✗ ✓ ✗
Linear CKA ∣Y⊤X∣F2/(∣X⊤X∣F ∣Y⊤Y∣F)|Y^{\top} X|_{F}^{2}/(|X^{\top} X|_{F}\,|Y^{\top} Y|_{F})∣Y⊤X∣F2​/(∣X⊤X∣F​∣Y⊤Y∣F​) ✗ ✓ ✓
RBF CKA tr(KHLH)/tr(KHKH) tr(LHLH)\mathrm{tr}(KHLH)/\sqrt{\mathrm{tr}(KHKH)\,\mathrm{tr}(LHLH)}tr(KHLH)/tr(KHKH)tr(LHLH)​ ✗ ✓ ✓*

*RBF CKA 对各向同性缩放是否不变,取决于选择 RBF 核带宽参数的方式。在我们的实验中,带宽取为中位距离的一个分数,从而保证该相似性指标对各向同性缩放不变。

Linear Regression.

线性回归。

A simple way to relate neural network representations is via linear regression. One can fit every feature in YYY as a linear combination of features from XXX. A suitable summary statistic is the total fraction of variance explained by the fit:

用线性回归来联系神经网络表示,是一种简单做法。可以把 YYY 中的每一个特征拟合成 XXX 中特征的线性组合。一个合适的汇总统计量,是拟合所解释的总方差比例:

RLR2=1−min⁡B∥Y−XB∥F2∥Y∥F2=∥QY⊤X∥F2∥X∥F2.(5)R^{2}_{\mathrm{LR}} = 1 - \frac{\min_{B} \|Y - XB\|_{F}^{2}}{\|Y\|_{F}^{2}} = \frac{\|Q_Y^{\top} X\|_{F}^{2}}{\|X\|_{F}^{2}}. \qquad (5)RLR2​=1−∥Y∥F2​minB​∥Y−XB∥F2​​=∥X∥F2​∥QY⊤​X∥F2​​.(5)

We are unaware of any application of linear regression to measuring similarity of neural network representations, although Romero et al. (2015) used a least squares loss between activations of two networks to encourage thin and deep “student” networks to learn functions similar to wide and shallow “teacher” networks.

我们尚未见到把线性回归用于度量神经网络表示相似性的工作,不过 Romero et al. (2015) 曾使用两个网络激活之间的最小二乘损失,来促使又瘦又深的“学生”网络去学习与又宽又浅的“教师”网络相似的函数。

Canonical Correlation Analysis (CCA).

典型相关分析(CCA)。

Canonical correlation finds bases for two matrices such that, when the original matrices are projected onto these bases, the correlation is maximized. For 1≤i≤p11 \le i \le p_11≤i≤p1​, the ithi^{\mathrm{th}}ith canonical correlation coefficient ρi\rho_iρi​ is given by:

典型相关为两个矩阵寻找基,使得把原矩阵投影到这些基上之后,相关性达到最大。对 1≤i≤p11 \le i \le p_11≤i≤p1​,第 iii 个典型相关系数 ρi\rho_iρi​ 由下式给出:

ρi=max⁡wXi, wYicorr(XwXi,YwYi)\rho_i = \max_{\mathbf{w}_{X}^{i},\,\mathbf{w}_{Y}^{i}} \mathrm{corr}(X\mathbf{w}_{X}^{i}, Y\mathbf{w}_{Y}^{i})ρi​=wXi​,wYi​max​corr(XwXi​,YwYi​)

subject to ∀j<i XwXj⊥XwXi,∀j<i YwYj⊥YwYi.(6)\text{subject to } \forall_{j<i}\, X\mathbf{w}_{X}^{j} \perp X\mathbf{w}_{X}^{i}, \qquad \forall_{j<i}\, Y\mathbf{w}_{Y}^{j} \perp Y\mathbf{w}_{Y}^{i}. \qquad (6)subject to ∀j<i​XwXj​⊥XwXi​,∀j<i​YwYj​⊥YwYi​.(6)

The vectors wXi∈Rp1\mathbf{w}_{X}^{i} \in \mathbb{R}^{p_1}wXi​∈Rp1​ and wYi∈Rp2\mathbf{w}_{Y}^{i} \in \mathbb{R}^{p_2}wYi​∈Rp2​ that maximize ρi\rho_iρi​ are the canonical weights, which transform the original data into canonical variables XwXiX\mathbf{w}_{X}^{i}XwXi​ and YwYiY\mathbf{w}_{Y}^{i}YwYi​. The constraints in (6) enforce orthogonality of the canonical variables.

使 ρi\rho_iρi​ 最大的向量 wXi∈Rp1\mathbf{w}_{X}^{i} \in \mathbb{R}^{p_1}wXi​∈Rp1​ 和 wYi∈Rp2\mathbf{w}_{Y}^{i} \in \mathbb{R}^{p_2}wYi​∈Rp2​ 是典型权重,它们把原始数据变换为典型变量 XwXiX\mathbf{w}_{X}^{i}XwXi​ 和 YwYiY\mathbf{w}_{Y}^{i}YwYi​。(6) 中的约束强制典型变量彼此正交。

For the purpose of this work, we consider two summary statistics of the goodness of fit of CCA:

就本文而言,我们考虑 CCA 拟合优度的两个汇总统计量:

RCCA2=∑i=1p1ρi2p1=∥QY⊤QX∥F2p1,(7)R^{2}_{\mathrm{CCA}} = \frac{\sum_{i=1}^{p_1} \rho_i^{2}}{p_1} = \frac{\|Q_Y^{\top} Q_X\|_{F}^{2}}{p_1}, \qquad (7)RCCA2​=p1​∑i=1p1​​ρi2​​=p1​∥QY⊤​QX​∥F2​​,(7)

ρˉCCA=∑i=1p1ρip1=∥QY⊤QX∥∗p1,(8)\bar{\rho}_{\mathrm{CCA}} = \frac{\sum_{i=1}^{p_1} \rho_i}{p_1} = \frac{\|Q_Y^{\top} Q_X\|_{*}}{p_1}, \qquad (8)ρˉ​CCA​=p1​∑i=1p1​​ρi​​=p1​∥QY⊤​QX​∥∗​​,(8)

where ∥⋅∥∗\|\cdot\|_*∥⋅∥∗​ denotes the nuclear norm. The mean squared CCA correlation RCCA2R^{2}_{\mathrm{CCA}}RCCA2​ is also known as Yanai’s GCD measure (Ramsay et al., 1984), and several statistical packages report the sum of the squared canonical correlations p1RCCA2=∑i=1p1ρi2p_1 R^{2}_{\mathrm{CCA}} = \sum_{i=1}^{p_1} \rho_i^{2}p1​RCCA2​=∑i=1p1​​ρi2​ under the name Pillai’s trace (SAS Institute, 2015; StataCorp, 2015). The mean CCA correlation ρˉCCA\bar{\rho}_{\mathrm{CCA}}ρˉ​CCA​ was previously used to measure similarity between neural network representations in Raghu et al. (2017).

其中 ∥⋅∥∗\|\cdot\|_*∥⋅∥∗​ 表示核范数。平均平方 CCA 相关 RCCA2R^{2}_{\mathrm{CCA}}RCCA2​ 也称为 Yanai 的 GCD 度量(Ramsay et al., 1984);若干统计软件包把平方典型相关之和 p1RCCA2=∑i=1p1ρi2p_1 R^{2}_{\mathrm{CCA}} = \sum_{i=1}^{p_1} \rho_i^{2}p1​RCCA2​=∑i=1p1​​ρi2​ 以 Pillai 迹的名称报告(SAS Institute, 2015; StataCorp, 2015)。平均 CCA 相关 ρˉCCA\bar{\rho}_{\mathrm{CCA}}ρˉ​CCA​ 曾被 Raghu et al. (2017) 用来度量神经网络表示之间的相似性。

SVCCA.

SVCCA。

CCA is sensitive to perturbation when the condition number of XXX or YYY is large (Golub & Zha, 1995). To improve robustness, singular vector CCA (SVCCA) performs CCA on truncated singular value decompositions of XXX and YYY (Raghu et al., 2017; Mroueh et al., 2015; Kuss & Graepel, 2003). As formulated in Raghu et al. (2017), SVCCA keeps enough principal components of the input matrices to explain a fixed proportion of the variance, and drops remaining components. Thus, it is invariant to invertible linear transformation only if the retained subspace does not change.

当 XXX 或 YYY 的条件数很大时,CCA 对扰动敏感(Golub & Zha, 1995)。为提高稳健性,奇异向量 CCA(SVCCA)在 XXX 和 YYY 的截断奇异值分解上做 CCA(Raghu et al., 2017; Mroueh et al., 2015; Kuss & Graepel, 2003)。按 Raghu et al. (2017) 的表述,SVCCA 保留足以解释固定比例方差的主成分,并丢掉其余成分。因此,只有在所保留的子空间不变时,它才对可逆线性变换不变。

Projection-Weighted CCA.

投影加权 CCA。

Morcos et al. (2018) propose a different strategy to reduce the sensitivity of CCA to perturbation, which they term “projection-weighted canonical correlation” (PWCCA):

Morcos et al. (2018) 提出另一种降低 CCA 对扰动敏感性的策略,他们称之为“投影加权典型相关”(PWCCA):

ρPW=∑i=1cαiρi∑i=1cαi,αi=∑j∣⟨hi,xj⟩∣,(9)\rho_{\mathrm{PW}} = \frac{\sum_{i=1}^{c} \alpha_i \rho_i}{\sum_{i=1}^{c} \alpha_i}, \qquad \alpha_i = \sum_{j} |\langle \mathbf{h}_i, \mathbf{x}_j \rangle|, \qquad (9)ρPW​=∑i=1c​αi​∑i=1c​αi​ρi​​,αi​=j∑​∣⟨hi​,xj​⟩∣,(9)

where xj\mathbf{x}_jxj​ is the jthj^{\mathrm{th}}jth column of XXX, and hi=XwXi\mathbf{h}_i = X\mathbf{w}_{X}^{i}hi​=XwXi​ is the vector of canonical variables formed by projecting XXX to the ithi^{\mathrm{th}}ith canonical coordinate frame. As we show in Appendix C.3, PWCCA is closely related to linear regression, since:

其中 xj\mathbf{x}_jxj​ 是 XXX 的第 jjj 列,hi=XwXi\mathbf{h}_i = X\mathbf{w}_{X}^{i}hi​=XwXi​ 是把 XXX 投影到第 iii 个典型坐标架得到的典型变量向量。如我们在附录 C.3 中所示,PWCCA 与线性回归密切相关,因为:

RLR2=∑i=1cαi′ρi2∑i=1cαi′,αi′=∑j⟨hi,xj⟩2.(10)R^{2}_{\mathrm{LR}} = \frac{\sum_{i=1}^{c} \alpha'_i \rho_i^{2}}{\sum_{i=1}^{c} \alpha'_i}, \qquad \alpha'_i = \sum_{j} \langle \mathbf{h}_i, \mathbf{x}_j \rangle^{2}. \qquad (10)RLR2​=∑i=1c​αi′​∑i=1c​αi′​ρi2​​,αi′​=j∑​⟨hi​,xj​⟩2.(10)

Neuron Alignment Procedures.

神经元对齐方法。

Other work has studied alignment between individual neurons, rather than alignment between subspaces. Li et al. (2015) examined correlation between the neurons in different neural networks, and attempt to find a bipartite match or semi-match that maximizes the sum of the correlations between the neurons, and then to measure the average correlations. Wang et al. (2018) proposed to search for subsets of neurons X~⊂X\tilde{X} \subset XX~⊂X and Y~⊂Y\tilde{Y} \subset YY~⊂Y such that, to within some tolerance, every neuron in X~\tilde{X}X~ can be represented by a linear combination of neurons from Y~\tilde{Y}Y~ and vice versa. They found that the maximum matching subsets are very small for intermediate layers.

另有工作研究的是单个神经元之间的对齐,而不是子空间之间的对齐。Li et al. (2015) 考察不同神经网络中神经元之间的相关,并试图寻找使神经元相关之和最大的二分匹配或半匹配,再度量平均相关。Wang et al. (2018) 提出寻找神经元子集 X~⊂X\tilde{X} \subset XX~⊂X 和 Y~⊂Y\tilde{Y} \subset YY~⊂Y,使得在某一容差内,X~\tilde{X}X~ 中的每个神经元都可以写成 Y~\tilde{Y}Y~ 中神经元的线性组合,反之亦然。他们发现,对中间层而言,最大可匹配子集非常小。

Mutual Information.

互信息。

Among non-linear measures, one candidate is mutual information, which is invariant not only to invertible linear transformation, but to any invertible transformation. Li et al. (2015) previously used mutual information to measure neuronal alignment. In the context of comparing representations, we believe mutual information is not useful. Given any pair of representations produced by deterministic functions of the same input, mutual information between either and the input must be at least as large as mutual information between the representations. Moreover, in fully invertible neural networks (Dinh et al., 2017; Jacobsen et al., 2018), the mutual information between any two layers is equal to the entropy of the input.

在非线性度量中,一个候选是互信息:它不仅对可逆线性变换不变,而且对任意可逆变换都不变。Li et al. (2015) 曾用互信息来度量神经元对齐。在比较表示这一语境下,我们认为互信息并无用处。给定由同一输入的确定性函数产生的任意一对表示,其中任一表示与输入之间的互信息,至少不小于这两个表示之间的互信息。此外,在完全可逆的神经网络中(Dinh et al., 2017; Jacobsen et al., 2018),任意两层之间的互信息都等于输入的熵。

5. Linear CKA versus CCA and Regression

5. 线性 CKA 与 CCA、回归的关系

Linear CKA is closely related to CCA and linear regression. If XXX and YYY are centered, then QXQ_XQX​ and QYQ_YQY​ are also centered, so:

线性 CKA 与 CCA 和线性回归密切相关。若 XXX 和 YYY 已经中心化,则 QXQ_XQX​ 和 QYQ_YQY​ 也已中心化,因此:

RCCA2=CKA(QXQX⊤,QYQY⊤)p2p1.(11)R^{2}_{\mathrm{CCA}} = \mathrm{CKA}(Q_X Q_X^{\top}, Q_Y Q_Y^{\top}) \sqrt{\frac{p_2}{p_1}}. \qquad (11)RCCA2​=CKA(QX​QX⊤​,QY​QY⊤​)p1​p2​​​.(11)

When performing the linear regression fit of XXX with design matrix YYY, RLR2=∥QY⊤X∥F2/∥X∥F2R^{2}_{\mathrm{LR}} = \|Q_Y^{\top} X\|_{F}^{2}/\|X\|_{F}^{2}RLR2​=∥QY⊤​X∥F2​/∥X∥F2​, so:

当用设计矩阵 YYY 对 XXX 做线性回归拟合时,RLR2=∥QY⊤X∥F2/∥X∥F2R^{2}_{\mathrm{LR}} = \|Q_Y^{\top} X\|_{F}^{2}/\|X\|_{F}^{2}RLR2​=∥QY⊤​X∥F2​/∥X∥F2​,因此:

RLR2=CKA(XX⊤,QYQY⊤)p1 ∥X⊤X∥F∥X∥F2.(12)R^{2}_{\mathrm{LR}} = \mathrm{CKA}(XX^{\top}, Q_Y Q_Y^{\top}) \frac{\sqrt{p_1}\,\|X^{\top} X\|_{F}}{\|X\|_{F}^{2}}. \qquad (12)RLR2​=CKA(XX⊤,QY​QY⊤​)∥X∥F2​p1​​∥X⊤X∥F​​.(12)

When might we prefer linear CKA over CCA? One way to show the difference is to rewrite XXX and YYY in terms of their singular value decompositions X=UXΣXVX⊤X = U_X \Sigma_X V_X^{\top}X=UX​ΣX​VX⊤​, Y=UYΣYVY⊤Y = U_Y \Sigma_Y V_Y^{\top}Y=UY​ΣY​VY⊤​. Let the ithi^{\mathrm{th}}ith eigenvector of XX⊤XX^{\top}XX⊤ (left-singular vector of XXX) be indexed as uXi\mathbf{u}_{X}^{i}uXi​. Then RCCA2R^{2}_{\mathrm{CCA}}RCCA2​ is:

什么时候我们会更愿意用线性 CKA 而不是 CCA?展示二者差别的一种方式,是把 XXX 和 YYY 写成奇异值分解 X=UXΣXVX⊤X = U_X \Sigma_X V_X^{\top}X=UX​ΣX​VX⊤​、Y=UYΣYVY⊤Y = U_Y \Sigma_Y V_Y^{\top}Y=UY​ΣY​VY⊤​。把 XX⊤XX^{\top}XX⊤ 的第 iii 个特征向量(即 XXX 的左奇异向量)记为 uXi\mathbf{u}_{X}^{i}uXi​。则 RCCA2R^{2}_{\mathrm{CCA}}RCCA2​ 为:

RCCA2=∥UY⊤UX∥F2/p1=∑i=1p1∑j=1p2⟨uXi,uYj⟩2/p1.(13)R^{2}_{\mathrm{CCA}} = \|U_Y^{\top} U_X\|_{F}^{2}/p_1 = \sum_{i=1}^{p_1} \sum_{j=1}^{p_2} \langle \mathbf{u}_{X}^{i}, \mathbf{u}_{Y}^{j} \rangle^{2} / p_1. \qquad (13)RCCA2​=∥UY⊤​UX​∥F2​/p1​=i=1∑p1​​j=1∑p2​​⟨uXi​,uYj​⟩2/p1​.(13)

Let the ithi^{\mathrm{th}}ith eigenvalue of XX⊤XX^{\top}XX⊤ (squared singular value of XXX) be indexed as λXi\lambda_{X}^{i}λXi​. Linear CKA can be written as:

把 XX⊤XX^{\top}XX⊤ 的第 iii 个特征值(即 XXX 的奇异值平方)记为 λXi\lambda_{X}^{i}λXi​。线性 CKA 可以写成:

CKA(XX⊤,YY⊤)=∥Y⊤X∥F2∥X⊤X∥F ∥Y⊤Y∥F=∑i=1p1∑j=1p2λXiλYj⟨uXi,uYj⟩2∑i=1p1(λXi)2∑j=1p2(λYj)2.(14)\mathrm{CKA}(XX^{\top}, YY^{\top}) = \frac{\|Y^{\top} X\|_{F}^{2}}{\|X^{\top} X\|_{F}\,\|Y^{\top} Y\|_{F}} = \frac{\sum_{i=1}^{p_1} \sum_{j=1}^{p_2} \lambda_{X}^{i} \lambda_{Y}^{j} \langle \mathbf{u}_{X}^{i}, \mathbf{u}_{Y}^{j} \rangle^{2}}{\sqrt{\sum_{i=1}^{p_1} (\lambda_{X}^{i})^{2}} \sqrt{\sum_{j=1}^{p_2} (\lambda_{Y}^{j})^{2}}}. \qquad (14)CKA(XX⊤,YY⊤)=∥X⊤X∥F​∥Y⊤Y∥F​∥Y⊤X∥F2​​=∑i=1p1​​(λXi​)2​∑j=1p2​​(λYj​)2​∑i=1p1​​∑j=1p2​​λXi​λYj​⟨uXi​,uYj​⟩2​.(14)

Linear CKA thus resembles CCA weighted by the eigenvalues of the corresponding eigenvectors, i.e. the amount of variance in XXX or YYY that each explains. SVCCA (Raghu et al., 2017) and projection-weighted CCA (Morcos et al., 2018) were also motivated by the idea that eigenvectors that correspond to small eigenvalues are less important, but linear CKA incorporates this weighting symmetrically and can be computed without a matrix decomposition.

因此,线性 CKA 很像按相应特征向量的特征值——也就是它们各自解释的 XXX 或 YYY 中的方差量——加权后的 CCA。SVCCA(Raghu et al., 2017)和投影加权 CCA(Morcos et al., 2018)的动机同样是:对应小特征值的特征向量不那么重要;但线性 CKA 以对称的方式纳入这种加权,并且不必做矩阵分解就能计算。

Comparison of (13) and (14) immediately suggests the possibility of alternative weightings of scalar products between eigenvectors. Indeed, as we show in Appendix D.1, the similarity index induced by “canonical ridge” regularized CCA (Vinod, 1976), when appropriately normalized, interpolates between RCCA2R^{2}_{\mathrm{CCA}}RCCA2​, linear regression, and linear CKA.

比较 (13) 和 (14),会立刻想到还可以对特征向量之间的内积采用别的加权方式。事实上,如我们在附录 D.1 中所示,由“典型岭”正则化 CCA(Vinod, 1976)诱导的相似性指标,在适当归一化后,会在 RCCA2R^{2}_{\mathrm{CCA}}RCCA2​、线性回归和线性 CKA 之间插值。

6. Results

6. 结果

6.1. A Sanity Check for Similarity Indexes

6.1. 相似性指标的一项健全性检查

We propose a simple sanity check for similarity indexes: Given a pair of architecturally identical networks trained from different random initializations, for each layer in the first network, the most similar layer in the second network should be the architecturally corresponding layer. We train 10 networks and, for each layer of each network, we compute the accuracy with which we can find the corresponding layer in each of the other networks by maximum similarity. We then average the resulting accuracies. We compare CKA with CCA, SVCCA, PWCCA, and linear regression.

我们为相似性指标提出一项简单的健全性检查:给定一对结构相同、从不同随机初始化训出的网络,对第一个网络中的每一层,第二个网络里最相似的一层应当是结构上相对应的那一层。我们训练 10 个网络,并对每个网络的每一层,计算能否凭借最大相似性、在其余每个网络中找到对应层的准确率,再对得到的准确率取平均。我们把 CKA 与 CCA、SVCCA、PWCCA 和线性回归相比较。

Six heatmaps of layer-to-layer similarity for CCA, linear regression, SVCCA, and CKA on CNNs trained from different initializations.

Figure 2. CKA reveals consistent relationships between layers of CNNs trained with different random initializations, whereas CCA, linear regression, and SVCCA do not. For linear regression, which is asymmetric, we plot R2R^{2}R2 for the fit of the layer on the x-axis with the layer on the y-axis. Results are averaged over 10 networks. See Table 2 for a numerical summary.

图 2. CKA 能够揭示从不同随机初始化训出的 CNN 各层之间一致的关系,而 CCA、线性回归和 SVCCA 则不能。线性回归是不对称的,我们画出的是用 xxx 轴上的层去拟合 yyy 轴上的层的 R2R^{2}R2。结果对 10 个网络取平均。数值汇总见表 2。

Table 2. Accuracy of identifying corresponding layers based on maximum similarity for 10 architecturally identical 10-layer CNNs trained from different initializations, with logits layers excluded. For SVCCA, we used a truncation threshold of 0.99 as recommended in Raghu et al. (2017). For asymmetric indexes (PWCCA and linear regression) we symmetrized the similarity as S+S⊤S + S^{\top}S+S⊤. CKA RBF kernel parameters reflect the fraction of the median Euclidean distance used as σ\sigmaσ. Results not significantly different from the best result are bold-faced (p<0.05p < 0.05p<0.05, jackknife zzz-test).

Index Accuracy
CCA (ρˉ\bar{\rho}ρˉ​) 1.4
CCA (RCCA2R^{2}_{\mathrm{CCA}}RCCA2​) 10.6
SVCCA (ρˉ\bar{\rho}ρˉ​) 9.9
SVCCA (RCCA2R^{2}_{\mathrm{CCA}}RCCA2​) 15.1
PWCCA 11.1
Linear Reg. 45.4
Linear HSIC 22.2
CKA (Linear) 99.3
CKA (RBF 0.2) 80.6
CKA (RBF 0.4) 99.1
CKA (RBF 0.8) 99.3

表 2. 依据最大相似性识别对应层的准确率:10 个结构相同的 10 层 CNN,从不同初始化训练,不含 logits 层。 对 SVCCA,我们按 Raghu et al. (2017) 的建议使用 0.99 的截断阈值。对不对称指标(PWCCA 和线性回归),我们用 S+S⊤S + S^{\top}S+S⊤ 把相似性对称化。CKA 的 RBF 核参数表示用作 σ\sigmaσ 的中位欧氏距离的分数。与最好结果无显著差异的数字加粗(p<0.05p < 0.05p<0.05,jackknife zzz 检验)。

指标 准确率
CCA (ρˉ\bar{\rho}ρˉ​) 1.4
CCA (RCCA2R^{2}_{\mathrm{CCA}}RCCA2​) 10.6
SVCCA (ρˉ\bar{\rho}ρˉ​) 9.9
SVCCA (RCCA2R^{2}_{\mathrm{CCA}}RCCA2​) 15.1
PWCCA 11.1
Linear Reg. 45.4
Linear HSIC 22.2
CKA (Linear) 99.3
CKA (RBF 0.2) 80.6
CKA (RBF 0.4) 99.1
CKA (RBF 0.8) 99.3

We first investigate a simple VGG-like convolutional network based on All-CNN-C (Springenberg et al., 2015) (see Appendix E for architecture details). Figure 2 and Table 2 show that CKA passes our sanity check, but other methods perform substantially worse. For SVCCA, we experimented with a range of truncation thresholds, but no threshold revealed the layer structure (Appendix F.2); our results are consistent with those in Appendix E of Raghu et al. (2017).

我们首先考察一个基于 All-CNN-C(Springenberg et al., 2015)的简单类 VGG 卷积网络(架构细节见附录 E)。图 2 和表 2 表明,CKA 通过了我们的健全性检查,而其他方法要差得多。对 SVCCA,我们尝试了一系列截断阈值,但没有任何阈值能揭示层结构(附录 F.2);我们的结果与 Raghu et al. (2017) 附录 E 中的结果一致。

We also investigate Transformer networks, where all layers are of equal width. In Appendix F.1, we show similarity between the 12 sublayers of the encoders of Transformer models (Vaswani et al., 2017) trained from different random initializations. All similarity indexes achieve non-trivial accuracy and thus pass the sanity check, although RBF CKA and RCCA2R^{2}_{\mathrm{CCA}}RCCA2​ performed slightly better than other methods. However, we found that there are differences in feature scale between representations of feed-forward network and self-attention sublayers that CCA does not capture because it is invariant to non-isotropic scaling.

我们也考察了各层宽度相同的 Transformer 网络。在附录 F.1 中,我们展示了从不同随机初始化训出的 Transformer 模型(Vaswani et al., 2017)编码器中 12 个子层之间的相似性。所有相似性指标都达到了非平凡的准确率,因而通过了健全性检查,不过 RBF CKA 和 RCCA2R^{2}_{\mathrm{CCA}}RCCA2​ 比其他方法略好。然而我们发现,前馈网络子层与自注意力子层的表示在特征尺度上存在差异,CCA 因为对非各向同性缩放不变而捕捉不到这一点。

6.2. Using CKA to Understand Network Architectures

6.2. 用 CKA 理解网络结构

CKA can reveal pathology in neural networks representations. In Figure 3, we show CKA between layers of individual CNNs with different depths, where layers are repeated 2, 4, or 8 times. Doubling depth improved accuracy, but greater multipliers hurt accuracy. At 8x depth, CKA indicates that representations of more than half of the network are very similar to the last layer. We validated that these later layers do not refine the representation by training an ℓ2\ell^{2}ℓ2-regularized logistic regression classifier on each layer of the network. Classification accuracy in shallower architectures progressively improves with depth, but for the 8x deeper network, accuracy plateaus less than halfway through the network.

CKA 能够揭示神经网络表示中的病变。在图 3 中,我们展示了不同深度的单个 CNN 各层之间的 CKA,其中层被重复 2、4 或 8 次。把深度加倍提高了准确率,但更大的倍数反而损害准确率。在 8 倍深度时,CKA 表明网络一半以上的表示都与最后一层非常相似。我们通过在网络的每一层上训练一个 ℓ2\ell^{2}ℓ2 正则的逻辑回归分类器,验证了这些更靠后的层并没有再改进表示。较浅结构中的分类准确率随深度逐步提高,但在 8 倍更深的网络里,准确率在不到一半深度处就趋于平台。

Linear CKA heatmaps and logistic regression accuracy curves for CNNs of 1x, 2x, 4x, and 8x depth on CIFAR-10.

Figure 3. CKA reveals when depth becomes pathological. Top: Linear CKA between layers of individual networks of different depths on CIFAR-10. Titles show accuracy of each network. Later layers of the 8x depth network are similar to the last layer. Bottom: Accuracy of a logistic regression classifier trained on layers of the same networks is consistent with CKA.

图 3. CKA 能够揭示深度何时变得病变。上:CIFAR-10 上不同深度的单个网络各层之间的线性 CKA。标题给出各网络的准确率。8 倍深度网络的后半段层与最后一层相似。下:在同一批网络各层上训练的逻辑回归分类器准确率,与 CKA 相一致。

When applied to ResNets (He et al., 2016), CKA reveals no pathology (Figure 4). We instead observe a grid pattern that originates from the architecture: Post-residual activations are similar to other post-residual activations, but activations within blocks are not.

用到 ResNet(He et al., 2016)上时,CKA 并未揭示病变(图 4)。我们看到的是一种来自结构本身的网格图案:残差之后的激活与其他残差之后的激活相似,但块内部的激活则不然。

Linear CKA heatmaps of a ResNet-62 model for all layers, even layers, and odd layers.

Figure 4. Linear CKA between layers of a ResNet-62 model. The grid pattern for ResNets in the left panel arises from the architecture. Right panels show similarity separately for even layer (post-residual) and odd layer (block interior) activations. Layers in the same block group (i.e. at the same feature map scale) are more similar than layers in different block groups.

图 4. ResNet-62 模型各层之间的线性 CKA。左图中 ResNet 的网格图案来自其结构。右侧两图分别给出偶数层(残差之后)和奇数层(块内部)激活的相似性。同一块组(也就是同一特征图尺度)中的层,比不同块组中的层更相似。

CKA is equally effective at revealing relationships between layers of different architectures. Figure 5 shows the relationship between different layers of networks with and without residual connections. CKA indicates that, as networks are made deeper, the new layers are effectively inserted in between the old layers. Other similarity indexes fail to reveal meaningful relationships between different architectures, as we show in Appendix F.5.

CKA 同样擅长揭示不同结构各层之间的关系。图 5 给出了有残差连接和没有残差连接的网络中不同层之间的关系。CKA 表明,当网络被做得更深时,新层实际上是被插入到旧层之间。其他相似性指标无法揭示不同结构之间有意义的关系,我们在附录 F.5 中展示了这一点。

Linear CKA heatmaps comparing layers of Plain-10, Plain-18, ResNet-14, and ResNet-32 networks.

Figure 5. Linear CKA between layers of networks with different architectures.

图 5. 不同结构网络各层之间的线性 CKA。

In Figure 6, we show CKA between networks with different layer widths. Like Morcos et al. (2018), we find that increasing layer width leads to more similar representations between networks. As width increases, CKA approaches 1; CKA of earlier layers saturates faster than later layers. Networks are generally more similar to other networks of the same width than they are to the widest network we trained.

在图 6 中,我们展示了不同层宽的网络之间的 CKA。与 Morcos et al. (2018) 类似,我们发现增加层宽会使网络之间的表示更相似。随着宽度增加,CKA 趋近 1;浅层的 CKA 比深层饱和得更快。网络通常与同宽的其他网络更相似,而不是与我们训练过的最宽网络更相似。

Line plots of linear CKA versus width, showing similarity to a width-4096 network and to same-width networks.

Figure 6. Layers become more similar to each other and to wide networks as width increases, but similarity of earlier layers saturates first. Left: Similarity of networks with the widest network we trained. Middle: Similarity of networks with other networks of the same width trained from random initialization. All CKA values are computed between 10 networks; shaded regions reflect jackknife standard error.

图 6. 随着宽度增加,各层彼此之间以及与宽网络之间变得更相似,但浅层的相似性先饱和。左:各网络与我们训练过的最宽网络之间的相似性。中:各网络与从随机初始化训出的同宽其他网络之间的相似性。所有 CKA 值都在 10 个网络之间计算;阴影区域表示 jackknife 标准误差。

6.3. Similar Representations Across Datasets

6.3. 跨数据集的相似表示

CKA can also be used to compare networks trained on different datasets. In Figure 7, we show that models trained on CIFAR-10 and CIFAR-100 develop similar representations in their early layers. These representations require training; similarity with untrained networks is much lower. We further explore similarity between layers of untrained networks in Appendix F.3.

CKA 也可以用来比较在不同数据集上训练的网络。在图 7 中我们表明,在 CIFAR-10 和 CIFAR-100 上训练的模型,会在浅层形成相似的表示。这些表示需要经过训练;与未训练网络之间的相似性要低得多。我们在附录 F.3 中进一步考察了未训练网络各层之间的相似性。

Line plots of CKA between models trained on CIFAR-10 and CIFAR-100, and versus untrained models.

Figure 7. CKA shows that models trained on different datasets (CIFAR-10 and CIFAR-100) develop similar representations, and these representations differ from untrained models. The left panel shows similarity between the same layer of different models on the CIFAR-10 test set, while the right panel shows similarity computed on CIFAR-100 test set. CKA is averaged over 10 models of each type (45 pairs).

图 7. CKA 表明,在不同数据集(CIFAR-10 和 CIFAR-100)上训练的模型会形成相似的表示,并且这些表示与未训练模型不同。左图给出不同模型同一层在 CIFAR-10 测试集上的相似性,右图给出在 CIFAR-100 测试集上计算的相似性。CKA 对每类 10 个模型取平均(45 对)。

6.4. Analysis of the Shared Subspace

6.4. 共享子空间的分析

Equation 14 suggests a way to further elucidating what CKA is measuring, based on the action of one representational similarity matrix (RSM) YY⊤YY^{\top}YY⊤ applied to the eigenvectors uXi\mathbf{u}_{X}^{i}uXi​ of the other RSM XX⊤XX^{\top}XX⊤. By definition, XX⊤uXiXX^{\top}\mathbf{u}_{X}^{i}XX⊤uXi​ points in the same direction as uXi\mathbf{u}_{X}^{i}uXi​, and its norm ∥XX⊤uXi∥2\|XX^{\top}\mathbf{u}_{X}^{i}\|_{2}∥XX⊤uXi​∥2​ is the corresponding eigenvalue. The degree of scaling and rotation by YY⊤YY^{\top}YY⊤ thus indicates how similar the action of YY⊤YY^{\top}YY⊤ is to XX⊤XX^{\top}XX⊤, for each eigenvector of XX⊤XX^{\top}XX⊤. For visualization purposes, this approach is somewhat less useful than the CKA summary statistic, since it does not collapse the similarity to a single number, but it provides a more complete picture of what CKA measures. Figure 8 shows that, for large eigenvectors, XX⊤XX^{\top}XX⊤ and YY⊤YY^{\top}YY⊤ have similar actions, but the rank of the subspace where this holds is substantially lower than the dimensionality of the activations. In the penultimate (global average pooling) layer, the dimensionality of the shared subspace is approximately 10, which is the number of classes in the CIFAR-10 dataset.

公式 14 提示了一种进一步阐明 CKA 在度量什么的方法:看一张表示相似性矩阵(RSM)YY⊤YY^{\top}YY⊤ 作用在另一张 RSM XX⊤XX^{\top}XX⊤ 的特征向量 uXi\mathbf{u}_{X}^{i}uXi​ 上会怎样。按定义,XX⊤uXiXX^{\top}\mathbf{u}_{X}^{i}XX⊤uXi​ 与 uXi\mathbf{u}_{X}^{i}uXi​ 方向相同,其范数 ∥XX⊤uXi∥2\|XX^{\top}\mathbf{u}_{X}^{i}\|_{2}∥XX⊤uXi​∥2​ 就是对应的特征值。因此,YY⊤YY^{\top}YY⊤ 造成的缩放和旋转程度,就表明对 XX⊤XX^{\top}XX⊤ 的每个特征向量而言,YY⊤YY^{\top}YY⊤ 的作用与 XX⊤XX^{\top}XX⊤ 有多相似。就可视化而言,这种方法不如 CKA 汇总统计量好用,因为它并不把相似性压成一个数,但它能更完整地刻画 CKA 所度量的内容。图 8 表明,对大的特征向量,XX⊤XX^{\top}XX⊤ 和 YY⊤YY^{\top}YY⊤ 的作用相似,但这种相似性成立的子空间秩,远低于激活的维数。在倒数第二层(全局平均池化层),共享子空间的维数大约是 10,也就是 CIFAR-10 数据集的类别数。

Scaling and rotation plots of shared subspaces between two Tiny-10 networks at conv1, conv4, and average pooling layers.

Figure 8. The shared subspace of two Tiny-10 networks trained from random initialization is spanned primarily by the eigenvectors corresponding to the largest eigenvalues. Each row represents a different network layer. Note that the average pooling layer has only 64 units. Left: Scaling of the eigenvectors uXi\mathbf{u}_{X}^{i}uXi​ of the RSM XX⊤XX^{\top}XX⊤ from network A by RSMs of networks A and B. Orange lines show ∥XX⊤uXi∥2\|XX^{\top}\mathbf{u}_{X}^{i}\|_{2}∥XX⊤uXi​∥2​, i.e. the eigenvalues. Purple dots show ∥YY⊤uXi∥2\|YY^{\top}\mathbf{u}_{X}^{i}\|_{2}∥YY⊤uXi​∥2​, the scaling of the eigenvectors of the RSM of network A by the RSM of network B. Right: Cosine of the rotation by the RSM of network B, (uXi)⊤YY⊤uXi/∥YY⊤uXi∥2(\mathbf{u}_{X}^{i})^{\top} YY^{\top} \mathbf{u}_{X}^{i} / \|YY^{\top}\mathbf{u}_{X}^{i}\|_{2}(uXi​)⊤YY⊤uXi​/∥YY⊤uXi​∥2​.

图 8. 两个从随机初始化训出的 Tiny-10 网络,其共享子空间主要由最大特征值对应的特征向量张成。每一行代表网络的不同层。注意平均池化层只有 64 个单元。左:网络 A 的 RSM XX⊤XX^{\top}XX⊤ 的特征向量 uXi\mathbf{u}_{X}^{i}uXi​ 被网络 A 和 B 的 RSM 缩放的情况。橙色线表示 ∥XX⊤uXi∥2\|XX^{\top}\mathbf{u}_{X}^{i}\|_{2}∥XX⊤uXi​∥2​,即特征值。紫色点表示 ∥YY⊤uXi∥2\|YY^{\top}\mathbf{u}_{X}^{i}\|_{2}∥YY⊤uXi​∥2​,也就是网络 B 的 RSM 对网络 A 的 RSM 特征向量的缩放。右:网络 B 的 RSM 造成的旋转余弦 (uXi)⊤YY⊤uXi/∥YY⊤uXi∥2(\mathbf{u}_{X}^{i})^{\top} YY^{\top} \mathbf{u}_{X}^{i} / \|YY^{\top}\mathbf{u}_{X}^{i}\|_{2}(uXi​)⊤YY⊤uXi​/∥YY⊤uXi​∥2​。

7. Conclusion and Future Work

7. 结论与未来工作

Measuring similarity between the representations learned by neural networks is an ill-defined problem, since it is not entirely clear what aspects of the representation a similarity index should focus on. Previous work has suggested that there is little similarity between intermediate layers of neural networks trained from different random initializations (Raghu et al., 2017; Wang et al., 2018). We propose CKA as a method for comparing representations of neural networks, and show that it consistently identifies correspondences between layers, not only in the same network trained from different initializations, but across entirely different architectures, whereas other methods do not. We also provide a unified framework for understanding the space of similarity indexes, as well as an empirical framework for evaluation.

度量神经网络所学表示之间的相似性,是一个定义并不清晰的问题,因为并不完全清楚相似性指标应当关注表示的哪些方面。已有工作认为,从不同随机初始化训出的神经网络,其中间层之间几乎没有相似性(Raghu et al., 2017; Wang et al., 2018)。我们提出用 CKA 来比较神经网络的表示,并表明它能够一致地找出层与层之间的对应:不仅是同一结构、从不同初始化训出的网络,也包括完全不同的结构;而其他方法做不到这一点。我们还提供了一个理解相似性指标空间的统一框架,以及一套经验上的评测框架。

We show that CKA captures intuitive notions of similarity, i.e. that neural networks trained from different initializations should be similar to each other. However, it remains an open question whether there exist kernels beyond the linear and RBF kernels that would be better for analyzing neural network representations. Moreover, there are other potential choices of weighting in Equation 14 that may be more appropriate in certain settings. We leave these questions as future work. Nevertheless, CKA seems to be much better than previous methods at finding correspondences between the learned representations in hidden layers of neural networks.

我们表明,CKA 抓住了对相似性的直觉理解,也就是:从不同初始化训出的神经网络应当彼此相似。不过,在线性核和 RBF 核之外,是否还存在更适合分析神经网络表示的核,仍然是一个开放问题。此外,公式 14 中还有其他可能的加权选择,在某些设定下也许更合适。我们把这些问题留给未来工作。尽管如此,在寻找神经网络隐层所学表示之间的对应关系上,CKA 看起来比以往方法要好得多。

Acknowledgements

We thank Gamaleldin Elsayed, Jaehoon Lee, Paul-Henri Mignot, Maithra Raghu, Samuel L. Smith, and Alex Williams for comments on the manuscript, Rishabh Agarwal for ideas, and Aliza Elkin for support.

References

Advani, M. S. and Saxe, A. M. High-dimensional dynamics of generalization error in neural networks. arXiv preprint arXiv:1710.03667, 2017.

Amari, S.-i., Ozeki, T., Karakida, R., Yoshida, Y., and Okada, M. Dynamics of learning in MLP: Natural gradient and singularity revisited. Neural Computation, 30(1):1–33, 2018.

Björck, Å. and Golub, G. H. Numerical methods for computing angles between linear subspaces. Mathematics of Computation, 27(123):579–594, 1973.

Chen, A. M., Lu, H.-m., and Hecht-Nielsen, R. On the geometry of feedforward neural network error surfaces. Neural Computation, 5(6):910–927, 1993.

Connolly, A. C., Guntupalli, J. S., Gors, J., Hanke, M., Halchenko, Y. O., Wu, Y.-C., Abdi, H., and Haxby, J. V. The representation of biological classes in the human brain. Journal of Neuroscience, 32(8):2608–2618, 2012.

Cortes, C., Mohri, M., and Rostamizadeh, A. Algorithms for learning kernels based on centered alignment. Journal of Machine Learning Research, 13(Mar):795–828, 2012.

Cristianini, N., Shawe-Taylor, J., Elisseeff, A., and Kandola, J. S. On kernel-target alignment. In Advances in Neural Information Processing Systems, 2002.

Dinh, L., Sohl-Dickstein, J., and Bengio, S. Density estimation using real NVP. In International Conference on Learning Representations, 2017.

Dumoulin, V., Shlens, J., and Kudlur, M. A learned representation for artistic style. In International Conference on Learning Representations, 2017.

Edelman, S. Representation is representation of similarities. Behavioral and Brain Sciences, 21(4):449–467, 1998.

Elsayed, G. F., Lara, A. H., Kaufman, M. T., Churchland, M. M., and Cunningham, J. P. Reorganization between preparatory and movement population responses in motor cortex. Nature Communications, 7:13239, 2016.

Freiwald, W. A. and Tsao, D. Y. Functional compartmentalization and viewpoint generalization within the macaque face-processing system. Science, 330(6005):845–851, 2010.

Garriga-Alonso, A., Rasmussen, C. E., and Aitchison, L. Deep convolutional networks as shallow Gaussian processes. In International Conference on Learning Representations, 2019.

Gatys, L. A., Ecker, A. S., and Bethge, M. Image style transfer using convolutional neural networks. In IEEE Conference on Computer Vision and Pattern Recognition, 2016.

Golub, G. H. and Zha, H. The canonical correlations of matrix pairs and their numerical computation. In Linear Algebra for Signal Processing, pp. 27–49. Springer, 1995.

Gretton, A., Bousquet, O., Smola, A., and Schölkopf, B. Measuring statistical dependence with Hilbert-Schmidt norms. In International Conference on Algorithmic Learning Theory, 2005.

Haxby, J. V., Gobbini, M. I., Furey, M. L., Ishai, A., Schouten, J. L., and Pietrini, P. Distributed and overlapping representations of faces and objects in ventral temporal cortex. Science, 293(5539):2425–2430, 2001.

He, K., Zhang, X., Ren, S., and Sun, J. Deep residual learning for image recognition. In IEEE Conference on Computer Vision and Pattern Recognition, 2016.

Ioffe, S. and Szegedy, C. Batch normalization: Accelerating deep network training by reducing internal covariate shift. In International Conference on Machine Learning, 2015.

Jacobsen, J.-H., Smeulders, A. W., and Oyallon, E. i-RevNet: Deep invertible networks. In International Conference on Learning Representations, 2018.

Jacot, A., Gabriel, F., and Hongler, C. Neural tangent kernel: Convergence and generalization in neural networks. In Advances in Neural Information Processing Systems, 2018.

Johnson, J., Alahi, A., and Fei-Fei, L. Perceptual losses for real-time style transfer and super-resolution. In European Conference on Computer Vision, 2016.

Khaligh-Razavi, S.-M. and Kriegeskorte, N. Deep supervised, but not unsupervised, models may explain IT cortical representation. PLoS Computational Biology, 10(11):e1003915, 2014.

Kriegeskorte, N., Mur, M., and Bandettini, P. A. Representational similarity analysis—connecting the branches of systems neuroscience. Frontiers in Systems Neuroscience, 2:4, 2008a.

Kriegeskorte, N., Mur, M., Ruff, D. A., Kiani, R., Bodurka, J., Esteky, H., Tanaka, K., and Bandettini, P. A. Matching categorical object representations in inferior temporal cortex of man and monkey. Neuron, 60(6):1126–1141, 2008b.

Kuss, M. and Graepel, T. The geometry of kernel canonical correlation analysis. Technical report, Max Planck Institute for Biological Cybernetics, 2003.

Laakso, A. and Cottrell, G. Content and cluster analysis: assessing representational similarity in neural systems. Philosophical Psychology, 13(1):47–76, 2000.

LeCun, Y., Kanter, I., and Solla, S. A. Second order properties of error surfaces: Learning time and generalization. In Advances in Neural Information Processing Systems, 1991.

Lee, J., Sohl-Dickstein, J., Pennington, J., Novak, R., Schoenholz, S., and Bahri, Y. Deep neural networks as Gaussian processes. In International Conference on Learning Representations, 2018.

Li, Y., Yosinski, J., Clune, J., Lipson, H., and Hopcroft, J. Convergent learning: Do different neural networks learn the same representations? In NIPS 2015 Workshop on Feature Extraction: Modern Questions and Challenges, 2015.

Lorenzo-Seva, U. and Ten Berge, J. M. Tucker’s congruence coefficient as a meaningful index of factor similarity. Methodology, 2(2):57–64, 2006.

Morcos, A., Raghu, M., and Bengio, S. Insights on representational similarity in neural networks with canonical correlation. In Advances in Neural Information Processing Systems, 2018.

Mroueh, Y., Marcheret, E., and Goel, V. Asymmetrically weighted CCA and hierarchical kernel sentence embedding for multimodal retrieval. arXiv preprint arXiv:1511.06267, 2015.

Novak, R., Xiao, L., Bahri, Y., Lee, J., Yang, G., Abolafia, D. A., Pennington, J., and Sohl-Dickstein, J. Bayesian deep convolutional networks with many channels are Gaussian processes. In International Conference on Learning Representations, 2019.

Orhan, E. and Pitkow, X. Skip connections eliminate singularities. In International Conference on Learning Representations, 2018.

Press, W. H. Canonical correlation clarified by singular value decomposition, 2011. URL http://numerical.recipes/whp/notes/CanonCorrBySVD.pdf.

Raghu, M., Gilmer, J., Yosinski, J., and Sohl-Dickstein, J. SVCCA: Singular vector canonical correlation analysis for deep learning dynamics and interpretability. In Advances in Neural Information Processing Systems, 2017.

Ramsay, J., ten Berge, J., and Styan, G. Matrix correlation. Psychometrika, 49(3):403–423, 1984.

Robert, P. and Escoufier, Y. A unifying tool for linear multivariate statistical methods: the RV-coefficient. Applied Statistics, 25(3):257–265, 1976.

Romero, A., Ballas, N., Kahou, S. E., Chassang, A., Gatta, C., and Bengio, Y. FitNets: Hints for thin deep nets. In International Conference on Learning Representations, 2015.

SAS Institute. Introduction to Regression Procedures. 2015. URL https://support.sas.com/documentation/onlinedoc/stat/141/introreg.pdf.

Saxe, A. M., McClelland, J. L., and Ganguli, S. Exact solutions to the nonlinear dynamics of learning in deep linear neural networks. In International Conference on Learning Representations, 2014.

Sejdinovic, D., Sriperumbudur, B., Gretton, A., and Fukumizu, K. Equivalence of distance-based and RKHS-based statistics in hypothesis testing. The Annals of Statistics, pp. 2263–2291, 2013.

Smith, S. L., Turban, D. H., Hamblin, S., and Hammerla, N. Y. Offline bilingual word vectors, orthogonal transformations and the inverted softmax. In International Conference on Learning Representations, 2017.

Song, L., Smola, A., Gretton, A., Borgwardt, K. M., and Bedo, J. Supervised feature selection via dependence estimation. In International Conference on Machine Learning, 2007.

Springenberg, J. T., Dosovitskiy, A., Brox, T., and Riedmiller, M. Striving for simplicity: The all convolutional net. In International Conference on Learning Representations Workshop, 2015.

StataCorp. Stata Multivariate Statistics Reference Manual. 2015. URL https://www.stata.com/manuals14/mv.pdf.

Sussillo, D., Churchland, M. M., Kaufman, M. T., and Shenoy, K. V. A neural network that finds a naturalistic solution for the production of muscle activity. Nature Neuroscience, 18(7):1025, 2015.

Tucker, L. R. A method for synthesis of factor analysis studies. Technical report, Educational Testing Service, Princeton, NJ, 1951.

Vaswani, A., Shazeer, N., Parmar, N., Uszkoreit, J., Jones, L., Gomez, A. N., Kaiser, Ł., and Polosukhin, I. Attention is all you need. In Advances in Neural Information Processing Systems, pp. 5998–6008, 2017.

Vinod, H. D. Canonical ridge and econometrics of joint production. Journal of Econometrics, 4(2):147–166, 1976.

Wang, L., Hu, L., Gu, J., Wu, Y., Hu, Z., He, K., and Hopcroft, J. E. Towards understanding learning representations: To what extent do different neural networks learn the same representation. In Advances in Neural Information Processing Systems, 2018.

Yamins, D. L., Hong, H., Cadieu, C. F., Solomon, E. A., Seibert, D., and DiCarlo, J. J. Performance-optimized hierarchical models predict neural responses in higher visual cortex. Proceedings of the National Academy of Sciences, 111(23):8619–8624, 2014.

Zagoruyko, S. and Komodakis, N. Wide residual networks. In British Machine Vision Conference, 2016.