class_docstr: Time series encoder. This module can learn features for any `order_by` temporal column, both with and without accompanying target data.
  
  The backbone of this encoder is either a recurrent neural network or a transformer; both structured in an encoder-decoder fashion.
class_docstr_tok: ["Time","series","encoder",".","This","module","can","learn","features","for","any","`","order_by","`","temporal","column",",","both","with","and","without","accompanying","target","data",".","The","backbone","of","this","encoder","is","either","a","recurrent","neural","network","or","a","transformer",";","both","structured","in","an","encoder-decoder","fashion","."]
docstr: Computes the loss of the first `lengths` items in the chunk 
docstr_tok: ["Computes","the","loss","of","the","first","`","lengths","`","items","in","the","chunk"]
code: def _masked_criterion(self, output, targets, lengths):
      """Computes the loss of the first `lengths` items in the chunk"""
      # Put in (B, T) format and zero-out the unnecessary values
      mask = len_to_mask(lengths, zeros=False).t()
  
      # Inflate to feature dimension
      mask = mask.unsqueeze(-1).repeat(1, 1, output.shape[-1])
      output = output * mask
      targets = targets * mask
  
      # compute the loss with respect to the appropriate lengths and average across the batch-size
      # We compute for every output (x_i)_i=1^L and target (y_i)_i=1^L, loss = 1/L \sum (x_i - y_i)^2
      # And average across the mini-batch
      losses = (
          self._base_criterion(output, targets).sum(dim=2).sum(dim=0)
      )
  
      # The TBPTT will compute a slightly different loss, but it is not problematic
      loss = torch.dot((1.0 / lengths.float()), losses) / len(losses)
  
      return loss
  
imports: import time
  from math import gcd
  from typing import List
  from copy import deepcopy
  import numpy
  import pandas
  import torch
  import torch.nn
  from torch import optim
  from type_infer.dtype import dtype
  from lightwood.helpers.log import log
  from lightwood.encoder.base import BaseEncoder
  from lightwood.helpers.device import get_device_from_name
  from lightwood.helpers.torch import LightwoodAutocast
  from lightwood.encoder.datetime import DatetimeNormalizerEncoder
  from lightwood.encoder.time_series.helpers.rnn_helpers import EncoderRNNNumerical, DecoderRNNNumerical
  from lightwood.encoder.helpers import MinMaxNormalizer, CatNormalizer
  from lightwood.encoder.time_series.helpers.transformer_helpers import TransformerEncoder, get_chunk, len_to_mask
label_desc: Use image node_id 11 for calling the TimeSeriesEncoder obj's underlying member method code with example usage: obj._masked_criterion(output, targets, lengths) and returns: loss