class_docstr: Generates target sentence/ids using a base model.
  
  It generates target sentence/ids for a model (a pretrained transformer model or a function).
class_docstr_tok: ["Generates","target","sentence\/ids","using","a","base","model",".","It","generates","target","sentence\/ids","for","a","model","(","a","pretrained","transformer","model","or","a","function",")","."]
docstr: Create a text generator model from a pretrained transformer model or a function.
  
  For a pretrained transformer model, a tokenizer should be passed.
  
  Parameters
  ----------
  model: object or function
      A object of any pretrained transformer model or function for which target sentence/ids are to be generated.
  
  tokenizer: object
      A tokenizer object(PreTrainedTokenizer/PreTrainedTokenizerFast) which is used to tokenize sentence.
  
  target_sentences: list
      A target sentence for every explanation row.
  
  device: str
      By default, it infers if system has a gpu and accordingly sets device. Should be 'cpu' or 'cuda' or pytorch models.
  
  Returns
  -------
  numpy.ndarray
      Array of target sentence/ids.
docstr_tok: ["Create","a","text","generator","model","from","a","pretrained","transformer","model","or","a","function",".","For","a","pretrained","transformer","model",",","a","tokenizer","should","be","passed",".","Parameters","--","--","--","--","--","model",":","object","or","function","A","object","of","any","pretrained","transformer","model","or","function","for","which","target","sentence\/ids","are","to","be","generated",".","tokenizer",":","object","A","tokenizer","object","(","PreTrainedTokenizer\/PreTrainedTokenizerFast",")","which","is","used","to","tokenize","sentence",".","target_sentences",":","list","A","target","sentence","for","every","explanation","row",".","device",":","str","By","default",",","it","infers","if","system","has","a","gpu","and","accordingly","sets","device",".","Should","be","'cpu","'","or","'cuda","'","or","pytorch","models",".","Returns","--","--","--","-","numpy.ndarray","Array","of","target","sentence\/ids","."]
code: def __init__(
      self,
      model=None,
      tokenizer=None,
      target_sentences=None,
      device=None,
  ):
      """Create a text generator model from a pretrained transformer model or a function.
  
      For a pretrained transformer model, a tokenizer should be passed.
  
      Parameters
      ----------
      model: object or function
          A object of any pretrained transformer model or function for which target sentence/ids are to be generated.
  
      tokenizer: object
          A tokenizer object(PreTrainedTokenizer/PreTrainedTokenizerFast) which is used to tokenize sentence.
  
      target_sentences: list
          A target sentence for every explanation row.
  
      device: str
          By default, it infers if system has a gpu and accordingly sets device. Should be 'cpu' or 'cuda' or pytorch models.
  
      Returns
      -------
      numpy.ndarray
          Array of target sentence/ids.
      """
      super().__init__(model)
  
      self.explanation_row = 0
      if target_sentences is not None:
          self.inner_model = lambda _: np.array(
              [target_sentences[self.explanation_row]]
          )
  
      self.tokenizer = tokenizer
      self.device = device
      if self.device is None:
          self.device = getattr(self.inner_model, "device", None)
      if safe_isinstance(model, "transformers.PreTrainedModel"):
          self.model_agnostic = False
          self.model_type = "pt"
      elif safe_isinstance(model, "transformers.TFPreTrainedModel"):
          self.model_agnostic = False
          self.model_type = "tf"
      else:
          self.model_agnostic = True
          self.model_type = None
      # X is input used to generate target sentence used for caching
      self.X = None
      # target sentence/ids generated from the model using X
      self.target_X = None
  
file_path: shap/shap/models/_text_generation.py
imports: import numpy
  from .._serializable import Deserializer, Serializer
  from ..utils import safe_isinstance
  from ._model import Model
label_desc: Use image node_id 1 to create a new TextGeneration object from inherited base classes: Model with example: obj = TextGeneration(model, tokenizer, target_sentences, device)