第10章現代のリカレントニューラルネットワーク
10.6.2. Decoder10.6.2 デコーダ
In the following decoder interface, we add an additional
init_state method to convert the encoder output (enc_all_outputs) into the encoded state. Note that this step may require extra inputs, such as the valid length of the input, which was explained in Section 10.5. To generate a variable-length sequence token by token, every time the decoder may map an input (e.g., the generated token at the previous time step) and the encoded state into an output token at the current time step.英語のヒント
以下のデコーダのインターフェースでは、エンコーダの出力(
enc_all_outputs)を符号化された状態に変換するためのinit_stateメソッドを追加する。この手順には、10.5節で説明した入力の有効な長さのような、追加の入力が必要になることがあることに注意してほしい。可変長の系列をトークンごとに生成するため、デコーダは毎回、入力(たとえば前の時間ステップで生成されたトークン)と符号化された状態を、現在の時間ステップの出力トークンに写す。class Decoder(nn.Module): #@save
"""The base decoder interface for the encoder--decoder architecture."""
def __init__(self):
super().__init__()
# Later there can be additional arguments (e.g., length excluding padding)
def init_state(self, enc_all_outputs, *args):
raise NotImplementedError
def forward(self, X, state):
raise NotImplementedError