class_docstr: Generates scores (log odds) for the top-k tokens for Causal/Masked LM.
      
class_docstr_tok: ["Generates","scores","(","log","odds",")","for","the","top-k","tokens","for","Causal\/Masked","LM","."]
docstr: Calculates log odds from logits.
  
  This function passes the logits through softmax and then computes log odds for the top-k token ids.
  
  Parameters
  ----------
  logits: numpy.ndarray
      An array of logits generated from the model.
  
  Returns
  -------
  numpy.ndarray
      Computes log odds for corresponding top-k token ids.
docstr_tok: ["Calculates","log","odds","from","logits",".","This","function","passes","the","logits","through","softmax","and","then","computes","log","odds","for","the","top-k","token","ids",".","Parameters","--","--","--","--","--","logits",":","numpy.ndarray","An","array","of","logits","generated","from","the","model",".","Returns","--","--","--","-","numpy.ndarray","Computes","log","odds","for","corresponding","top-k","token","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 top-k token ids.
  
      Parameters
      ----------
      logits: numpy.ndarray
          An array of logits generated from the model.
  
      Returns
      -------
      numpy.ndarray
          Computes log odds for corresponding top-k token ids.
      """
  
      # pass logits through softmax, get the token corresponding score and convert back to log odds (as one vs all)
      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_topk_token_ids = np.take(
          logodds, self.topk_token_ids, axis=-1
      )
      return logodds_for_topk_token_ids
  
file_path: shap/shap/models/_topk_lm.py
imports: import numpy
  import scipy.special
  from .._serializable import Deserializer, Serializer
  from ..utils import safe_isinstance
  from ..utils.transformers import MODELS_FOR_CAUSAL_LM, getattr_silent
  from ._model import Model
label_desc: Use image node_id 5 for calling the TopKLM obj's underlying member method code with example usage: obj.get_logodds(logits) and returns: logodds_for_topk_token_ids, logodds