class_docstr: Language generation pipeline using any `ModelWithLMHead`. This pipeline predicts the words that will follow a
  specified text prompt.
  
  Example:
  
  ```python
  >>> from transformers import pipeline
  
  >>> generator = pipeline(model="gpt2")
  >>> generator("I can't believe you did such a ", do_sample=False)
  [{'generated_text': "I can't believe you did such a icky thing to me. I'm so sorry. I'm so sorry. I'm so sorry. I'm so sorry. I'm so sorry. I'm so sorry. I'm so sorry. I"}]
  
  >>> # These parameters will return suggestions, and only the newly created text making it easier for prompting suggestions.
  >>> outputs = generator("My tart needs some", num_return_sequences=4, return_full_text=False)
  ```
  
  Learn more about the basics of using a pipeline in the [pipeline tutorial](../pipeline_tutorial). You can pass text
  generation parameters to this pipeline to control stopping criteria, decoding strategy, and more. Learn more about
  text generation parameters in [Text generation strategies](../generation_strategies) and [Text
  generation](text_generation).
  
  This language generation pipeline can currently be loaded from [`pipeline`] using the following task identifier:
  `"text-generation"`.
  
  The models that this pipeline can use are models that have been trained with an autoregressive language modeling
  objective, which includes the uni-directional models in the library (e.g. gpt2). See the list of available models
  on [huggingface.co/models](https://huggingface.co/models?filter=text-generation).
class_docstr_tok: ["Language","generation","pipeline","using","any","`","ModelWithLMHead","`",".","This","pipeline","predicts","the","words","that","will","follow","a","specified","text","prompt",".","Example",":","``","`","python",">",">",">","from","transformers","import","pipeline",">",">",">","generator","=","pipeline","(","model=","''","gpt2","''",")",">",">",">","generator","(","``","I","ca","n't","believe","you","did","such","a","``",",","do_sample=False",")","[","{","'generated_text","'",":","``","I","ca","n't","believe","you","did","such","a","icky","thing","to","me",".","I","'m","so","sorry",".","I","'m","so","sorry",".","I","'m","so","sorry",".","I","'m","so","sorry",".","I","'m","so","sorry",".","I","'m","so","sorry",".","I","'m","so","sorry",".","I","''","}","]",">",">",">","#","These","parameters","will","return","suggestions",",","and","only","the","newly","created","text","making","it","easier","for","prompting","suggestions",".",">",">",">","outputs","=","generator","(","``","My","tart","needs","some","''",",","num_return_sequences=4",",","return_full_text=False",")","``","`","Learn","more","about","the","basics","of","using","a","pipeline","in","the","[","pipeline","tutorial","]","(","..","\/pipeline_tutorial",")",".","You","can","pass","text","generation","parameters","to","this","pipeline","to","control","stopping","criteria",",","decoding","strategy",",","and","more",".","Learn","more","about","text","generation","parameters","in","[","Text","generation","strategies","]","(","..","\/generation_strategies",")","and","[","Text","generation","]","(","text_generation",")",".","This","language","generation","pipeline","can","currently","be","loaded","from","[","`","pipeline","`","]","using","the","following","task","identifier",":","`","``","text-generation","''","`",".","The","models","that","this","pipeline","can","use","are","models","that","have","been","trained","with","an","autoregressive","language","modeling","objective",",","which","includes","the","uni-directional","models","in","the","library","(","e.g",".","gpt2",")",".","See","the","list","of","available","models","on","[","huggingface.co\/models","]","(","https",":","\/\/huggingface.co\/models","?","filter=text-generation",")","."]
code: def preprocess(
      self,
      prompt_text,
      prefix="",
      handle_long_generation=None,
      add_special_tokens=False,
      truncation=None,
      padding=False,
      max_length=None,
      **generate_kwargs,
  ):
      inputs = self.tokenizer(
          prefix + prompt_text,
          return_tensors=self.framework,
          truncation=truncation,
          padding=padding,
          max_length=max_length,
          add_special_tokens=add_special_tokens,
      )
      inputs["prompt_text"] = prompt_text
  
      if handle_long_generation == "hole":
          cur_len = inputs["input_ids"].shape[-1]
          if "max_new_tokens" in generate_kwargs:
              new_tokens = generate_kwargs["max_new_tokens"]
          else:
              new_tokens = (
                  generate_kwargs.get(
                      "max_length", self.model.config.max_length
                  )
                  - cur_len
              )
              if new_tokens < 0:
                  raise ValueError(
                      "We cannot infer how many new tokens are expected"
                  )
          if cur_len + new_tokens > self.tokenizer.model_max_length:
              keep_length = self.tokenizer.model_max_length - new_tokens
              if keep_length <= 0:
                  raise ValueError(
                      "We cannot use `hole` to handle this generation the number of desired tokens exceeds the"
                      " models max length"
                  )
  
              inputs["input_ids"] = inputs["input_ids"][
                  :, -keep_length:
              ]
              if "attention_mask" in inputs:
                  inputs["attention_mask"] = inputs["attention_mask"][
                      :, -keep_length:
                  ]
  
      return inputs
  
file_path: transformers/src/transformers/pipelines/text_generation.py
imports: import enum
  import warnings
  from ..utils import add_end_docstrings, is_tf_available, is_torch_available
  from .base import PIPELINE_INIT_ARGS, Pipeline
label_desc: Use image node_id 5 for calling the TextGenerationPipeline obj's underlying member method code with example usage: obj.preprocess(prompt_text, prefix, handle_long_generation, add_special_tokens, truncation, padding, max_length) and returns: inputs