Multi-Step time series LSTM Network

Jari_Peeperkorn: <p>Hey</p>
<p>I am having issues with the LSTM function in pytorch. I am using an LSTM neural network to forecast a certain value. The input is multidimensional (multiple features) and the output should be one dimensional (only one feature that needs to be forecasted). I want to forecast something 1-6 timesteps in advance. I want to use multi timestep input as well. Now I have to different ways of achieving this but neither of them seem to work.</p>
<p>The first one is making 6 different many-to-one networks each forecasting another timestep 1-6h in advance, but still using the recurrent structure (see picture) when forecasting multiple time steps ahead (so not just shifting the target data by 1-6 hours). Another option would be a many to many neural network, this would work fine as well I think. (also see picture)</p>
<p>My input now looks like: where first the different parameters at the same timestep are grouped and then further each time all the timesteps we want to use in the forecast are grouped (look back)</p>
<p>tensor([[[-0.2800, -0.6381, -0.1033, -0.4941,  0.0016],<br>
[-0.3159,  0.1378, -0.1010, -0.4529,  0.0016],<br>
[-0.2800,  0.1378, -0.0963, -0.4706,  0.1150],<br>
…,<br>
[-0.5673, -0.2149, -0.0598, -0.4000,  0.2850],<br>
[-0.3518, -0.4265, -0.0669, -0.3646,  0.3417],<br>
[-0.2440, -0.0738, -0.0657, -0.3823,  0.2283]],</p>
<pre><code>    [[-0.3159,  0.1378, -0.1010, -0.4529,  0.0016],
     [-0.2800,  0.1378, -0.0963, -0.4706,  0.1150],
     [-0.7469,  0.1731, -0.0845, -0.4176,  0.3417],
     ...,
     [-0.3518, -0.4265, -0.0669, -0.3646,  0.3417],
     [-0.2440, -0.0738, -0.0657, -0.3823,  0.2283],
     [-0.1722, -0.5323, -0.0610, -0.4117,  0.2283]],

    [[-0.2800,  0.1378, -0.0963, -0.4706,  0.1150],
     [-0.7469,  0.1731, -0.0845, -0.4176,  0.3417],
     [-0.7829, -0.4265, -0.0692, -0.4176,  0.4550],
     ...,
     [-0.2440, -0.0738, -0.0657, -0.3823,  0.2283],
     [-0.1722, -0.5323, -0.0610, -0.4117,  0.2283],
     [-0.1363, -0.8850, -0.0669, -0.4294,  0.1150]],

    ...,

    [[-0.3518,  0.2083, -0.1386,  0.8479, -0.1684],
     [-0.3518,  0.4552, -0.1398,  0.9480,  0.0016],
     [-0.2800, -0.4265, -0.1398,  0.9126,  0.0583],
     ...,
     [-1.0343, -0.1443, -0.1433,  0.8479,  0.0016],
     [-0.8906,  0.3847, -0.1445,  1.0304, -0.2251],
     [-0.7829, -0.0385, -0.1433,  1.0127, -0.1117]],

    [[-0.3518,  0.4552, -0.1398,  0.9480,  0.0016],
     [-0.2800, -0.4265, -0.1398,  0.9126,  0.0583],
     [-0.4596, -0.9202, -0.1410,  0.8479,  0.1150],
     ...,
     [-0.8906,  0.3847, -0.1445,  1.0304, -0.2251],
     [-0.7829, -0.0385, -0.1433,  1.0127, -0.1117],
     [-0.8547,  0.2436, -0.1422,  0.9715, -0.0550]],

    [[-0.2800, -0.4265, -0.1398,  0.9126,  0.0583],
     [-0.4596, -0.9202, -0.1410,  0.8479,  0.1150],
     [-0.6392, -0.5323, -0.1422,  0.8655,  0.0016],
     ...,
     [-0.7829, -0.0385, -0.1433,  1.0127, -0.1117],
     [-0.8547,  0.2436, -0.1422,  0.9715, -0.0550],
     [-0.9984, -0.0033, -0.1422,  0.8597,  0.0583]]])
