class_docstr: RNN Encoder.
  
  Modified to encode history vector in context lstm.
class_docstr_tok: ["RNN","Encoder",".","Modified","to","encode","history","vector","in","context","lstm","."]
docstr: Return padded and reshaped sequence (x) according to tensor lengths
  Example:
      x = tensor([[1, 2], [2, 3], [4, 0], [5, 6], [7, 8], [9, 10]])
      lengths = tensor([1, 2, 2, 1])
  Would output:
      tensor([[[1, 2], [0, 0]],
              [[2, 3], [4, 0]],
              [[5, 6], [7, 8]],
              [[9, 10], [0, 0]]])
docstr_tok: ["Return","padded","and","reshaped","sequence","(","x",")","according","to","tensor","lengths","Example",":","x","=","tensor","(","[","[","1",",","2","]",",","[","2",",","3","]",",","[","4",",","0","]",",","[","5",",","6","]",",","[","7",",","8","]",",","[","9",",","10","]","]",")","lengths","=","tensor","(","[","1",",","2",",","2",",","1","]",")","Would","output",":","tensor","(","[","[","[","1",",","2","]",",","[","0",",","0","]","]",",","[","[","2",",","3","]",",","[","4",",","0","]","]",",","[","[","5",",","6","]",",","[","7",",","8","]","]",",","[","[","9",",","10","]",",","[","0",",","0","]","]","]",")"]
code: def sequence_to_padding(self, x, lengths):
      """
      Return padded and reshaped sequence (x) according to tensor lengths
      Example:
          x = tensor([[1, 2], [2, 3], [4, 0], [5, 6], [7, 8], [9, 10]])
          lengths = tensor([1, 2, 2, 1])
      Would output:
          tensor([[[1, 2], [0, 0]],
                  [[2, 3], [4, 0]],
                  [[5, 6], [7, 8]],
                  [[9, 10], [0, 0]]])
      """
      ret_tensor = torch.zeros(
          (lengths.shape[0], torch.max(lengths).int())
          + tuple(x.shape[1:])
      ).to(x.device)
      cum_len = 0
      for i, l in enumerate(lengths):
          ret_tensor[i, :l] = x[cum_len : cum_len + l]
          cum_len += l
      return ret_tensor
  
file_path: ParlAI/parlai/agents/hred/modules.py
imports: import torch
  import torch.nn
  from parlai.agents.seq2seq.modules import OutputLayer, RNNEncoder, _transpose_hidden_state
  from parlai.core.torch_generator_agent import TorchGeneratorModel
label_desc: Use image node_id 3 for calling the HredEncoder obj's underlying member method code with example usage: obj.sequence_to_padding(x, lengths) and returns: ret_tensor