Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ChecklistAugmenter AssertionError #638

Closed
Cerebrock opened this issue May 4, 2022 · 4 comments · Fixed by #644
Closed

ChecklistAugmenter AssertionError #638

Cerebrock opened this issue May 4, 2022 · 4 comments · Fixed by #644
Labels
bug Something isn't working dependency issue

Comments

@Cerebrock
Copy link

Describe the bug
ChecklistAugmenter is bugged, error is
``AssertionError: Unexpected type of parameter 'use_tokenizer'. Parameter should be bool or Tokenizer```

To Reproduce
Run Augmentation example notebook:
https://colab.research.google.com/github/QData/TextAttack/blob/master/docs/2notebook/3_Augmentations.ipynb

@jpilaul
Copy link

jpilaul commented May 10, 2022

I get the same error with CLAREAugmenter

@jpilaul
Copy link

jpilaul commented May 10, 2022

I've changed the init params of Sentence in attacked_text.py
From:

sentence = Sentence(
    self.text, use_tokenizer=textattack.shared.utils.words_from_text
)

To:

sentence = Sentence(
    textattack.shared.utils.words_from_text(self.text), use_tokenizer=False
)

And it works like a charm

@VijayKalmath
Copy link
Contributor

From PR #293-(Oct 6, 2020) , we send the function textattack.shared.utils.words_from_text for use_tokenizer in the pos_of_word_index function.

def pos_of_word_index(self, desired_word_idx):
    """Returns the part-of-speech of the word at index `word_idx`.
    Uses FLAIR part-of-speech tagger.
    """
    if not self._pos_tags:
        sentence = Sentence(
            self.text, use_tokenizer=textattack.shared.utils.words_from_text   <<< Function sent as Callable function.
        )
        textattack.shared.utils.flair_tag(sentence)
        self._pos_tags = sentence
    flair_word_list, flair_pos_list = textattack.shared.utils.zip_flair_result(
        self._pos_tags
    )

And as of PR "Major refactoring of internal label logic #2645" in the flairNLP Repo (Feb 11, 2022) in "https://github.com/flairNLP/flair/blob/master/flair/data.py" - Flair does not allow callable functions as input for the Sentence Class.

To follow Flair's implementation and fix the errors seen in Issues #642 and #638, we should revert PR "have flair use textattack tokenization method #293".

I can go ahead and submit a PR to revert PR #293 if it makes overall sense.

@Jebrankhan
Copy link

Can you please revert #293 if there is no other way to resolve #642 and #638?

VijayKalmath added a commit to VijayKalmath/TextAttack that referenced this issue May 25, 2022
With the recent update in the Flair Package, the Sentence Class no
longer accepts a Callable function as the tokenization method.

Adding a TokenizerWrapper to textattack.shared.utils.words_from_text
is more suitable to retain funcionality instead of having to revert
"PR have flair use textattack tokenization method QData#293"

Flair also no longer supports get_tag attribute for token ,
updated strings.py function to follow new Flair requirements.

Fixes QData#642
Fixes QData#638
@jxmorris12 jxmorris12 added bug Something isn't working dependency issue labels May 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working dependency issue
Projects
None yet
5 participants