</code></pre>
<p>And the output looks like, where the different timesteps 1-6h in advance are grouped.  I can change this easily.</p>
<p>tensor([[[ -7.],<br>
[ -9.],<br>
[-11.],<br>
[-13.],<br>
[-13.]],</p>
<pre><code>    [[ -9.],
     [-11.],
     [-13.],
     [-13.],
     [-10.]],

    [[-11.],
     [-13.],
     [-13.],
     [-10.],
     [ -9.]],

    ...,

    [[-12.],
     [-10.],
     [-10.],
     [-10.],
     [ -9.]],

    [[-10.],
     [-10.],
     [-10.],
     [ -9.],
     [ -8.]],

    [[-10.],
     [-10.],
     [ -9.],
     [ -8.],
     [-10.]]])
</code></pre>
<p>Now I have no idea how to use the LSTM structure to do multi timesteps forecasting. The output layer should be linear.</p>
<p>The batch size does not really matter to me, I think it can be one for now.<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/2X/5/598d822d530690ae794fea13c31ce9eeaa6a1020.jpeg" data-download-href="https://discuss.pytorch.org/uploads/default/598d822d530690ae794fea13c31ce9eeaa6a1020" title="Screenshot%20from%202019-04-04%2011-42-06"><img src="https://discuss.pytorch.org/uploads/default/optimized/2X/5/598d822d530690ae794fea13c31ce9eeaa6a1020_2_690x427.jpeg" alt="Screenshot%20from%202019-04-04%2011-42-06" data-base62-sha1="cMdFSoG0qbc0miZBRzjlePsOmwU" width="690" height="427" srcset="https://discuss.pytorch.org/uploads/default/optimized/2X/5/598d822d530690ae794fea13c31ce9eeaa6a1020_2_690x427.jpeg, https://discuss.pytorch.org/uploads/default/original/2X/5/598d822d530690ae794fea13c31ce9eeaa6a1020.jpeg 1.5x, https://discuss.pytorch.org/uploads/default/original/2X/5/598d822d530690ae794fea13c31ce9eeaa6a1020.jpeg 2x" data-dominant-color="E7E7E6"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">Screenshot%20from%202019-04-04%2011-42-06</span><span class="informations">812×503 65.5 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>

vdw: <p>Probably not a very useful answer, but at least some some ideas:</p>
<p>You could look into <a href="https://pytorch.org/tutorials/intermediate/seq2seq_translation_tutorial.html" rel="nofollow noopener">sequence-to-sequence / encoder-decoder models</a>, which are essentially many-to-many solutions, most commonly used in machine translation. Both input and output are sequences, and since your input and output sequences have the same length, you can easily use batches.</p>
<p>Alternatively you can re-organize your dataset to allow for a (usually) simpler many-to-one model. It’s not clear if your input sequences of a fixed length. But lets say for a single data item the input is [A, B, C, D, E, F] and the output sequence is [1, 2 ,3]</p>
<p>Option A: The input sequences keep the fixed length:</p>
<pre><code> [A, B, C, D, E, F], [1]
 [B, C, D, E, F, 1], [2]
 [C, D, E, F, 1, 2], [3]
</code></pre>
<p>The prediction is the step by step. In each step you use the last prediction as last element of the input sequences kick out the first element.</p>
<p>Option B: You create sequences of variable length. for training you only might want to make sure that each batch contains only sequences of the same length.</p>
<pre><code> [A, B, C, D, E, F], [1]
 [A, B, C, D, E, F, 1], [2]
 [A, B, C, D, E, F, 1, 2], [3]
</code></pre>
<p>or use padding:</p>
<pre><code> [A, B, C, D, E, F, 0, 0], [1]
 [A, B, C, D, E, F, 1, 0], [2]
 [A, B, C, D, E, F, 1, 2], [3]</code></pre>

Jari_Peeperkorn: <p>Sorry if it was not completely clear.</p>
<p>The input is multidimensional (5) so I can not directly use your options, as A-F are five dimensional data and 1-3 are one dimensional. The input consists of not only the thing we want to forecast but multiple features.</p>

vdw: <p>Sorry, I see your point now! Technically, you could represent all data as a 6-dimensional vector, where A-F have zeros at the 6th dimension and 1-3 have zeros at positions 1-5. But, yeah, that’s probably too far fetched :).</p>
<p>Then you probably can still try to treat your problem like a sequence-to-sequence task. While 6 many-to-one network will work in principle, you obviously use the dependencies between the outputs – I assume that the 6h output not only depends on the input but also on the outputs for hours 1-5.</p>

