class_docstr: The UnifiedInformationExplainer for returning explanations for pytorch NN models.
      
class_docstr_tok: ["The","UnifiedInformationExplainer","for","returning","explanations","for","pytorch","NN","models","."]
docstr: Generate the Phi/hidden state that needs to be interpreted
  /Generates a function that returns the new hidden state given a new perturbed input is passed
  :param model: a pytorch model
  :type: torch.nn
  :param layer: the layer to generate Phi for
  :type layer: int
  :param total_layers: the total number of bert layers
  :return: The phi function
  :rtype: function
docstr_tok: ["Generate","the","Phi\/hidden","state","that","needs","to","be","interpreted","\/Generates","a","function","that","returns","the","new","hidden","state","given","a","new","perturbed","input","is","passed",":","param","model",":","a","pytorch","model",":","type",":","torch.nn",":","param","layer",":","the","layer","to","generate","Phi","for",":","type","layer",":","int",":","param","total_layers",":","the","total","number","of","bert","layers",":","return",":","The","phi","function",":","rtype",":","function"]
code: def _generate_Phi(self, layer):
      """Generate the Phi/hidden state that needs to be interpreted
      /Generates a function that returns the new hidden state given a new perturbed input is passed
      :param model: a pytorch model
      :type: torch.nn
      :param layer: the layer to generate Phi for
      :type layer: int
      :param total_layers: the total number of bert layers
      :return: The phi function
      :rtype: function
      """
  
      def Phi(x):
          x = x.unsqueeze(0)
          attention_mask = torch.ones(x.shape[:2]).to(x.device)
          extended_attention_mask = attention_mask.unsqueeze(
              1
          ).unsqueeze(2)
          extended_attention_mask = extended_attention_mask.to(
              dtype=torch.float
          )
          extended_attention_mask = (
              1.0 - extended_attention_mask
          ) * -10000.0
          hidden_states = x
          if layer == 14 or layer == 13:
              encoder = self.model.bert.encoder
              pooler = self.model.bert.pooler
              if layer == 13:
                  # explain pooler layer
                  return pooler(
                      encoder(hidden_states, attention_mask, False)[-1]
                  )[0]
              else:
                  # explain the classification layer
                  classifier = self.model.classifier
                  return classifier(
                      pooler(
                          encoder(hidden_states, attention_mask, False)[
                              -1
                          ]
                      )
                  )[0]
          else:
              # extract one of the bert layers
              model_list = self.model.bert.encoder.layer[:layer]
              for layer_module in model_list:
                  hidden_states = layer_module(
                      hidden_states, extended_attention_mask
                  )
              return hidden_states[0][layer]
  
      return Phi
  
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 7 for calling the UnifiedInformationExplainer obj's underlying member method code with example usage: obj._generate_Phi(layer) and returns: Phi, hidden_states, pooler, classifier