class_docstr: Introspective rationale generator used in paper
      
class_docstr_tok: ["Introspective","rationale","generator","used","in","paper"]
docstr: Forward pass of the introspection generator module
  
  :param X_tokens: tokenized and embedded text with shape
      (batch_size, length, embed_dim)
  :type X_tokens: torch Variable
  :param mask: mask indicating word tokens (1) and padding (0)
      with shape (batch_size, length)
  :type mask: torch.FloatTensor
  :return: z_scores_ (scores of token importances),
  cls_pred_logits (internal classifier predictions),
  word_embeddings (embedded tokenized text input)
  :rtype: tuple()
docstr_tok: ["Forward","pass","of","the","introspection","generator","module",":","param","X_tokens",":","tokenized","and","embedded","text","with","shape","(","batch_size",",","length",",","embed_dim",")",":","type","X_tokens",":","torch","Variable",":","param","mask",":","mask","indicating","word","tokens","(","1",")","and","padding","(","0",")","with","shape","(","batch_size",",","length",")",":","type","mask",":","torch.FloatTensor",":","return",":","z_scores_","(","scores","of","token","importances",")",",","cls_pred_logits","(","internal","classifier","predictions",")",",","word_embeddings","(","embedded","tokenized","text","input",")",":","rtype",":","tuple","(",")"]
code: def forward(self, X_tokens, mask):
      """Forward pass of the introspection generator module
  
      :param X_tokens: tokenized and embedded text with shape
          (batch_size, length, embed_dim)
      :type X_tokens: torch Variable
      :param mask: mask indicating word tokens (1) and padding (0)
          with shape (batch_size, length)
      :type mask: torch.FloatTensor
      :return: z_scores_ (scores of token importances),
      cls_pred_logits (internal classifier predictions),
      word_embeddings (embedded tokenized text input)
      :rtype: tuple()
      """
      cls_pred_logits, hidden_states, _ = self.classifier(
          X_tokens, attention_mask=mask
      )
  
      # hidden states must be in shape (batch_size, hidden_dim, length)
      # RNN returns (batch_size, hidden_dim, length)
      # BERT returns (batch_size, length, hidden_dim)
      last_hidden_state = hidden_states[-1]
      if last_hidden_state.shape[1] != self.hidden_dim:
          last_hidden_state = hidden_states[-1].transpose(1, 2)
  
      # max_cls_hidden dimensions: (batch_size, hidden_dim)
      max_cls_hidden = torch.max(
          last_hidden_state + (1 - mask).unsqueeze(1) * self.NEG_INF,
          dim=2,
      )[0]
      if self.fixed_classifier:
          max_cls_hidden = Variable(max_cls_hidden.data)
  
      word_embeddings = hidden_states[0]
  
      _, cls_pred = torch.max(cls_pred_logits, dim=1)
  
      # classifier label embedding dimensions: (batch_size, lab_emb_dim)
      cls_lab_embeddings = self.lab_embed_layer(cls_pred)
  
      # initial h0 dimensions: (batch_size, hidden_dim / 2)
      init_h0 = self.Transformation(
          torch.cat([max_cls_hidden, cls_lab_embeddings], dim=1)
      )
      # initial h0 dimensions: (2, batch_size, hidden_dim / 2)
      init_h0 = (
          init_h0.unsqueeze(0)
          .expand(2, init_h0.size(0), init_h0.size(1))
          .contiguous()
      )
  
      # z_scores' dimensions: (batch_size, length, 2)
      z_scores_ = self.Generator(word_embeddings, mask=mask, h0=init_h0)
      z_scores_[:, :, 1] = (
          z_scores_[:, :, 1] + (1 - mask) * self.NEG_INF
      )
  
      return z_scores_, cls_pred_logits, word_embeddings
  
imports: import os
  import logging
  import numpy
  import torch
  import torch.nn
  from torch.autograd import Variable
  from tqdm import tqdm
  from interpret_text.experimental.common.utils_introspective_rationale import generate_data
label_desc: Use image node_id 3 for calling the IntrospectionGeneratorModule obj's underlying member method code with example usage: obj.forward(X_tokens, mask) and returns: z_scores_,  cls_pred_logits,  word_embeddings