code: def __init__(self, model_name="gpt2"):
      self.all_metrics = {}
      self.original_candidates = []
      self.successful_candidates = []
  
      if model_name == "gpt2":
          from transformers import GPT2LMHeadModel, GPT2Tokenizer
  
          self.ppl_model = GPT2LMHeadModel.from_pretrained("gpt2")
          self.ppl_model.to(textattack.shared.utils.device)
          self.ppl_tokenizer = GPT2Tokenizer.from_pretrained("gpt2")
          self.ppl_model.eval()
          self.max_length = self.ppl_model.config.n_positions
      else:
          from transformers import AutoModelForMaskedLM, AutoTokenizer
  
          self.ppl_model = AutoModelForMaskedLM.from_pretrained(
              model_name
          )
          self.ppl_tokenizer = AutoTokenizer.from_pretrained(model_name)
          self.ppl_model.to(textattack.shared.utils.device)
          self.ppl_model.eval()
          self.max_length = (
              self.ppl_model.config.max_position_embeddings
          )
  
      self.stride = 512
  
file_path: TextAttack/textattack/metrics/quality_metrics/perplexity.py
imports: import torch
  from textattack.attack_results import FailedAttackResult, SkippedAttackResult
  from textattack.metrics import Metric
  import textattack.shared.utils
label_desc: Use image node_id 1 to create a new Perplexity object from inherited base classes: Metric with example: obj = Perplexity(model_name)