class_docstr: Generates scores (log odds) for output text explanation algorithms using Teacher Forcing technique.
  
  This class supports generation of log odds for transformer models as well as functions. In model agnostic
  cases (model is function) it expects a similarity_model and similarity_tokenizer to approximate log odd scores
  for target sentence generated by the model.
class_docstr_tok: ["Generates","scores","(","log","odds",")","for","output","text","explanation","algorithms","using","Teacher","Forcing","technique",".","This","class","supports","generation","of","log","odds","for","transformer","models","as","well","as","functions",".","In","model","agnostic","cases","(","model","is","function",")","it","expects","a","similarity_model","and","similarity_tokenizer","to","approximate","log","odd","scores","for","target","sentence","generated","by","the","model","."]
docstr: The function generates logits for transformer models.
  
  It generates logits for encoder-decoder models as well as decoder only models by using the teacher forcing technique.
  
  Parameters
  ----------
  X: numpy.ndarray
      An array containing a list of masked inputs.
  
  Y: numpy.ndarray
      An array containing a list of target sentence/ids.
  
  Returns
  -------
  numpy.ndarray
      Decoder output logits for output(target sentence) ids.
docstr_tok: ["The","function","generates","logits","for","transformer","models",".","It","generates","logits","for","encoder-decoder","models","as","well","as","decoder","only","models","by","using","the","teacher","forcing","technique",".","Parameters","--","--","--","--","--","X",":","numpy.ndarray","An","array","containing","a","list","of","masked","inputs",".","Y",":","numpy.ndarray","An","array","containing","a","list","of","target","sentence\/ids",".","Returns","--","--","--","-","numpy.ndarray","Decoder","output","logits","for","output","(","target","sentence",")","ids","."]
code: def get_teacher_forced_logits(self, X, Y):
      """The function generates logits for transformer models.
  
      It generates logits for encoder-decoder models as well as decoder only models by using the teacher forcing technique.
  
      Parameters
      ----------
      X: numpy.ndarray
          An array containing a list of masked inputs.
  
      Y: numpy.ndarray
          An array containing a list of target sentence/ids.
  
      Returns
      -------
      numpy.ndarray
          Decoder output logits for output(target sentence) ids.
      """
      # check if type of model architecture assigned in model config
      if (
          hasattr(self.similarity_model.config, "is_encoder_decoder")
          and not self.similarity_model.config.is_encoder_decoder
      ) and (
          hasattr(self.similarity_model.config, "is_decoder")
          and not self.similarity_model.config.is_decoder
      ):
          pass  # self.similarity_model.config.is_decoder = True # TODOmaybe: is this okay?
          # raise ValueError(
          #     "Please assign either of is_encoder_decoder or is_decoder to True in model config for extracting target sentence ids"
          # )
      # get output ids for teacher forcing
      output_ids = self.get_outputs(Y)
      if self.similarity_model.config.is_encoder_decoder:
          # encode batched inputs by padding on the right side
          inputs = self.get_inputs(X, padding_side="right")
          # assigning decoder start token id as it is needed for encoder decoder model generation
          decoder_start_token_id = None
          if (
              hasattr(
                  self.similarity_model.config, "decoder_start_token_id"
              )
              and self.similarity_model.config.decoder_start_token_id
              is not None
          ):
              decoder_start_token_id = (
                  self.similarity_model.config.decoder_start_token_id
              )
          elif (
              hasattr(self.similarity_model.config, "bos_token_id")
              and self.similarity_model.config.bos_token_id is not None
          ):
              decoder_start_token_id = (
                  self.similarity_model.config.bos_token_id
              )
          elif (
              hasattr(self.similarity_model.config, "decoder")
              and hasattr(
                  self.similarity_model.config.decoder, "bos_token_id"
              )
              and self.similarity_model.config.decoder.bos_token_id
              is not None
          ):
              decoder_start_token_id = (
                  self.similarity_model.config.decoder.bos_token_id
              )
          else:
              raise ValueError(
                  "No decoder_start_token_id or bos_token_id defined in config for encoder-decoder generation"
              )
          # concat decoder start token id to target sentence ids
          output_start_id = (
              np.ones((output_ids.shape[0], 1)) * decoder_start_token_id
          )
          output_ids = np.concatenate(
              (output_start_id, output_ids), axis=-1
          )
          # generate outputs and logits
          logits = self.model_inference(inputs, output_ids)
          logits = logits[:, :-1, :]
      else:
          # encode batched inputs by padding on the left side
          inputs = self.get_inputs(X, padding_side="left")
          # generate outputs and logits
          logits = self.model_inference(inputs, output_ids)
          # extract only logits corresponding to target sentence ids
          logits = logits[:, -output_ids.shape[1] - 1 : -1, :]
      return logits
  
file_path: shap/shap/models/_teacher_forcing.py
imports: import numpy
  import scipy.special
  from ..None import models
  from .._serializable import Deserializer, Serializer
  from ..utils import safe_isinstance
  from ..utils.transformers import getattr_silent, parse_prefix_suffix_for_tokenizer
  from ._model import Model
label_desc: Use image node_id 9 for calling the TeacherForcing obj's underlying member method code with example usage: obj.get_teacher_forced_logits(X, Y) and returns: logits