class_docstr: Constraints word swaps to only swap words with the same part of speech.
  Uses the NLTK universal part-of-speech tagger by default. An implementation
  of `<https://arxiv.org/abs/1907.11932>`_ adapted from
  `<https://github.com/jind11/TextFooler>`_.
  
  POS taggers from Flair `<https://github.com/flairNLP/flair>`_ and
  Stanza `<https://github.com/stanfordnlp/stanza>`_ are also available
  
  Args:
      tagger_type (str): Name of the tagger to use (available choices: "nltk", "flair", "stanza").
      tagset (str): tagset to use for POS tagging (e.g. "universal")
      allow_verb_noun_swap (bool): If `True`, allow verbs to be swapped with nouns and vice versa.
      compare_against_original (bool): If `True`, compare against the original text.
          Otherwise, compare against the most recent text.
      language_nltk: Language to be used for nltk POS-Tagger
          (available choices: "eng", "rus")
      language_stanza: Language to be used for stanza POS-Tagger
          (available choices: https://stanfordnlp.github.io/stanza/available_models.html)
class_docstr_tok: ["Constraints","word","swaps","to","only","swap","words","with","the","same","part","of","speech",".","Uses","the","NLTK","universal","part-of-speech","tagger","by","default",".","An","implementation","of","`","<","https",":","\/\/arxiv.org\/abs\/1907.11932",">","`","_","adapted","from","`","<","https",":","\/\/github.com\/jind11\/TextFooler",">","`","_",".","POS","taggers","from","Flair","`","<","https",":","\/\/github.com\/flairNLP\/flair",">","`","_","and","Stanza","`","<","https",":","\/\/github.com\/stanfordnlp\/stanza",">","`","_","are","also","available","Args",":","tagger_type","(","str",")",":","Name","of","the","tagger","to","use","(","available","choices",":","``","nltk","''",",","``","flair","''",",","``","stanza","''",")",".","tagset","(","str",")",":","tagset","to","use","for","POS","tagging","(","e.g",".","``","universal","''",")","allow_verb_noun_swap","(","bool",")",":","If","`","True","`",",","allow","verbs","to","be","swapped","with","nouns","and","vice","versa",".","compare_against_original","(","bool",")",":","If","`","True","`",",","compare","against","the","original","text",".","Otherwise",",","compare","against","the","most","recent","text",".","language_nltk",":","Language","to","be","used","for","nltk","POS-Tagger","(","available","choices",":","``","eng","''",",","``","rus","''",")","language_stanza",":","Language","to","be","used","for","stanza","POS-Tagger","(","available","choices",":","https",":","\/\/stanfordnlp.github.io\/stanza\/available_models.html",")"]
code: def __init__(
      self,
      tagger_type="nltk",
      tagset="universal",
      allow_verb_noun_swap=True,
      compare_against_original=True,
      language_nltk="eng",
      language_stanza="en",
  ):
      super().__init__(compare_against_original)
      self.tagger_type = tagger_type
      self.tagset = tagset
      self.allow_verb_noun_swap = allow_verb_noun_swap
      self.language_nltk = language_nltk
      self.language_stanza = language_stanza
  
      self._pos_tag_cache = lru.LRU(2**14)
      if tagger_type == "flair":
          if tagset == "universal":
              self._flair_pos_tagger = SequenceTagger.load("upos-fast")
          else:
              self._flair_pos_tagger = SequenceTagger.load("pos-fast")
  
      if tagger_type == "stanza":
          self._stanza_pos_tagger = stanza.Pipeline(
              lang=self.language_stanza,
              processors="tokenize, pos",
              tokenize_pretokenized=True,
          )
  
file_path: TextAttack/textattack/constraints/grammaticality/part_of_speech.py
imports: import flair
  from flair.data import Sentence
  from flair.models import SequenceTagger
  import lru
  import nltk
  import textattack
  from textattack.constraints import Constraint
  from textattack.shared.utils import LazyLoader, device
  from textattack.shared.validators import transformation_consists_of_word_swaps
label_desc: Use image node_id 1 to create a new PartOfSpeech object from inherited base classes: Constraint with example: obj = PartOfSpeech(tagger_type, tagset, allow_verb_noun_swap, compare_against_original, language_nltk, language_stanza)