docstr: Generates the perturbed versions of the prompt.
  prompt: Prompt to perturb.
  n_samples: How many perturbations to generate in one run
  ng: The size of the ngrams, ng=4 means operating over 4-grams.
  max_chunks: Maximum number of chunks to perturb in a single perturbation round.
  batch_size: Batch size of the perturbation runs.
  
  Returns: Perturbed texts and the indices of perturbed n-grams.
docstr_tok: ["Generates","the","perturbed","versions","of","the","prompt",".","prompt",":","Prompt","to","perturb",".","n_samples",":","How","many","perturbations","to","generate","in","one","run","ng",":","The","size","of","the","ngrams",",","ng=4","means","operating","over","4-grams",".","max_chunks",":","Maximum","number","of","chunks","to","perturb","in","a","single","perturbation","round",".","batch_size",":","Batch","size","of","the","perturbation","runs",".","Returns",":","Perturbed","texts","and","the","indices","of","perturbed","n-grams","."]
code: def generate_k_perturbed(
      self,
      prompt,
      n_samples=100,
      ng=5,
      max_chunks=5,
      batch_size=16,
      progress_bar=None,
      accelerator=None,
  ):
      """
      Generates the perturbed versions of the prompt.
      prompt: Prompt to perturb.
      n_samples: How many perturbations to generate in one run
      ng: The size of the ngrams, ng=4 means operating over 4-grams.
      max_chunks: Maximum number of chunks to perturb in a single perturbation round.
      batch_size: Batch size of the perturbation runs.
  
      Returns: Perturbed texts and the indices of perturbed n-grams.
      """
      sample_k = np.random.randint(1, max_chunks + 1, size=n_samples)
      indices = []
      masked_texts = []
      for k in sample_k:
          mt, ng_idx = self.tokenize_and_mask(prompt, ng=ng, sample_k=k)
          # If consecutive ones are sampled, combine them into a single one.
          masked_texts.append(mt)
          indices.append(list(sorted(ng_idx)))
      raw_fills = self.replace_masks(
          masked_texts,
          batch_size=batch_size,
          progress_bar=progress_bar,
          device=accelerator.device,
      )
      extracted_id_to_fills = self.extract_fills(raw_fills)
      perturbed_texts = self.apply_extracted_fills(
          masked_texts, extracted_id_to_fills
      )
      return perturbed_texts, indices
  
imports: import numpy
  from abc import ABC, abstractmethod
  from .text_utils import extract_non_overlapping_ngrams
label_desc: Use image node_id 8 for calling the PerturbationModel obj's underlying member method code with example usage: obj.generate_k_perturbed(prompt, n_samples, ng, max_chunks, batch_size, progress_bar, accelerator) and returns: perturbed_texts,  indices