class_docstr: Wrapper for a Huggingface Transformers GPT-2 model.
  
  This class loads a tokenizer and model using the Huggingface library and
  provides the LIT-required functions plus additional helper functions to
  convert and clean tokens and to compute the top_k predictions from logits.
class_docstr_tok: ["Wrapper","for","a","Huggingface","Transformers","GPT-2","model",".","This","class","loads","a","tokenizer","and","model","using","the","Huggingface","library","and","provides","the","LIT-required","functions","plus","additional","helper","functions","to","convert","and","clean","tokens","and","to","compute","the","top_k","predictions","from","logits","."]
docstr: Constructor for GPT2LanguageModel.
  
  Args:
    model_name_or_path: gpt2, gpt2-medium, gpt2-large, gpt2-xl, distilgpt2,
      etc.
    top_k: How many predictions to prune.
docstr_tok: ["Constructor","for","GPT2LanguageModel",".","Args",":","model_name_or_path",":","gpt2",",","gpt2-medium",",","gpt2-large",",","gpt2-xl",",","distilgpt2",",","etc",".","top_k",":","How","many","predictions","to","prune","."]
code: def __init__(self, model_name_or_path="gpt2", top_k=10):
      """Constructor for GPT2LanguageModel.
  
      Args:
        model_name_or_path: gpt2, gpt2-medium, gpt2-large, gpt2-xl, distilgpt2,
          etc.
        top_k: How many predictions to prune.
      """
      super().__init__()
  
      # Normally path is a directory; if it's an archive file, download and
      # extract to the transformers cache.
      if model_name_or_path.endswith(".tar.gz"):
          model_name_or_path = file_cache.cached_path(
              model_name_or_path, extract_compressed_file=True
          )
  
      self.tokenizer = transformers.AutoTokenizer.from_pretrained(
          model_name_or_path, use_fast=False
      )
      # Set this after init, as if pad_token= is passed to
      # AutoTokenizer.from_pretrained() above it will create a new token with
      # with id = max_vocab_length and cause out-of-bounds errors in
      # the embedding lookup.
      self.tokenizer.pad_token = self.tokenizer.eos_token
      self.model = transformers.TFGPT2LMHeadModel.from_pretrained(
          model_name_or_path,
          output_hidden_states=True,
          output_attentions=True,
      )
      self.top_k = top_k
  
imports: import re
  from lit_nlp.api import model
  from lit_nlp.api import types
  from lit_nlp.examples.models import model_utils
  from lit_nlp.lib import file_cache
  from lit_nlp.lib import utils
  import numpy
  import tensorflow
  import transformers
label_desc: Use image node_id 3 to create a new GPT2LanguageModel object from inherited base classes: lit_model with example: obj = GPT2LanguageModel(model_name_or_path, top_k)