Jari_Peeperkorn: <p>Yes the 6th output will preferably also depend on the output for 1-5 hours. If not I could just shift my output target data 6 hours, but then as far as I know, I am not using the strength of the recurrent structure.</p>

Jari_Peeperkorn: <p>Would you happen to have an example of the Seq2seq LSTM in pytorch? I have a little bit of problems trying to implement it. And I do notcompletely understand how to interpret the example here <a href="https://pytorch.org/tutorials/intermediate/seq2seq_translation_tutorial.html" rel="nofollow noopener">https://pytorch.org/tutorials/intermediate/seq2seq_translation_tutorial.html</a> to change it to something more relevant for me.</p>

vdw: <p>Well, I’ve tried to come up with some kind of minimal example. I took some code of mine - which essentially is itself derived from the Seq2Seq tutorial you’ve linked - but adjusted to your use case. While it should run “as is”, <strong>I do not give any guarantees that it’s correct!</strong> Without any training data I cannot test of the loss decreases and the predictions get better over time.</p>
<p>I actually never used LSTMs for regression, so I’m not sure I’ve done it properly. I’ve commented the code a bit so it might give at least some pointers what’s going on.</p>
<pre><code>import torch
import torch.nn as nn
import torch.optim as optim

import numpy as np

class Encoder(nn.Module):

    def __init__(self, input_size, hidden_dim, num_layers=1):
        super(Encoder, self).__init__()

        self.input_size = input_size
        self.hidden_dim = hidden_dim
        self.num_layers = num_layers
        self.lstm = nn.LSTM(self.input_size, self.hidden_dim, num_layers=self.num_layers)
        self.hidden = None

    def init_hidden(self, batch_size):
        return (torch.zeros(self.num_layers, batch_size, self.hidden_dim),
                torch.zeros(self.num_layers, batch_size, self.hidden_dim))

    def forward(self, inputs):
        # Push through RNN layer (the ouput is irrelevant)
        _, self.hidden = self.lstm(inputs, self.hidden)
        return self.hidden


class Decoder(nn.Module):

    def __init__(self, hidden_dim, num_layers=1):
        super(Decoder, self).__init__()
        # input_size=1 since the output are single values
        self.lstm = nn.LSTM(1, hidden_dim, num_layers=num_layers)
        self.out = nn.Linear(hidden_dim, 1)

    def forward(self, outputs, hidden, criterion):
        batch_size, num_steps = outputs.shape
        # Create initial start value/token
        input = torch.tensor([[0.0]] * batch_size, dtype=torch.float)
        # Convert (batch_size, output_size) to (seq_len, batch_size, output_size)
        input = input.unsqueeze(0)

        loss = 0
        for i in range(num_steps):
            # Push current input through LSTM: (seq_len=1, batch_size, input_size=1)
            output, hidden = self.lstm(input, hidden)
            # Push the output of last step through linear layer; returns (batch_size, 1)
            output = self.out(output[-1])
            # Generate input for next step by adding seq_len dimension (see above)
            input = output.unsqueeze(0)
            # Compute loss between predicted value and true value
            loss += criterion(output, outputs[:, i])
        return loss


