class_docstr: The UnifiedInformationExplainer for returning explanations for pytorch NN models.
      
class_docstr_tok: ["The","UnifiedInformationExplainer","for","returning","explanations","for","pytorch","NN","models","."]
docstr: Calculate the variance of the state generated from the perturbed inputs that is used for Interpreter
  :param sampled_x: A list of sampled input embeddings $x$, each $x$ is of shape ``[length, dimension]``.
  All the $x$s can have different length, but should have the same dimension. Sampled number should be higher
  to get a good estimation.
  :type sampled_x: list[torch.Tensor]
  :param reduced_axes: The axes that is variable in Phi (e.g., the sentence length axis). We will reduce
  these axes by mean along them.
  :type reduced_axes: list[int]
  :param model: A pytorch model
  :type model: torch.model
  :param explain_layer: The layer that needs to be explained. Defaults to the last layer
  :type explain_layer: int
  :param device: A pytorch device
  :type device: torch.device
  :param Phi: A function whose input is x (element in the first parameter) and returns a hidden
  state (of type ``torch.FloatTensor``, of any shape
  :type Phi: function
  :return: The regularization term calculated
  :rtype: torch.FloatTensor
docstr_tok: ["Calculate","the","variance","of","the","state","generated","from","the","perturbed","inputs","that","is","used","for","Interpreter",":","param","sampled_x",":","A","list","of","sampled","input","embeddings","$","x","$",",","each","$","x","$","is","of","shape","``","[","length",",","dimension","]","``",".","All","the","$","x","$","s","can","have","different","length",",","but","should","have","the","same","dimension",".","Sampled","number","should","be","higher","to","get","a","good","estimation",".",":","type","sampled_x",":","list","[","torch.Tensor","]",":","param","reduced_axes",":","The","axes","that","is","variable","in","Phi","(","e.g.",",","the","sentence","length","axis",")",".","We","will","reduce","these","axes","by","mean","along","them",".",":","type","reduced_axes",":","list","[","int","]",":","param","model",":","A","pytorch","model",":","type","model",":","torch.model",":","param","explain_layer",":","The","layer","that","needs","to","be","explained",".","Defaults","to","the","last","layer",":","type","explain_layer",":","int",":","param","device",":","A","pytorch","device",":","type","device",":","torch.device",":","param","Phi",":","A","function","whose","input","is","x","(","element","in","the","first","parameter",")","and","returns","a","hidden","state","(","of","type","``","torch.FloatTensor","``",",","of","any","shape",":","type","Phi",":","function",":","return",":","The","regularization","term","calculated",":","rtype",":","torch.FloatTensor"]
code: def _calculate_regularization(
      self, sampled_x, model, reduced_axes=None
  ):
      """Calculate the variance of the state generated from the perturbed inputs that is used for Interpreter
      :param sampled_x: A list of sampled input embeddings $x$, each $x$ is of shape ``[length, dimension]``.
      All the $x$s can have different length, but should have the same dimension. Sampled number should be higher
      to get a good estimation.
      :type sampled_x: list[torch.Tensor]
      :param reduced_axes: The axes that is variable in Phi (e.g., the sentence length axis). We will reduce
      these axes by mean along them.
      :type reduced_axes: list[int]
      :param model: A pytorch model
      :type model: torch.model
      :param explain_layer: The layer that needs to be explained. Defaults to the last layer
      :type explain_layer: int
      :param device: A pytorch device
      :type device: torch.device
      :param Phi: A function whose input is x (element in the first parameter) and returns a hidden
      state (of type ``torch.FloatTensor``, of any shape
      :type Phi: function
      :return: The regularization term calculated
      :rtype: torch.FloatTensor
      """
      sample_num = len(sampled_x)
      sample_s = []
      self.Phi = self._generate_Phi(layer=self.target_layer)
      for n in range(sample_num):
          x = sampled_x[n]
          if self.device is not None:
              x = x.to(self.device)
  
          s = self.Phi(x)
          if reduced_axes is not None:
              for axis in reduced_axes:
                  assert axis < len(s.shape)
                  s = s.mean(dim=axis, keepdim=True)
          sample_s.append(s.tolist())
      sample_s = np.array(sample_s)
      return np.std(sample_s, axis=0)
  
imports: import torch
  from torch import nn, optim
  from tqdm import tqdm
  import numpy
  import random
  import html
  import matplotlib.pyplot
  from IPython.core.display import display, HTML
  from interpret_text.experimental.common.base_explainer import _validate_X
  from interpret_text.experimental.common.structured_model_mixin import PureStructuredModelMixin
  from interpret_text.experimental.explanation import _create_local_explanation
  from interpret_text.experimental.common.utils_unified import _get_single_embedding, make_bert_embeddings
label_desc: Use image node_id 3 for calling the UnifiedInformationExplainer obj's underlying member method code with example usage: obj._calculate_regularization(sampled_x, model, reduced_axes) and returns: np