第4章分類のための線形ニューラルネットワーク
4.7.3. Correction of Distribution Shift4.7.3 分布シフトの補正
As we have discussed, there are many cases where training and test distributions are different. In some cases, we get lucky and the models work despite covariate, label, or concept shift. In other cases, we can do better by employing principled strategies to cope with the shift. The remainder of this section grows considerably more technical. The impatient reader could continue on to the next section as this material is not prerequisite to subsequent concepts.
英語のヒント
これまで論じてきたように、訓練とテストの分布が異なる場合はたくさんある。運がよく、共変量シフト、ラベルシフト、概念シフトがあってもモデルが働く場合もある。別の場合には、シフトに対処する筋の通った戦略を使うことで、もっとうまくやれる。この節の残りは、かなり技術的になる。この内容は以降の概念の前提ではないので、先を急ぐ読者は次の節に進んでもよい。
4.7.3.1. Empirical Risk and Risk4.7.3.1 経験リスクとリスク
Let’s first reflect on what exactly is happening during model training: we iterate over features and associated labels of training data and update the parameters of a model after every minibatch. For simplicity we do not consider regularization, so we largely minimize the loss on the training:
英語のヒント
まず、モデルの訓練中に正確には何が起きているかを振り返ろう。訓練データの特徴量と対応するラベルを順に処理し、ミニバッチごとにモデルのパラメータを更新している。簡単のために正則化は考えないので、おおむね訓練での損失を最小にしていることになる。
(4.7.1)
where is the loss function measuring “how bad” the prediction is given the associated label . Statisticians call the term in (4.7.1) empirical risk. The empirical risk is an average loss over the training data for approximating the risk, which is the expectation of the loss over the entire population of data drawn from their true distribution :
英語のヒント
ここでは、対応するラベルが与えられたときに予測が「どれほど悪いか」を測る損失関数である。統計学者は式(4.7.1)の項を経験リスクと呼ぶ。経験リスクは、リスクを近似するための訓練データ全体での平均の損失である。リスクとは、真の分布から取り出されたデータの母集団全体にわたる損失の期待値である。
(4.7.2)
However, in practice we typically cannot obtain the entire population of data. Thus, empirical risk minimization, which is minimizing the empirical risk in (4.7.1), is a practical strategy for machine learning, with the hope of approximately minimizing the risk.
英語のヒント
しかし実際には、データの母集団全体はふつう手に入らない。そのため、経験リスク最小化、つまり式(4.7.1)の経験リスクを最小にすることは、リスクをおおよそ最小にできるという期待のもとでの、機械学習の実用的な戦略である。
4.7.3.2. Covariate Shift Correction4.7.3.2 共変量シフトの補正
Assume that we want to estimate some dependency for which we have labeled data . Unfortunately, the observations are drawn from some source distribution rather than the target distribution . Fortunately, the dependency assumption means that the conditional distribution does not change: . If the source distribution is “wrong”, we can correct for that by using the following simple identity in the risk:
英語のヒント
ラベル付きのデータがある、何らかの依存関係を推定したいとしよう。残念ながら、観測はターゲット分布ではなく、あるソース分布から取り出されている。幸い、依存関係についての仮定から、条件付き分布は変わらない。つまりである。ソース分布が「間違っている」なら、リスクについての次の単純な恒等式を使って、それを補正できる。
(4.7.3)
In other words, we need to reweigh each data example by the ratio of the probability that it would have been drawn from the correct distribution to that from the wrong one:
英語のヒント
言い換えれば、各データ事例に、それが正しい分布から取り出された確率と、間違った分布から取り出された確率との比で、重みを付け直す必要がある。
(4.7.4)
Plugging in the weight for each data example we can train our model using weighted empirical risk minimization:
英語のヒント
各データ事例に重みを代入すれば、重み付きの経験リスク最小化を使ってモデルを訓練できる。
(4.7.5)
Alas, we do not know that ratio, so before we can do anything useful we need to estimate it. Many methods are available, including some fancy operator-theoretic approaches that attempt to recalibrate the expectation operator directly using a minimum-norm or a maximum entropy principle. Note that for any such approach, we need samples drawn from both distributions—the “true” , e.g., by access to test data, and the one used for generating the training set (the latter is trivially available). Note however, that we only need features ; we do not need to access labels .
英語のヒント
あいにく、その比はわからないので、何か役に立つことをする前に、それを推定する必要がある。使える方法はたくさんあり、なかには、最小ノルムや最大エントロピーの原理を使って期待値の演算子を直接較正し直そうとする、凝った作用素論的な手法もある。どの手法でも、両方の分布から取り出した標本が必要になることに注意してほしい。たとえばテストデータに手が届くことで得られる「真の」と、訓練集合を生成するのに使われたである(後者は当然手に入る)。ただし、必要なのは特徴量だけで、ラベルに手が届く必要はないことに注意してほしい。
In this case, there exists a very effective approach that will give almost as good results as the original: namely, logistic regression, which is a special case of softmax regression (see Section 4.1) for binary classification. This is all that is needed to compute estimated probability ratios. We learn a classifier to distinguish between data drawn from and data drawn from . If it is impossible to distinguish between the two distributions then it means that the associated instances are equally likely to come from either one of those two distributions. On the other hand, any instances that can be well discriminated should be significantly overweighted or underweighted accordingly.
英語のヒント
この場合、元のものとほぼ同じくらいよい結果を与える、とても効果的な手法がある。すなわち、ロジスティック回帰である。これは、二値分類のためのソフトマックス回帰の特別な場合である(4.1節を参照)。推定された確率の比を計算するのに必要なのは、これだけである。から取り出されたデータとから取り出されたデータを見分ける分類器を学習する。二つの分布を見分けられないなら、それは、対応するインスタンスが二つの分布のどちらから来た可能性も等しいということである。一方、うまく識別できるインスタンスには、それに応じて重みを大きく増やすか減らすかすべきである。
For simplicity’s sake assume that we have an equal number of instances from both distributions and , respectively. Now denote by labels that are for data drawn from and for data drawn from . Then the probability in a mixed dataset is given by
英語のヒント
簡単のため、二つの分布とから、それぞれ同じ数のインスタンスがあると仮定しよう。ここで、から取り出されたデータには、から取り出されたデータにはとなるラベルをで表す。すると、混ぜたデータセットでの確率は次で与えられる。
(4.7.6)
Thus, if we use a logistic regression approach, where ( is a parametrized function), it follows that
英語のヒント
したがって、ロジスティック回帰の手法を使い、(はパラメータ化された関数)とすると、次が導かれる。
(4.7.7)
As a result, we need to solve two problems: the first, to distinguish between data drawn from both distributions, and then a weighted empirical risk minimization problem in (4.7.5) where we weigh terms by .
英語のヒント
その結果、二つの問題を解く必要がある。一つ目は、二つの分布から取り出されたデータを見分ける問題であり、次は、項にで重みを付ける、式(4.7.5)の重み付き経験リスク最小化の問題である。
Now we are ready to describe a correction algorithm. Suppose that we have a training set and an unlabeled test set . For covariate shift, we assume that for all are drawn from some source distribution and for all are drawn from the target distribution. Here is a prototypical algorithm for correcting covariate shift:
英語のヒント
これで、補正のアルゴリズムを説明する準備が整った。訓練集合と、ラベルのないテスト集合があるとしよう。共変量シフトについては、すべてのについてはあるソース分布から取り出され、すべてのについてはターゲット分布から取り出されると仮定する。共変量シフトを補正する典型的なアルゴリズムは次のとおりである。
- Create a binary-classification training set: .
英語のヒント
二値分類の訓練集合を作る。 - Train a binary classifier using logistic regression to get the function .
英語のヒント
ロジスティック回帰を使って二値分類器を訓練し、関数を得る。 - Weigh training data using or better for some constant .
英語のヒント
、あるいはもっとよいのは、ある定数についてのを使って、訓練データに重みを付ける。
Note that the above algorithm relies on a crucial assumption. For this scheme to work, we need that each data example in the target (e.g., test time) distribution had nonzero probability of occurring at training time. If we find a point where but , then the corresponding importance weight should be infinity.
英語のヒント
上のアルゴリズムは、決定的に重要な仮定に頼っていることに注意してほしい。このやり方がうまくいくには、ターゲット(たとえばテスト時)の分布の各データ事例が、訓練時に0でない確率で起こりえたことが必要である。なのにとなる点が見つかれば、対応する重要度重みは無限大になるはずである。
4.7.3.3. Label Shift Correction4.7.3.3 ラベルシフトの補正
Assume that we are dealing with a classification task with categories. Using the same notation in Section 4.7.3.2, and are the source distribution (e.g., training time) and target distribution (e.g., test time), respectively. Assume that the distribution of labels shifts over time: , but the class-conditional distribution stays the same: . If the source distribution is “wrong”, we can correct for that according to the following identity in the risk as defined in (4.7.2):
英語のヒント
(4.7.8)
Here, our importance weights will correspond to the label likelihood ratios:
英語のヒント
ここでは、重要度重みはラベルの尤度比に対応する。
(4.7.9)
One nice thing about label shift is that if we have a reasonably good model on the source distribution, then we can get consistent estimates of these weights without ever having to deal with the ambient dimension. In deep learning, the inputs tend to be high-dimensional objects like images, while the labels are often simpler objects like categories.
英語のヒント
ラベルシフトのよいところの一つは、ソース分布でそれなりによいモデルがあれば、入力の空間の次元を一切扱わずに、これらの重みの一致推定値が得られることである。深層学習では、入力は画像のような高次元の対象になりがちだが、ラベルはカテゴリーのような、もっと単純な対象であることが多い。
To estimate the target label distribution, we first take our reasonably good off-the-shelf classifier (typically trained on the training data) and compute its “confusion” matrix using the validation set (also from the training distribution). The confusion matrix, , is simply a matrix, where each column corresponds to the label category (ground truth) and each row corresponds to our model’s predicted category. Each cell’s value is the fraction of total predictions on the validation set where the true label was and our model predicted .
英語のヒント
ターゲットのラベル分布を推定するには、まず、それなりによい既製の分類器(ふつうは訓練データで訓練したもの)を用意し、検証集合(これも訓練分布から来る)を使ってその「混同」行列を計算する。混同行列は単にの行列で、各列はラベルのカテゴリー(正解)に、各行はモデルが予測したカテゴリーに対応する。各セルの値は、検証集合での予測全体のうち、真のラベルがで、モデルがと予測したものの割合である。
Now, we cannot calculate the confusion matrix on the target data directly because we do not get to see the labels for the examples that we see in the wild, unless we invest in a complex real-time annotation pipeline. What we can do, however, is average all of our model’s predictions at test time together, yielding the mean model outputs , where the element is the fraction of the total predictions on the test set where our model predicted .
英語のヒント
さて、ターゲットのデータでの混同行列を直接計算することはできない。複雑なリアルタイムの注釈付けの仕組みに投資しないかぎり、現実の場で目にする事例のラベルを見ることはできないからである。しかし、できることはある。テスト時のモデルの予測をすべて平均し、モデルの出力の平均を得ることである。その要素は、テスト集合での予測全体のうち、モデルがと予測したものの割合である。
It turns out that under some mild conditions—if our classifier was reasonably accurate in the first place, and if the target data contains only categories that we have seen before, and if the label shift assumption holds in the first place (the strongest assumption here)—we can estimate the test set label distribution by solving a simple linear system
英語のヒント
実は、いくつかの穏やかな条件のもとで、つまり、そもそも分類器がそれなりに正確であり、ターゲットのデータには以前に見たことのあるカテゴリーしか含まれず、そもそもラベルシフトの仮定が成り立つ(ここでの最も強い仮定)ならば、単純な連立一次方程式を解くことで、テスト集合のラベル分布を推定できる。
(4.7.10)
because as an estimate holds for all , where is the element of the -dimensional label distribution vector . If our classifier is sufficiently accurate to begin with, then the confusion matrix will be invertible, and we get a solution .
英語のヒント
なぜなら、推定値として、すべてのについてが成り立つからである。ここでは、次元のラベル分布ベクトルの要素である。分類器がそもそも十分に正確なら、混同行列は逆行列をもち、解が得られる。
Because we observe the labels on the source data, it is easy to estimate the distribution . Then, for any training example with label , we can take the ratio of our estimated to calculate the weight , and plug this into weighted empirical risk minimization in (4.7.5).
英語のヒント
ソースのデータではラベルが観測できるので、分布を推定するのは簡単である。そうすれば、ラベルをもつどの訓練事例についても、推定したの比をとって重みを計算し、これを式(4.7.5)の重み付き経験リスク最小化に代入できる。
4.7.3.4. Concept Shift Correction4.7.3.4 概念シフトの補正
Concept shift is much harder to fix in a principled manner. For instance, in a situation where suddenly the problem changes from distinguishing cats from dogs to one of distinguishing white from black animals, it will be unreasonable to assume that we can do much better than just collecting new labels and training from scratch. Fortunately, in practice, such extreme shifts are rare. Instead, what usually happens is that the task keeps on changing slowly. To make things more concrete, here are some examples:
英語のヒント
概念シフトを筋の通ったやり方で直すのは、はるかに難しい。たとえば、問題が突然、猫と犬を見分ける問題から、白い動物と黒い動物を見分ける問題に変わる状況では、新しいラベルを集めてゼロから訓練し直すよりずっとうまくやれると仮定するのは無理があるだろう。幸い、実際にはそのような極端なシフトはまれである。むしろふつう起きるのは、課題がゆっくりと変わり続けることである。もっと具体的にするため、いくつか例を挙げる。
- In computational advertising, new products are launched, old products become less popular. This means that the distribution over ads and their popularity changes gradually and any click-through rate predictor needs to change gradually with it.
英語のヒント
計算広告では、新しい商品が発売され、古い商品は人気が落ちていく。つまり、広告とその人気にわたる分布は徐々に変わり、クリック率を予測するものはどれも、それに合わせて徐々に変わる必要がある。 - Traffic camera lenses degrade gradually due to environmental wear, affecting image quality progressively.
英語のヒント
交通カメラのレンズは環境による摩耗で徐々に劣化し、画質がだんだん損なわれていく。 - News content changes gradually (i.e., most of the news remains unchanged but new stories appear).
英語のヒント
ニュースの内容は徐々に変わる(つまり、ニュースのほとんどは変わらないが、新しい話題が現れる)。
In such cases, we can use the same approach that we used for training networks to make them adapt to the change in the data. In other words, we use the existing network weights and simply perform a few update steps with the new data rather than training from scratch.
英語のヒント
こうした場合には、ネットワークを訓練するのに使ったのと同じ手法を使って、ネットワークをデータの変化に適応させられる。言い換えれば、ゼロから訓練するのではなく、既存のネットワークの重みを使い、新しいデータで更新の段階をいくつか行うだけである。