메뉴
HN
Hacker News 51일 전

학습 데이터의 순서 의존성과 리 브래킷(Lie Bracket)

IMP
7/10
핵심 요약

이 글은 신경망 학습 과정에서 학습 데이터(Training Example)를 벡터 장(Vector Field)으로 간주하고, 두 데이터의 학습 순서를 바꿨을 때 파라미터에 미치는 영향을 수학적으로 계산하는 방법을 설명합니다. 미분 기하학의 '리 브래킷(Lie Bracket)' 개념을 적용해 데이터의 순서 의존성을 정량화하며, 이를 실제 합성곱 신경망(ConvNet) 학습에 적용한 실험 결과를 보여줍니다.

번역된 본문

훈련 예제는 벡터 장(Vector Field)이며 그 리 브래킷(Lie Bracket)은 계산될 수 있습니다. (결과 바로가기)

이상적인 머신러닝 모델이라면 학습 과정에서 훈련 예제가 제공되는 순서에 영향을 받지 않을 것입니다. 베이지안 관점에서 훈련 데이터셋은 순서가 없는 데이터이며, 하나의 추가적인 예제를 보는 것에 기반한 모든 업데이트는 서로 교환 법칙이 성립(commute)해야 합니다. 그러나 경사 하강법(gradient descent)으로 훈련된 신경망의 경우에는 그렇지 않습니다. 이 글은 두 훈련 예제의 순서를 바꾸는 것이 파라미터별로 미치는 영향을 계산하는 방법을 설명하고, 간단한 ConvNet 모델에 대해 이 계산 결과를 보여줄 것입니다.

시작하기 위해, 우리는 하나의 간단한 수학적 사실을 인식하기만 하면 됩니다.

훈련 예제는 벡터 장입니다 만약 우리가 파라미터 $\theta \in \Theta = \mathbb{R}^\text{num params}$를 가진 신경망을 훈련시키고 있다면, 각 훈련 예제를 벡터 장으로 취급할 수 있습니다. 구체적으로, $x$가 훈련 예제이고 $\mathcal{L}^{(x)}$가 해당 훈련 예제 $x$에 대한 개별 손실(per-example loss)이라면, 이 벡터 장은 다음과 같습니다: $$ v^{(x)}(\theta) = -\nabla_{\theta} \mathcal{L}^{(x)} $$ 즉, 특정 훈련 예제에 대해 결과 벡터 장의 화살표는 파라미터가 업데이트되어야 할 방향을 가리킵니다. 이러한 관점에서, 경사 하강 업데이트는 기본적으로 학습률 $\epsilon$만큼 벡터 장의 방향으로 이동하는 것처럼 보입니다. $$ \theta' = \theta + \epsilon v^{(x)}(\theta). $$

훈련 예제 리 브래킷 (The Training Example Lie Bracket) 벡터 장으로 할 수 있는 일 중 하나는 리 브래킷을 계산하는 것입니다. 따라서 $x, y$가 훈련 예제라면, 다음을 계산할 수 있습니다: $$ [v^{(x)}, v^{(y)}] = (v^{(x)}\cdot \nabla_\theta) v^{(y)} - (v^{(y)}\cdot \nabla_\theta) v^{(x)} $$ $\Theta$ 상의 임의의 두 벡터 장에 대해 리 브래킷을 계산할 수 있으므로, 당연히 두 훈련 예제에서 발생하는 벡터 장의 리 브래킷도 계산할 수 있습니다. 두 훈련 예제의 리 브래킷은 해당 예제들에 대한 학습의 순서 의존성(order dependence)을 알려줍니다. 벡터 장의 리 브래킷은 그 자체로 벡터 장이므로, 경사도(gradient)와 마찬가지로 파라미터 텐서와 동일한 형태(shape)를 가진 리 브래킷 텐서를 얻게 됩니다.

