code: def UnsupervisedLoss(y_pred, embedded_x, obf_vars, eps=1e-9):
      """
      Implements unsupervised loss function.
      This differs from orginal paper as it's scaled to be batch size independent
      and number of features reconstructed independent (by taking the mean)
  
      Parameters
      ----------
      y_pred : torch.Tensor or np.array
          Reconstructed prediction (with embeddings)
      embedded_x : torch.Tensor
          Original input embedded by network
      obf_vars : torch.Tensor
          Binary mask for obfuscated variables.
          1 means the variable was obfuscated so reconstruction is based on this.
      eps : float
          A small floating point to avoid ZeroDivisionError
          This can happen in degenerated case when a feature has only one value
  
      Returns
      -------
      loss : torch float
          Unsupervised loss, average value over batch samples.
      """
      errors = y_pred - embedded_x
      reconstruction_errors = torch.mul(errors, obf_vars) ** 2
      batch_means = torch.mean(embedded_x, dim=0)
      batch_means[batch_means == 0] = 1
  
      batch_stds = torch.std(embedded_x, dim=0) ** 2
      batch_stds[batch_stds == 0] = batch_means[batch_stds == 0]
      features_loss = torch.matmul(
          reconstruction_errors, 1 / batch_stds
      )
      # compute the number of obfuscated variables to reconstruct
      nb_reconstructed_variables = torch.sum(obf_vars, dim=1)
      # take the mean of the reconstructed variable errors
      features_loss = features_loss / (nb_reconstructed_variables + eps)
      # here we take the mean per batch, contrary to the paper
      loss = torch.mean(features_loss)
      return loss
  
imports: from dataclasses import dataclass
  from typing import List
  import numpy
  from sklearn.metrics import roc_auc_score, mean_squared_error, mean_absolute_error, accuracy_score, log_loss, balanced_accuracy_score, mean_squared_log_error
  import torch
label_desc: Use image node_id 1 for calling a global function with example usage: UnsupervisedLoss(y_pred, embedded_x, obf_vars, eps) and returns: loss