Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bogdan-kulynych/textfool
Plausible looking adversarial examples for text classification
https://github.com/bogdan-kulynych/textfool
adversarial-machine-learning adversarial-samples deep-learning machine-learning
Last synced: 2 months ago
JSON representation
Plausible looking adversarial examples for text classification
- Host: GitHub
- URL: https://github.com/bogdan-kulynych/textfool
- Owner: bogdan-kulynych
- License: mit
- Created: 2017-05-01T00:42:02.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-12-16T12:57:11.000Z (about 6 years ago)
- Last Synced: 2024-08-03T01:17:21.723Z (6 months ago)
- Topics: adversarial-machine-learning, adversarial-samples, deep-learning, machine-learning
- Language: Python
- Homepage:
- Size: 85 KB
- Stars: 92
- Watchers: 7
- Forks: 32
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-production-machine-learning - TextFool - kulynych/textfool.svg?style=social) - plausible looking adversarial examples for text generation. (Adversarial Robustness Libraries)
- Awesome-AIML-Data-Ops - TextFool - kulynych/textfool.svg?style=social) - plausible looking adversarial examples for text generation. (Adversarial Robustness Libraries)
- awesome-production-machine-learning - TextFool - kulynych/textfool.svg?style=social) - plausible looking adversarial examples for text generation. (Adversarial Robustness)
README
# Plausible looking adversarial examples for text classification
**This repository is deprecated. Check out [trickster](https://github.com/spring-epfl/trickster) library and the "[Evading classifiers in discrete domains with provable optimality guarantees](https://arxiv.org/abs/1810.10939)" paper for an evolution and a more mature version of this approach to generating adversarial examples.**
[![DOI](https://zenodo.org/badge/89886473.svg)](https://zenodo.org/badge/latestdoi/89886473)
This is a proof of concept aiming at producing "imperceptible" [adversarial examples](https://blog.openai.com/adversarial-example-research/) for text classifiers.
For instance, this are some adversarial examples produced by this code for a classifier of a tweet author's gender based on the tweet's text:
![Examples of adversarial examples](images/examples.png)
## Setup
### System
You need Python 3, and all system dependencies possibly required by
* Keras
* NLTK
* SpaCy### Python
```
pip install -r requirements.txt
```### NLP Data
* SpaCy English language model:
```
python -m spacy download en
```
* NLTK datasets (a prompt will appear upon running `paraphrase.py`)## Model
To train using default parameters simply run
```
python run_training.py
```
By default will check for the CSV data set at `./data/twitter_gender_data.csv`, and save the model weights to `./data/model.dat`.Should attain about 66% accuracy on validation data set for gender recognition.
### Data
This model uses Kaggle [Twitter User Gender Classification](https://www.kaggle.com/crowdflower/twitter-user-gender-classification) data.## Demo
To run the adversarial crafting script:
```
python run_demo.py
```
Success rate for crafting the adversarial example should be about 17%.
By default the script will write the crafted examples into `./data/adversarial_texts.csv`.## Paraphrasing
This module is rather reusable, although not immensely useful for anything practical. It provides a function that "paraphrases" a text by replacing some words with their WordNet synonyms, sorting by GloVe similarity between the synonym and the original context window. Relies on SpaCy and NLTK.Example of paraphrase:
![Paraphrase example](images/paraphrase_example.png)
## Citing notes
Please use [Zenodo link](https://zenodo.org/record/831638) to cite _textfool_. Not that this work is not published, and not peer-reviewed. _textfool_ has no relationship to _"Deep Text Classification Can be Fooled."_ by B. Liang, H. Li, M. Su, P. Bian, X. Li, and W. Shi.