The sequence to sequence model of Sutskever, Vinyals and Le reads a source sentence one word at a time with a stack of LSTM layers and keeps only the final state of every layer. That state is the fixed-size vector from which the decoder will write the translation. Implement the encoder.
encode(src_ids, emb, layers) -> (states, v)
src_ids: list of token ids, in the order they are read (any reversal has already been done). It may be empty.emb: embedding table, NumPy array of shape (V, E); token t is read as the vector emb[t].layers: list of dicts, bottom layer first. Layer has "W" of shape (4H, D_l + H) and "b" of shape (4H,), where and for . Every layer has the same hidden size .lstm_cell(x, h, c, W, b) returns the new (h, c) of one layer for one step. Use it.Every layer starts from . At each time step , layer 1 receives the embedding of token , and layer receives the hidden state that layer has just produced at the same step :
Return:
states: a list of tuples (h, c), bottom layer first, holding each layer's state after the last token (NumPy arrays of shape (H,)).v: one NumPy array of length , the concatenation .