docstr: This method encodes an input unrolled through time
docstr_tok: ["This","method","encodes","an","input","unrolled","through","time"]
code: def bptt(self, data, criterion, device):
      """This method encodes an input unrolled through time"""
      loss = 0
      hidden_state = self.init_hidden(device, batch_size=data.shape[0])
      next_tensor = data[:, 0, :].unsqueeze(dim=1)  # initial input
  
      for tensor_i in range(data.shape[1] - 1):
          rand = np.random.randint(2)
          # teach from forward as well as from known tensor alternatively
          if rand == 1:
              next_tensor, hidden_state = self.forward(
                  data[:, tensor_i, :].unsqueeze(dim=1), hidden_state
              )
          else:
              next_tensor, hidden_state = self.forward(
                  next_tensor.detach(), hidden_state
              )
  
          loss += criterion(
              next_tensor, data[:, tensor_i + 1, :].unsqueeze(dim=1)
          )
  
      return next_tensor, hidden_state, loss
  
file_path: lightwood/lightwood/encoder/time_series/helpers/rnn_helpers.py
imports: import torch
  import torch.nn
  import numpy
  from lightwood.helpers.torch import LightwoodAutocast
label_desc: Use image node_id 4 for calling the EncoderRNNNumerical obj's underlying member method code with example usage: obj.bptt(data, criterion, device) and returns: next_tensor,  hidden_state,  loss