Code Monkey home page Code Monkey logo

nlp_adversarial_examples's Introduction

  1. Download the Imdb dataset
./download_dataset.sh
  1. Download the glove vector embeddings (used by the model)
 ./download_glove.sh 
  1. Download the counter-fitted vectors (used by our attack)
./download_counterfitted_vectors.sh 
  1. Build the vocabulary and embeddings matrix.
python build_embeddings.py

That will take like a minute, and it will tokenize the dataset and save it to a pickle file. It will also compute some auxiliary files like the matrix of the vector embeddings for words in our dictionary. All files will be saved under aux_files directory created by this script.

  1. Train the sentiment analysis model.
python train_model.py

6)Download the Google language model.

./download_googlm.sh
  1. Pre-compute the distances between embeddings of different words (required to do the attack) and save the distance matrix.
python compute_dist_mat.py 

  1. Now, we are ready to try some attacks ! You can do so by running the IMDB_AttackDemo.ipynb Jupyter notebook !

Attacking Textual Entailment model

The model we are using for our experiment is the SNLI model of Keras SNLI Model .

First, Download the dataset using

bash download_snli_data.sh

Download the Glove and Counter-fitted Glove embedding vectors

bash ./download_glove.sh
bash ./download_counterfitted_vectors.sh

Train the NLI model

python sni_rnn.py

Pre-compute the embedding matrix

python nli_compute_dist_matrix.py

Now, you are ready to run the attack using example code provided in NLI_AttackDemo.ipynb Jupyter notebook.

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.