if __name__ == '__main__':

    # 5 is the number of features of your data points
    encoder = Encoder(5, 128)
    decoder = Decoder(128)
    # Create optimizers for encoder and decoder
    encoder_optimizer = optim.Adam(encoder.parameters(), lr=0.001)
    decoder_optimizer = optim.Adam(decoder.parameters(), lr=0.001)
    criterion = nn.MSELoss()

    # Some toy data: 2 sequences of length 10 with 5 features for each data point
    inputs = [
        [
            [0.5, 0.2, 0.3, 0.4, 0.1],
            [0.5, 0.2, 0.3, 0.4, 0.1],
            [0.5, 0.2, 0.3, 0.4, 0.1],
            [0.5, 0.2, 0.3, 0.4, 0.1],
            [0.5, 0.2, 0.3, 0.4, 0.1],
            [0.5, 0.2, 0.3, 0.4, 0.1],
            [0.5, 0.2, 0.3, 0.4, 0.1],
            [0.5, 0.2, 0.3, 0.4, 0.1],
            [0.5, 0.2, 0.3, 0.4, 0.1],
            [0.5, 0.2, 0.3, 0.4, 0.1],
        ],
        [
            [0.5, 0.2, 0.3, 0.4, 0.1],
            [0.5, 0.2, 0.3, 0.4, 0.1],
            [0.5, 0.2, 0.3, 0.4, 0.1],
            [0.5, 0.2, 0.3, 0.4, 0.1],
            [0.5, 0.2, 0.3, 0.4, 0.1],
            [0.5, 0.2, 0.3, 0.4, 0.1],
            [0.5, 0.2, 0.3, 0.4, 0.1],
            [0.5, 0.2, 0.3, 0.4, 0.1],
            [0.5, 0.2, 0.3, 0.4, 0.1],
            [0.5, 0.2, 0.3, 0.4, 0.1],
        ]
    ]

    inputs = torch.tensor(np.array(inputs), dtype=torch.float)
    # Convert (batch_size, seq_len, input_size) to (seq_len, batch_size, input_size)
    inputs = inputs.transpose(1,0)

    # 2 sequences (to match the batch size) of length 6 (for the 6h into the future)
    outputs = [ [0.1, 0.2, 0.3, 0.1, 0.2, 0.3], [0.3, 0.2, 0.1, 0.3, 0.2, 0.1] ]
    outputs = torch.tensor(np.array(outputs), dtype=torch.float)

    #
    # Do one complete forward &amp; backward pass
    #
    # Zero gradients of both optimizers
    encoder_optimizer.zero_grad()
    decoder_optimizer.zero_grad()
    # Reset hidden state of encoder for current batch
    encoder.hidden = encoder.init_hidden(inputs.shape[1])
    # Do forward pass through encoder
    hidden = encoder(inputs)
    # Do forward pass through decoder (decoder gets hidden state from encoder)
    loss = decoder(outputs, hidden, criterion)
    # Backpropagation
    loss.backward()
    # Update parameters
    encoder_optimizer.step()
    decoder_optimizer.step()
    print("Loss:", loss.item())</code></pre>

Jari_Peeperkorn: <aside class="quote no-group" data-username="vdw" data-post="7" data-topic="41670">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/vdw/48/10074_2.png" class="avatar"> vdw:</div>
<blockquote>
<h1>Convert (batch_size, seq_len, input_size) to (seq_len, batch_size, input_size) inputs = inputs.transpose(1,0)</h1>
</blockquote>
</aside>
<p>Is this step necessary? Does the network have to read the inputs in like this? Can you also input your network an input of (batch_size, seq_len, input_size) ?</p>

Jari_Peeperkorn: <aside class="quote no-group" data-username="vdw" data-post="7" data-topic="41670">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/vdw/48/10074_2.png" class="avatar"> vdw:</div>
<blockquote>
<h1>Reset hidden state of encoder for current batch encoder.hidden = encoder.init_hidden(inputs.shape[1])</h1>
</blockquote>
</aside>
<p>And why do we do this step? Will this not erase any sort of training we’ve done?</p>

vdw: <p>It’s possible, but then you have to tell Pytorch so by using <code>batch_first=True</code> here:</p>
<pre><code>    self.lstm = nn.LSTM(..., batch_first=True)
</code></pre>
<p>However, depending where you do it (the encoder, decoder, or both) you need to make other changes to the code. For example, when the decoder LSTM takes <code>batch_first=True</code> you probably have to change the following:</p>
<pre><code>#input = input.unsqueeze(0)
input = input.unsqueeze(1)

#output = self.out(output[-1])
output = self.out(output[:, -1, :])
</code></pre>
<p>…and maybe other stuffm I’ve haven’t tested it, but <code>batch_first=True</code> also changes the shape of the output of the LSTM which naturally affects how to handle it for subsequent steps.</p>

vdw: <p>You might want to have a look at these posts: <a href="https://discuss.pytorch.org/t/when-to-call-init-hidden-for-rnn/11518">1</a>, <a href="https://discuss.pytorch.org/t/when-to-initialize-lstm-hidden-state/2323">2</a>, <a href="https://discuss.pytorch.org/t/how-to-properly-use-hidden-states-for-rnn/13607/">3</a></p>

