'TypeError: Invalid text_input type <class 'pandas.core.frame.DataFrame'> (required str or OrderedDict)

from textattack.augmentation import EasyDataAugmenter
eda=EasyDataAugmenter()
eda.augment(train)

Error on this code

The "train" data type is dataframe. and the extension is csv with 2 column (text and label).

I want to use EDA to augment the data.

I already import and install all the package it needs:

    textattack: Downloading https://textattack.s3.amazonaws.com/word_embeddings/paragramcf.
    100%|██████████| 481M/481M [00:21<00:00, 22.6MB/s]
    textattack: Unzipping file /root/.cache/textattack/tmp1g7u54ae.zip to /root/.cache/textattack/word_embeddings/paragramcf.
    textattack: Successfully saved word_embeddings/paragramcf to cache.
    ---------------------------------------------------------------------------
    TypeError                                 Traceback (most recent call last)
    <ipython-input-18-e7415cc200bf> in <module>()
          1 from textattack.augmentation import EasyDataAugmenter
          2 eda=EasyDataAugmenter()
    ----> 3 eda.augment(train)
    
    /usr/local/lib/python3.7/dist-packages/textattack/augmentation/recipes.py in augment(self, text)
     64     def augment(self, text):
     65         augmented_text = []
---> 66         augmented_text += self.synonym_replacement.augment(text)
     67         augmented_text += self.random_deletion.augment(text)
     68         augmented_text += self.random_swap.augment(text)

/usr/local/lib/python3.7/dist-packages/textattack/augmentation/augmenter.py in augment(self, text)
    111         """Returns all possible augmentations of ``text`` according to
    112         ``self.transformation``."""
--> 113         attacked_text = AttackedText(text)
    114         original_text = attacked_text
    115         all_transformed_texts = set()
    /usr/local/lib/python3.7/dist-packages/textattack/shared/attacked_text.py in __init__(self, text_input, attack_attrs)
         51         else:
         52             raise TypeError(
    ---> 53                 f"Invalid text_input type {type(text_input)} (required str or OrderedDict)"
         54             )
         55         # Process input lazily.
    
    TypeError: Invalid text_input type <class 'pandas.core.frame.DataFrame'> (required str or OrderedDict)


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source