第9章リカレントニューラルネットワーク
9.3.2. Perplexity9.3.2 パープレキシティ
Next, let’s discuss about how to measure the quality of the language model, which we will then use to evaluate our models in the subsequent sections. One way is to check how surprising the text is. A good language model is able to predict, with high accuracy, the tokens that come next. Consider the following continuations of the phrase “It is raining”, as proposed by different language models:
英語のヒント
次に、言語モデルの質をどう測るかを論じよう。これは、以降の節でモデルを評価するのに使う。一つの方法は、テキストがどれくらい意外かを確かめることである。よい言語モデルは、次に来るトークンを高い正確さで予測できる。さまざまな言語モデルが提案する、「It is raining」(雨が降っている)という句の次のような続きを考えよう。
- “It is raining outside”
英語のヒント
「It is raining outside」(外は雨が降っている) - “It is raining banana tree”
英語のヒント
「It is raining banana tree」(雨が降っているバナナの木) - “It is raining piouw;kcj pwepoiut”
英語のヒント
「It is raining piouw;kcj pwepoiut」(雨が降っている piouw;kcj pwepoiut)
In terms of quality, Example 1 is clearly the best. The words are sensible and logically coherent. While it might not quite accurately reflect which word follows semantically (“in San Francisco” and “in winter” would have been perfectly reasonable extensions), the model is able to capture which kind of word follows. Example 2 is considerably worse by producing a nonsensical extension. Nonetheless, at least the model has learned how to spell words and some degree of correlation between words. Last, Example 3 indicates a poorly trained model that does not fit data properly.
英語のヒント
質の点では、例1が明らかに最もよい。単語は筋が通っており、論理的に一貫している。意味的にどの単語が続くかを正確には反映していないかもしれない(「in San Francisco(サンフランシスコでは)」や「in winter(冬には)」もまったく妥当な続きだっただろう)が、このモデルはどんな種類の単語が続くかをとらえられている。例2は、無意味な続きを生み出しており、かなり悪い。それでも、少なくともこのモデルは、単語の綴り方と、単語のあいだのある程度の相関を学習している。最後に、例3は、データにうまく当てはまっていない、訓練の不十分なモデルを示している。
We might measure the quality of the model by computing the likelihood of the sequence. Unfortunately this is a number that is hard to understand and difficult to compare. After all, shorter sequences are much more likely to occur than the longer ones, hence evaluating the model on Tolstoy’s magnum opus War and Peace will inevitably produce a much smaller likelihood than, say, on Saint-Exupery’s novella The Little Prince. What is missing is the equivalent of an average.
英語のヒント
系列の尤度を計算して、モデルの質を測ることもできる。残念ながら、これは理解しにくく、比べにくい数である。結局のところ、短い系列は長い系列よりずっと現れやすいので、トルストイの大作『戦争と平和』でモデルを評価すれば、たとえばサン=テグジュペリの中編『星の王子さま』で評価するよりも、必然的にずっと小さな尤度が出る。欠けているのは、平均にあたるものである。
Information theory comes handy here. We defined entropy, surprisal, and cross-entropy when we introduced the softmax regression (Section 4.1.3). If we want to compress text, we can ask about predicting the next token given the current set of tokens. A better language model should allow us to predict the next token more accurately. Thus, it should allow us to spend fewer bits in compressing the sequence. So we can measure it by the cross-entropy loss averaged over all the tokens of a sequence:
英語のヒント
ここで情報理論が役に立つ。ソフトマックス回帰を紹介したとき(4.1.3節)に、エントロピー、驚き、交差エントロピーを定義した。テキストを圧縮したいなら、現在のトークンの集合が与えられたときに次のトークンを予測することを考えればよい。よりよい言語モデルなら、次のトークンをより正確に予測できるはずである。したがって、系列を圧縮するのに使うビットはより少なくて済むはずである。そこで、系列のすべての個のトークンにわたって平均した交差エントロピー損失で、それを測れる。
(9.3.7)
where is given by a language model and is the actual token observed at time step from the sequence. This makes the performance on documents of different lengths comparable. For historical reasons, scientists in natural language processing prefer to use a quantity called perplexity. In a nutshell, it is the exponential of (9.3.7):
英語のヒント
ここで、は言語モデルが与え、は系列から時間ステップで観測された実際のトークンである。これにより、長さの異なる文書での性能を比べられるようになる。歴史的な理由から、自然言語処理の科学者はパープレキシティと呼ばれる量を使うのを好む。手短に言えば、それは(9.3.7)の指数関数である。
(9.3.8)
Perplexity can be best understood as the reciprocal of the geometric mean of the number of real choices that we have when deciding which token to pick next. Let’s look at a number of cases:
英語のヒント
パープレキシティは、次にどのトークンを選ぶかを決めるときに実際にある選択肢の数の、幾何平均の逆数として理解するのが一番よい。いくつかの場合を見てみよう。
- In the best case scenario, the model always perfectly estimates the probability of the target token as 1. In this case the perplexity of the model is 1.
英語のヒント
最善の場合には、モデルは目標のトークンの確率をいつも完璧に1と推定する。この場合、モデルのパープレキシティは1である。 - In the worst case scenario, the model always predicts the probability of the target token as 0. In this situation, the perplexity is positive infinity.
英語のヒント
最悪の場合には、モデルは目標のトークンの確率をいつも0と予測する。この状況では、パープレキシティは正の無限大である。 - At the baseline, the model predicts a uniform distribution over all the available tokens of the vocabulary. In this case, the perplexity equals the number of unique tokens of the vocabulary. In fact, if we were to store the sequence without any compression, this would be the best we could do for encoding it. Hence, this provides a nontrivial upper bound that any useful model must beat.
英語のヒント
基準となる場合には、モデルは語彙のすべての使えるトークンにわたる一様分布を予測する。この場合、パープレキシティは語彙の一意なトークンの数に等しい。実際、系列をまったく圧縮せずに保存するとしたら、これが符号化するうえでできる最善である。したがって、これはどんな有用なモデルも上回らなければならない、自明でない上界を与える。