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: Calculates log odds from logits.
  
  This function passes the logits through softmax and then computes log odds for the output(target sentence) ids.
  
  Parameters
  ----------
  logits: numpy.ndarray
      An array of logits generated from the model.
  
  Returns
  -------
  numpy.ndarray
      Computes log odds for corresponding output ids.
docstr_tok: ["Calculates","log","odds","from","logits",".","This","function","passes","the","logits","through","softmax","and","then","computes","log","odds","for","the","output","(","target","sentence",")","ids",".","Parameters","--","--","--","--","--","logits",":","numpy.ndarray","An","array","of","logits","generated","from","the","model",".","Returns","--","--","--","-","numpy.ndarray","Computes","log","odds","for","corresponding","output","ids","."]
code: def get_logodds(self, logits):
      """Calculates log odds from logits.
  
      This function passes the logits through softmax and then computes log odds for the output(target sentence) ids.
  
      Parameters
      ----------
      logits: numpy.ndarray
          An array of logits generated from the model.
  
      Returns
      -------
      numpy.ndarray
          Computes log odds for corresponding output ids.
      """
      # set output ids for which scores are to be extracted
      if self.output.dtype.type is np.str_:
          output_ids = self.get_outputs(self.output)[0]
      else:
          output_ids = self.output[0]
  
      def calc_logodds(arr):
          probs = np.exp(arr) / np.exp(arr).sum(-1)
          logodds = scipy.special.logit(probs)
          return logodds
  
      # pass logits through softmax, get the token corresponding score and convert back to log odds (as one vs all)
      logodds = np.apply_along_axis(calc_logodds, -1, logits)
      logodds_for_output_ids = logodds[
          :, np.array(range(logodds.shape[1])), output_ids
      ]
      return logodds_for_output_ids
  
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 7 for calling the TeacherForcing obj's underlying member method code with example usage: obj.get_logodds(logits) and returns: logodds_for_output_ids, logodds