Jari_Peeperkorn: <p>Oh yes, I see now. This hidden are not the weights but a parameter that is calculated when we are running the neural network. Thank you very much for all the help!</p>

Jari_Peeperkorn: <p>I have implemented it for my problem and I got this training history (the x axis goes for each epoch through each batch and plots the loss on the y axis) Now I will make some grid for the hyper parameters. Again thanks for all the help.</p>
<p><img src="https://discuss.pytorch.org/uploads/default/original/2X/7/77d500fdc69d1044a812cb5705646a4bcee9ac30.png" alt="training" data-base62-sha1="h65b0YXTeppzPaBdKjUCRGWZ4yI" width="391" height="252"></p>

vdw: <p>Happy to help. It’s a good way to learn more myself. Happy coding!</p>

Jari_Peeperkorn: <aside class="quote no-group" data-username="vdw" data-post="7" data-topic="41670">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/vdw/48/10074_2.png" class="avatar"> vdw:</div>
<blockquote>
<h1>Push current input through LSTM: (seq_len=1, batch_size, input_size=1)</h1>
</blockquote>
</aside>
<p>Is this comment correct? Because how I saw it, the input size is actually the thing we defined as the hidden size. So the number of input features of the decoder is equal to the number of features the decoder gives the one time step output.</p>

vdw: <p><code>input_size</code> has nothing to do with <code>hidden_size</code>.</p>
<p><code>hidden_size</code> specifies the dimension of the internal hidden states of the RNN as defined when doing <code>self.lstm = nn.LSTM(input_size, hidden_size, ...)</code>. This can be any value independet of <code>input_size</code></p>
<p><code>input_size</code> is the number of features for each element in the sequence. In your case, for the encoder <code>input_size=6</code> and for the decoder <code>input_size=1</code>. Both encoder work that they take the output for the last step as input for the current step. And since the output of your decoder is just 1-dimensional, the <code>input_size</code> must be as well.</p>
<p>In classic machine translation where both input and target words are represented as vectors with the same dimension (e.g.,), then yes, encoder and decoder have the same <code>input_size</code>. In your case, however, encoder and decoder handle different types of inputs and targets: 6-dim for the encoder, 1-dim for the decoder.</p>
<p>This also means that the current input of the decoder has always the shape <code>(1, batch_size, 1)</code>, which I was referring to in that comment.</p>

Jari_Peeperkorn: <p>if I understand correctly then: all the information of the sequence length * input size, so in my case 50 data points or so, is stored into just 6 numbers in the encoder? And the decoder takes only the last number to get information from?</p>
<p>Because I thought at first that what the decoder takes from the encoder would be multidimensional, so that there is less loss of information.</p>

vdw: <p>Best check this <a href="https://i.stack.imgur.com/SjnTl.png" rel="noopener nofollow ugc">very useful diagram</a>:</p>
<ul>
<li>Since you have sequence of length 50, you have <code>x_1, x_2, ..., x_50</code>; each <code>x_i</code> is one time step</li>
<li>For you encoder, each <code>x_i</code> is 6-dimensional; for your decoder, each <code>x_i</code> is 1-dimensional</li>
<li><code>depth</code> reflects <code>num_layers</code> in the code</li>
<li>The hidden state of a LSTM is a tuple <code>(h_i, c_i)</code>, both have the same shape</li>
<li>The decoder gets the complete final hidden state <code>(h_n, c_n)</code> from the decoder (n=50 for you)</li>
<li>The shapes of <code>h_i</code> and <code>c_i</code> are defined by <code>hidden_dim</code></li>
</ul>
<p>To directly answer your questions:</p>
<blockquote>
<p>all the information of the sequence length * input size, so in my case 50 data points or so, is stored into just 6 numbers in the encoder?</p>
</blockquote>
<p>No, all the information of the input (seq_len*input_size) is stored as the last hidden state <code>(h_n, c_n)</code> which is independent from <code>input_size</code>. It depends on <code>hidden_dim</code>, ‘num_layers’, <code>num_directions</code>, and <code>batch_size</code>.</p>
<blockquote>
<p>And the decoder takes only the last number to get information from?</p>
</blockquote>
<p>No the decoder takes <code>(h_n, c_n)</code> is first hidden state. So yeah, the hidden state the decoder gets is multidimensional.</p>
<blockquote>
<p>Because I thought at first that what the decoder takes from the encoder would be multidimensional, so that there is less loss of information.</p>
</blockquote>
<p>Again, I think you confuse the hidden state with the input. Your decoder input/output is 1-dimensional (just a number). In the line <code>output, hidden = self.lstm(input, hidden)</code> of the decoder:</p>
<ul>
<li><code>input.shape = (batch_size, input_size=1)</code></li>
<li><code>hidden[0].shape = hidden[1].shape = (input_size=1, batch_size, hidden_dim)</code></li>
</ul>
<p>For the the encoder it’s the same, only with 6 instead of 1</p>

