第9章リカレントニューラルネットワーク
9.1.2. Sequence Models9.1.2 系列モデル
Sometimes, especially when working with language, we wish to estimate the joint probability of an entire sequence. This is a common task when working with sequences composed of discrete tokens, such as words. Generally, these estimated functions are called sequence models and for natural language data, they are called language models. The field of sequence modeling has been driven so much by natural language processing, that we often describe sequence models as “language models”, even when dealing with non-language data. Language models prove useful for all sorts of reasons. Sometimes we want to evaluate the likelihood of sentences. For example, we might wish to compare the naturalness of two candidate outputs generated by a machine translation system or by a speech recognition system. But language modeling gives us not only the capacity to evaluate likelihood, but the ability to sample sequences, and even to optimize for the most likely sequences.
英語のヒント
ときには、特に言語を扱うとき、系列全体の同時確率を推定したいことがある。これは、単語のような離散的なトークンからなる系列を扱うときによくある課題である。一般に、こうして推定される関数は系列モデルと呼ばれ、自然言語のデータについては言語モデルと呼ばれる。系列のモデリングの分野は自然言語処理にあまりにも強く推し進められてきたので、言語以外のデータを扱うときでさえ、系列モデルをしばしば「言語モデル」と呼ぶ。言語モデルは、あらゆる理由で役に立つ。文のもっともらしさを評価したいことがある。たとえば、機械翻訳のシステムや音声認識のシステムが生成した二つの候補の出力の自然さを比べたいことがある。しかし、言語のモデリングがもたらすのは、もっともらしさを評価する能力だけでなく、系列をサンプリングする能力、さらには最もありそうな系列を求めて最適化する能力でもある。
While language modeling might not, at first glance, look like an autoregressive problem, we can reduce language modeling to autoregressive prediction by decomposing the joint density of a sequence into the product of conditional densities in a left-to-right fashion by applying the chain rule of probability:
英語のヒント
言語のモデリングは一見すると自己回帰の問題には見えないかもしれないが、確率の連鎖律を当てはめて、系列の同時密度を左から右へと条件付き密度の積に分解すれば、言語のモデリングを自己回帰の予測に帰着できる。
(9.1.3)
Note that if we are working with discrete signals such as words, then the autoregressive model must be a probabilistic classifier, outputting a full probability distribution over the vocabulary for whatever word will come next, given the leftwards context.
英語のヒント
単語のような離散的な信号を扱う場合、自己回帰モデルは確率的な分類器でなければならず、左側の文脈が与えられたとき、次に来る単語が何であれ、語彙全体にわたる完全な確率分布を出力することに注意してほしい。
9.1.2.1. Markov Models9.1.2.1 マルコフモデル
Now suppose that we wish to employ the strategy mentioned above, where we condition only on the previous time steps, i.e., , rather than the entire sequence history . Whenever we can throw away the history beyond the previous steps without any loss in predictive power, we say that the sequence satisfies a Markov condition, i.e., that the future is conditionally independent of the past, given the recent history. When , we say that the data is characterized by a first-order Markov model, and when , we say that the data is characterized by a -order Markov model. For when the first-order Markov condition holds () the factorization of our joint probability becomes a product of probabilities of each word given the previous word:
英語のヒント
ここで、上で述べた戦略を使いたいとしよう。系列の履歴全体ではなく、直前の個の時間ステップ、つまりだけを条件とするものである。直前のステップより前の履歴を、予測力を少しも失わずに捨てられるなら、その系列はマルコフ条件を満たす、つまり、最近の履歴が与えられれば未来は過去と条件付き独立である、と言う。のとき、データは1次のマルコフモデルで特徴づけられると言い、のとき、データは次のマルコフモデルで特徴づけられると言う。1次のマルコフ条件が成り立つとき()、同時確率の分解は、直前の単語が与えられたときの各単語の確率の積になる。
(9.1.4)
We often find it useful to work with models that proceed as though a Markov condition were satisfied, even when we know that this is only approximately true. With real text documents we continue to gain information as we include more and more leftwards context. But these gains diminish rapidly. Thus, sometimes we compromise, obviating computational and statistical difficulties by training models whose validity depends on a -order Markov condition. Even today’s massive RNN- and Transformer-based language models seldom incorporate more than thousands of words of context.
英語のヒント
マルコフ条件が近似的にしか成り立たないとわかっているときでも、それが満たされているかのように進めるモデルを扱うのが役に立つことは多い。実際のテキストの文書では、左側の文脈をどんどん含めるにつれて、情報を得続ける。しかし、その得られる量は急速に減っていく。そのため、ときには妥協して、次のマルコフ条件に妥当性を頼るモデルを訓練することで、計算と統計の難しさを回避する。今日の巨大なRNNやTransformerにもとづく言語モデルでさえ、数千語を超える文脈を取り込むことはめったにない。
With discrete data, a true Markov model simply counts the number of times that each word has occurred in each context, producing the relative frequency estimate of . Whenever the data assumes only discrete values (as in language), the most likely sequence of words can be computed efficiently using dynamic programming.
英語のヒント
離散データでは、本当のマルコフモデルは、各単語が各文脈に現れた回数を単純に数え、の相対頻度による推定値を出す。データが(言語のように)離散的な値しかとらないときはいつでも、最もありそうな単語の系列は、動的計画法を使って効率よく計算できる。
9.1.2.2. The Order of Decoding9.1.2.2 復号の順序
You may be wondering why we represented the factorization of a text sequence as a left-to-right chain of conditional probabilities. Why not right-to-left or some other, seemingly random order? In principle, there is nothing wrong with unfolding in reverse order. The result is a valid factorization:
英語のヒント
テキストの系列の分解を、なぜ左から右への条件付き確率の連鎖として表したのか、不思議に思うかもしれない。なぜ右から左や、一見でたらめなほかの順序ではないのか。原理的には、を逆の順序で展開しても何も問題はない。結果は妥当な分解になる。
(9.1.5)
However, there are many reasons why factorizing text in the same direction in which we read it (left-to-right for most languages, but right-to-left for Arabic and Hebrew) is preferred for the task of language modeling. First, this is just a more natural direction for us to think about. After all we all read text every day, and this process is guided by our ability to anticipate which words and phrases are likely to come next. Just think of how many times you have completed someone else’s sentence. Thus, even if we had no other reason to prefer such in-order decodings, they would be useful if only because we have better intuitions for what should be likely when predicting in this order.
英語のヒント
しかし、テキストを読むのと同じ方向(ほとんどの言語では左から右だが、アラビア語やヘブライ語では右から左)に分解するほうが、言語のモデリングの課題には好まれる理由がたくさんある。第一に、そのほうが単に考えるうえで自然な方向である。結局のところ、私たちはみな毎日テキストを読み、その過程は、次にどの単語や句が来そうかを予想する能力に導かれている。他人の文を何度言い当てて完成させたことがあるか考えてみればよい。したがって、こうした順方向の復号を好むほかの理由がまったくなくても、この順序で予測するときに何がありそうかについての直観がよく働くというだけでも、それは役に立つだろう。
Second, by factorizing in order, we can assign probabilities to arbitrarily long sequences using the same language model. To convert a probability over steps through into one that extends to word we simply multiply by the conditional probability of the additional token given the previous ones: .
英語のヒント
第二に、順方向に分解することで、同じ言語モデルを使って任意の長さの系列に確率を割り当てられる。ステップからまでの確率を、単語まで延びる確率に変換するには、それまでのトークンが与えられたときの追加のトークンの条件付き確率を掛けるだけでよい:。
Third, we have stronger predictive models for predicting adjacent words than words at arbitrary other locations. While all orders of factorization are valid, they do not necessarily all represent equally easy predictive modeling problems. This is true not only for language, but for other kinds of data as well, e.g., when the data is causally structured. For example, we believe that future events cannot influence the past. Hence, if we change , we may be able to influence what happens for going forward but not the converse. That is, if we change , the distribution over past events will not change. In some contexts, this makes it easier to predict than to predict . For instance, in some cases, we can find for some additive noise , whereas the converse is not true (Hoyer et al., 2009). This is great news, since it is typically the forward direction that we are interested in estimating. The book by Peters et al. (2017) contains more on this topic. We barely scratch the surface of it.
英語のヒント
第三に、隣り合う単語を予測するほうが、任意のほかの位置の単語を予測するより強い予測モデルがある。分解の順序はどれも妥当だが、それらがどれも同じくらい易しい予測のモデリングの問題を表すとは限らない。これは言語だけでなく、たとえばデータが因果的に構造化されている場合のように、ほかの種類のデータにも当てはまる。たとえば、未来の出来事は過去に影響しえないと考えられる。したがって、を変えれば、その先ので起きることには影響を与えられるかもしれないが、その逆はない。つまり、を変えても、過去の出来事についての分布は変わらない。文脈によっては、このためを予測するよりを予測するほうが易しくなる。たとえば、場合によっては、ある加法的なノイズについてとなるものを見つけられるが、その逆は成り立たない(Hoyer et al., 2009)。ふつう推定したいのは順方向なので、これは朗報である。Peters et al. (2017)の本には、この話題についてもっと多くのことが書かれている。ここでは、その表面をかすめるにすぎない。