class_docstr: A constraint representing a maximum allowed perturbed words.
  
  Args:
      max_num_words (:obj:`int`, optional): Maximum number of perturbed words allowed.
      max_percent (:obj: `float`, optional): Maximum percentage of words allowed to be perturbed.
      compare_against_original (bool):  If `True`, compare new `x_adv` against the original `x`.
          Otherwise, compare it against the previous `x_adv`.
class_docstr_tok: ["A","constraint","representing","a","maximum","allowed","perturbed","words",".","Args",":","max_num_words","(",":","obj",":","`","int","`",",","optional",")",":","Maximum","number","of","perturbed","words","allowed",".","max_percent","(",":","obj",":","`","float","`",",","optional",")",":","Maximum","percentage","of","words","allowed","to","be","perturbed",".","compare_against_original","(","bool",")",":","If","`","True","`",",","compare","new","`","x_adv","`","against","the","original","`","x","`",".","Otherwise",",","compare","it","against","the","previous","`","x_adv","`","."]
code: def __init__(
      self,
      max_num_words=None,
      max_percent=None,
      compare_against_original=True,
  ):
      super().__init__(compare_against_original)
      if not compare_against_original:
          raise ValueError(
              "Cannot apply constraint MaxWordsPerturbed with `compare_against_original=False`"
          )
  
      if (max_num_words is None) and (max_percent is None):
          raise ValueError(
              "must set either `max_percent` or `max_num_words`"
          )
      if max_percent and not (0 <= max_percent <= 1):
          raise ValueError("max perc must be between 0 and 1")
      self.max_num_words = max_num_words
      self.max_percent = max_percent
  
imports: import math
  from textattack.constraints import Constraint
label_desc: Use image node_id 1 to create a new MaxWordsPerturbed object from inherited base classes: Constraint with example: obj = MaxWordsPerturbed(max_num_words, max_percent, compare_against_original)