Jari_Peeperkorn: <p>Wow thank you, I think I understand it. Just to be sure, is this image then a correct representation? The opaque stuff is what is not given (input) or is not interesting anymore (output).</p>
<p>And so the number of LSTM layers and the layer size should be the same in encoder and decoder.<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/2X/3/396587256971428bd5f5370fc047916723acd45e.png" data-download-href="https://discuss.pytorch.org/uploads/default/396587256971428bd5f5370fc047916723acd45e" title="enc-dec"><img src="https://discuss.pytorch.org/uploads/default/optimized/2X/3/396587256971428bd5f5370fc047916723acd45e_2_690x266.png" alt="enc-dec" data-base62-sha1="8bKJMi70wGcfgKJKSXDO9qAayZw" width="690" height="266" srcset="https://discuss.pytorch.org/uploads/default/optimized/2X/3/396587256971428bd5f5370fc047916723acd45e_2_690x266.png, https://discuss.pytorch.org/uploads/default/optimized/2X/3/396587256971428bd5f5370fc047916723acd45e_2_1035x399.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/2X/3/396587256971428bd5f5370fc047916723acd45e_2_1380x532.png 2x" data-dominant-color="F2F4F5"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">enc-dec</span><span class="informations">1400×540 36.7 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>

vdw: <p>Yup, that’s pretty much what the code is doing – just to add:</p>
<ul>
<li>The encoder get’s the whole sequence at once, while the decoder generates tokens/values time step by time step.</li>
<li>The decoder also gets some inputs <code>x_i</code> but <code>x_1</code> is some fixed start value (0.0 in the code but can technically be anything), and <code>x_(i+1) = output_i</code> – that is, the input for time step <code>i+1</code> is the last prediction of the decoder at time step <code>i</code>. That’s the <code>input = output.unsqueeze(0)</code> line. So strictly speaking the input for the decoder shouldn’t be opaque, but I get your point.</li>
<li>An extension of this model would be to use “teacher forcing” in the decoder, where for some examples in the data, not the predicted output is used as next input but the true values. You can read up on this in the PyTorch Seq2Seq tutorial, but it’s not important right now.</li>
</ul>
<p>This figure makes it very clear how the decoder works by taking the last output as next input, and starting with a defaut token <code>&lt;START&gt;</code> (which is the 0.0 in the code since deal with single values)<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/2X/2/2dc3affb73ddd0bbb98959f028fa6e18342a8ee4.png" data-download-href="https://discuss.pytorch.org/uploads/default/2dc3affb73ddd0bbb98959f028fa6e18342a8ee4" title="seq2seq"><img src="https://discuss.pytorch.org/uploads/default/optimized/2X/2/2dc3affb73ddd0bbb98959f028fa6e18342a8ee4_2_690x207.png" alt="seq2seq" data-base62-sha1="6wQKa4HTIU9ZYnRjXFFIprHV2Bu" width="690" height="207" srcset="https://discuss.pytorch.org/uploads/default/optimized/2X/2/2dc3affb73ddd0bbb98959f028fa6e18342a8ee4_2_690x207.png, https://discuss.pytorch.org/uploads/default/optimized/2X/2/2dc3affb73ddd0bbb98959f028fa6e18342a8ee4_2_1035x310.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/2X/2/2dc3affb73ddd0bbb98959f028fa6e18342a8ee4_2_1380x414.png 2x" data-dominant-color="F0F3F0"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">seq2seq</span><span class="informations">1585×477 46.1 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>