리 브래킷은 순서 의존성을 알려줍니다 이 값을 $y$ 이전에 $x$로 업데이트하는 것과 이후에 업데이트하는 것의 차이로 해석할 수 있습니다. 이를 확인하기 위해 테일러 전개(Taylor expand)를 해보겠습니다. $\epsilon$이 학습률이라면, $O(\epsilon^2)$까지 전개할 것입니다: $$\theta' = \theta + \epsilon v^{(x)}(\theta)$$ $$ \theta'' = \theta' + \epsilon v^{(y)}(\theta') $$ $$= \theta + \epsilon v^{(x)}(\theta) + \epsilon v^{(y)}(\theta) + \epsilon^2 (v^{(x)}(\theta) \cdot \nabla_\theta) v^{(y)}(\theta)$$ 이제 $x,y$를 반대 순서로 업데이트하면, 결과 파라미터 $\theta''$에 $O(\epsilon^2)$의 차이가 발생합니다. 구체적으로 다음과 같습니다: $$ \Delta \theta'' = \epsilon^2 \left( (v^{(x)}(\theta) \cdot \nabla_\theta) v^{(y)}(\theta) - (v^{(y)}(\theta) \cdot \nabla_\theta) v^{(x)}(\theta) \right) $$ $$ \Delta \theta'' = \epsilon^2 [v^{(x)}, v^{(y)}] (\theta) $$ 따라서 여기서 우리는 리 브래킷의 중요성을 알 수 있습니다. 이는 훈련 예제를 어떤 순서로 보여주느냐에 따라 파라미터가 최종적으로 도달하는 지점의 차이를 알려줍니다. 리 브래킷의 선형성에 의해, 두 미니배치의 순서를 바꾸는 것은 모든 예제 쌍에 대해 평균을 내어 구한 효과를 가진다는 점에 유의하십시오.

기존 연구 (Prior Work) 문헌에서 훈련 예제의 리 브래킷에 대한 연구를 찾아보았을 때, 우리가 발견한 가장 초기의 설명은 Dherin(2023)으로, 그는 업데이트의 교환성(commutativity)을 측정하는 브래킷의 능력을 신경망 학습의 암묵적 편향(implicit biases)과 연결했습니다. 우리는 실제 ConvNet의 학습 과정 중 다양한 체크포인트에서 브래킷 값을 명시적으로 계산함으로써 이 연구를 더 발전시킵니다.

실험 세부 정보 (Experiment Details) 우리는 MXResNet 아키텍처(어텐션 레이어 제외)를 복제하고, CelebA 데이터셋에서 배치 크기 32로 5000스텝 동안 훈련하며, 때때로 가중치 체크포인트를 저장했습니다. 옵티마이저는 Adam이며, 파라미터는 다음과 같습니다: lr = 5e-3, betas = (0.8, 0.999)

원문 보기
원문 보기 (영어)
Training Examples are Vector Fields and their Lie Brackets can be Computed skip to results An ideal machine learning model would not care what order training examples appeared in its training process. From a Bayesian perspective, the training dataset is unordered data and all updates based on seeing one additional example should commute with each other. For neural nets trained by gradient descent, however, this is not the case. This webpage will explain how to compute the effects of swapping the order of two training examples on a per-parameter level, and show the results of computing these quantities for a simple convnet model. To get started, we just need to recognize one simple mathematical fact: Training Examples are Vector Fields If we are training a neural network with parameters $\theta \in \Theta = \mathbb{R}^\text{num params}$, then we can treat each training example as a vector field. In particular, if $x$ is a training example and $\mathcal{L}^{(x)}$ is the per-example loss for the training example $x$, then this vector field is: $$ v^{(x)}(\theta) = -\nabla_{\theta} \mathcal{L}^{(x)} $$ In other words, for a specific training example, the arrows of the resulting vector field point in the direction that the parameters should be updated. In this view, a gradient update basically looks like moving in the direction of the vector field by the learning rate $\epsilon$. $$ \theta' = \theta + \epsilon v^{(x)}(\theta). $$ The Training Example Lie Bracket One thing we can do with vector fields is to compute their Lie bracket. So if $x, y$ are training examples, we may compute: $$ [v^{(x)}, v^{(y)}] = (v^{(x)}\cdot \nabla_\theta) v^{(y)} - (v^{(y)}\cdot \nabla_\theta) v^{(x)} $$ We can compute the Lie bracket of any two vector fields on $\Theta$, and so we can certainly compute the Lie bracket of the vector fields arising from two training examples. The Lie bracket of two training examples tells us about the order dependence of training on those examples. The Lie bracket of a vector field is itself a vector field, and so just like a gradient, we get a Lie bracket tensor for each parameter tensor of the same shape as that parameter tensor. The Lie Bracket Tells us About Order-Dependence We can interpret this quantity as the difference between updating on $x$ before $y$ vs after. Let's Taylor expand to see this. If $\epsilon$ is the learning rate, we'll want to expand to $O(\epsilon^2)$: $$\theta' = \theta + \epsilon v^{(x)}(\theta)$$ $$ \theta'' = \theta' + \epsilon v^{(y)}(\theta') $$ $$= \theta + \epsilon v^{(x)}(\theta) + \epsilon v^{(y)}(\theta) + \epsilon^2 (v^{(x)}(\theta) \cdot \nabla_\theta) v^{(y)}(\theta)$$ Now if we update $x,y$ in the other order, we get an $O(\epsilon^2)$ difference in the resulting parameters $\theta''$. Namely: $$ \Delta \theta'' = \epsilon^2 \left( (v^{(x)}(\theta) \cdot \nabla_\theta) v^{(y)}(\theta) - (v^{(y)}(\theta) \cdot \nabla_\theta) v^{(x)}(\theta) \right) $$ $$ \Delta \theta'' = \epsilon^2 [v^{(x)}, v^{(y)}] (\theta) $$ So here we can see the significance of the Lie bracket: It tells us the difference in where our parameters end up based on which order we show the training examples in. Note that by the linearity of the Lie bracket, swapping the order of two minibatches has an effect given by averaging over all pairs of examples. Prior Work When searching the literature for work on the Lie brackets of training examples, the earliest description we found was Dherin in 2023, who connects the bracket's ability to measure commutativity of updates to implicit biases in neural net training. We go farther here by explicitly computing the bracket value at various checkpoints in the training of an actual convnet. Experiment Details We replicate the MXResNet architecture (without attention layers) and train it on the CelebA dataset for 5000 steps at a batch size of 32, saving weight checkpoints from time to time. The optimizer is Adam, with the following parameters: lr = 5e-3 betas = (0.8, 0.999) The CelebA dataset has 40 binary attributes (such as Male or Black_Hair ) and the neural net is tasked with predicting each of these independently and simultaneously (averaged binary classification loss). We evaluated each checkpoint of the model on a batch of 32 examples from the test set. We computed Lie brackets between only the first 6 of these test examples to limit disk space usage, as each individual Lie bracket has the same size as a full checkpoint of the model. For each of these brackets representing a swap of two examples, we show how all 40 logits for all 32 test examples in the batch are perturbed when the two examples are swapped. Results We have some things to say about the results, but first try exploring them yourself! The slider controls which checkpoint from the training process we're examining, and you can click on the buttons to see data about particular Lie brackets. $[u_i, u_j] = -[u_j, u_i]$ so brackets across the diagonal from each other are just negatives of each other. Loss History Training Step Slider: Select a checkpoint. Lie Brackets of Example Pairs Click any off-diagonal pair to inspect bracket $[u_i, u_j]$ details for examples $i$ vs $j$. Note that it varies by which checkpoint you've selected. Heatmaps show how much logits for a specific input and feature change when the two selected examples are swapped. Patterns Lie Bracket Magnitudes are Proportional to Gradient Magnitudes If we look at the tensors that the Lie bracket provides for each parameter, the RMS magnitudes of these tensors vary widely over many orders of magnitude (just like the gradients for these tensors do). But, if we plot RMS magnitudes against RMS gradients for each parameter tensor on a log-log scale, we find that there is a remarkably tight correlation between the two. Indeed, it appears that for each bracket, it's possible to fit a simple 1-parameter line that pins down a constant of proportionality between bracket magnitudes and gradient magnitudes. This is interesting, because it suggests that the magnitude of a given Lie bracket is mostly determined by: 1. The $v^{(x)}$ part of $(v^{(x)}\cdot \nabla_\theta) v^{(y)}$ (and similarly for the other term). 2. Factors that are independent of which parameter tensor we're looking at such as how far along in the training we are and how "intrinsically non-commutative" the training examples we're taking the bracket of are. In other words, it suggests that for a given bracket, the $\nabla_\theta v^{(y)}$ part of $(v^{(x)}\cdot \nabla_\theta) v^{(y)}$ has a relatively constant magnitude across all the parameters of the net (and similarly for the other term). Non-Commutativity's Effect on Predictions may be able to Flag Modelling Issues You may have noticed that past checkpoint 600 or so, the Black_Hair and Brown_Hair logits tended to have large deltas under most of the Lie brackets in the matrix. This means that predictions for these two features varied a lot based on example ordering. We have a hypothesis for why this may be the case: Consider that in the dataset, black hair and brown hair are not simultaneously present. The other 3 combinations of these features are present, but a value of "True" for both at once should not occur. However, the model outputs separate predictions for each feature, and the resulting distribution can only be a product of the individual predictions. In other words, the loss function implicitly assumes that the model's predictions must be independent of each other. If the model is unsure whether a person's photo has black or brown hair, (which can be quite a common case, depending on lighting), then it would predict a 50% chance for each feature. The loss function interprets this as a 25% chance of any of the 4 combinations, but what the model would probably like to predict is a 50:50 split between (False, True) and (True, False). Our hypothesis is that this inadequacy in the loss function is what is driving the logit deltas for these features to tend