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: Evaluates a Causal/Masked LM model and returns logits corresponding to next word/masked word.
  
  Parameters
  ----------
  X: numpy.ndarray
      An array containing a list of masked inputs.
  
  Returns
  -------
  numpy.ndarray
      Logits corresponding to next word/masked word.
docstr_tok: ["Evaluates","a","Causal\/Masked","LM","model","and","returns","logits","corresponding","to","next","word\/masked","word",".","Parameters","--","--","--","--","--","X",":","numpy.ndarray","An","array","containing","a","list","of","masked","inputs",".","Returns","--","--","--","-","numpy.ndarray","Logits","corresponding","to","next","word\/masked","word","."]
code: def get_lm_logits(self, X):
      """Evaluates a Causal/Masked LM model and returns logits corresponding to next word/masked word.
  
      Parameters
      ----------
      X: numpy.ndarray
          An array containing a list of masked inputs.
  
      Returns
      -------
      numpy.ndarray
          Logits corresponding to next word/masked word.
      """
      if safe_isinstance(self.inner_model, MODELS_FOR_CAUSAL_LM):
          inputs = self.get_inputs(X, padding_side="left")
          if self.model_type == "pt":
              import torch
  
              inputs["position_ids"] = (
                  inputs["attention_mask"].long().cumsum(-1) - 1
              )
              inputs["position_ids"].masked_fill_(
                  inputs["attention_mask"] == 0, 0
              )
              inputs = inputs.to(self.device)
              # generate outputs and logits
              with torch.no_grad():
                  outputs = self.inner_model(**inputs, return_dict=True)
              # extract only logits corresponding to target sentence ids
              logits = (
                  outputs.logits.detach()
                  .cpu()
                  .numpy()
                  .astype("float64")[:, -1, :]
              )
          elif self.model_type == "tf":
              import tensorflow as tf
  
              inputs["position_ids"] = (
                  tf.math.cumsum(inputs["attention_mask"], axis=-1) - 1
              )
              inputs["position_ids"] = tf.where(
                  inputs["attention_mask"] == 0,
                  0,
                  inputs["position_ids"],
              )
              if self.device is None:
                  outputs = self.inner_model(inputs, return_dict=True)
              else:
                  try:
                      with tf.device(self.device):
                          outputs = self.inner_model(
                              inputs, return_dict=True
                          )
                  except RuntimeError as err:
                      print(err)
              logits = outputs.logits.numpy().astype("float64")[
                  :, -1, :
              ]
      return logits
  
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 8 for calling the TopKLM obj's underlying member method code with example usage: obj.get_lm_logits(X) and returns: logits