Coder Social home page Coder Social logo

textfool's Introduction

Plausible looking adversarial examples for text classification

DOI

This is a proof of concept aiming at producing "imperceptible" adversarial examples 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

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 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

Citing notes

Please use Zenodo link 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.

textfool's People

Contributors

bogdan-kulynych avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.