Let's examine the other key layers we haven't discussed yet.
まだ詳しく議論していない、その他の重要なレイヤーを見ていきましょう。
位置エンコーディング
Since our model contains no recurrence and no convolution, in order for the model to make use of the order of the sequence, we must inject some information about the relative or absolute position of the tokens in the sequence. To this end, we add "positional encodings" to the input embeddings at the bottoms of the encoder and decoder stacks.
本モデルは再帰や畳み込みを含まないため、シーケンスの順序を利用するには、トークンの相対的または絶対的な位置に関する情報を挿入する必要がある。その目的のため、我々はエンコーダとデコーダのスタックの最下部において、入力の埋め込み(Embedding)に「位置エンコーディング(Positional Encodings)」を加算する。
The attention mechanism can process relationships between all embeddings at once. However, the attention layer itself has no way to distinguish tokens based on their position in the sentence. This is a significant problem since word order is critical information.
アテンション機構は、すべての埋め込み間の関係を一度に処理できます。しかし、アテンション層自体には、文中の位置に基づいてトークンを区別する方法がありません。単語の順序は非常に重要な情報なのでこれは大きな問題です。
To solve this, positional encoding layers at the start of the encoder and decoder add position information to each token. Think of this as a timestamp for each token. The authors use sine and cosine functions at different frequencies to create these timestamps.
これを解決するため、エンコーダとデコーダの開始部にある位置エンコーディング層が、それぞれのトークンに位置情報を追加します。これはトークンに対するタイムスタンプのようなものだと考えてください。論文では、異なる周波数のサイン関数とコサイン関数を使用して、これらのタイムスタンプを作成しています。
$PE_{(pos, 2i)} = \sin(pos / 10000^{2i/d_{model}})$
$PE_{(pos, 2i+1)} = \cos(pos / 10000^{2i/d_{model}})$
$pos$: The position of the word in the sentence (0 for $\text{I}$, 1 for $\text{\_ate}$, etc.).
$i$: The dimension index (from 0 to 511).
The result is a 512-dimensional vector of numbers between −1 and 1. And the layer simply adds this vector to the embeddings for each token.