code: def calculate_loss(self, y, pi, sigma, mu, tag="train"):
      # NLL Loss
      log_prob = self.head.log_prob(pi, sigma, mu, y)
      loss = torch.mean(-log_prob)
      if self.head.hparams.weight_regularization is not None:
          sigma_l1_reg = 0
          pi_l1_reg = 0
          mu_l1_reg = 0
          if self.head.hparams.lambda_sigma > 0:
              # Weight Regularization Sigma
              sigma_params = torch.cat(
                  [x.view(-1) for x in self.head.sigma.parameters()]
              )
              sigma_l1_reg = (
                  self.head.hparams.lambda_sigma
                  * torch.norm(
                      sigma_params,
                      self.head.hparams.weight_regularization,
                  )
              )
          if self.head.hparams.lambda_pi > 0:
              pi_params = torch.cat(
                  [x.view(-1) for x in self.head.pi.parameters()]
              )
              pi_l1_reg = self.head.hparams.lambda_pi * torch.norm(
                  pi_params, self.head.hparams.weight_regularization
              )
          if self.head.hparams.lambda_mu > 0:
              mu_params = torch.cat(
                  [x.view(-1) for x in self.head.mu.parameters()]
              )
              mu_l1_reg = self.head.hparams.lambda_mu * torch.norm(
                  mu_params, self.head.hparams.weight_regularization
              )
  
          loss = loss + sigma_l1_reg + pi_l1_reg + mu_l1_reg
      self.log(
          f"{tag}_loss",
          loss,
          on_epoch=(tag == "valid") or (tag == "test"),
          on_step=(tag == "train"),
          # on_step=False,
          logger=True,
          prog_bar=True,
      )
      return loss
  
imports: from typing import Dict, Optional, Union
  import torch
  import torch.nn
  from omegaconf import DictConfig, OmegaConf
  from torch import Tensor
  from pytorch_tabular import models
  from pytorch_tabular.config.config import ModelConfig
  from pytorch_tabular.models.common.heads import blocks
  from pytorch_tabular.models.tab_transformer.tab_transformer import TabTransformerBackbone
  from pytorch_tabular.tabular_model import getattr_nested
  from pytorch_tabular.utils import get_logger
  from ..base_model import BaseModel, safe_merge_config
label_desc: Use image node_id 12 for calling the MDNModel obj's underlying member method code with example usage: obj.calculate_loss(y, pi, sigma, mu, tag) and returns: loss