Home

Awesome

Synonyms Encoding Method (SEM)

This repository contains necessary code for reproducing main results in the paper:

Natural Language Adversarial Attacks and Defenses in Word Level

We also add the code for IGA into the framework TextAttack.

Datesets

There are three datasets used in our experiments:

Requirements

The code was tested with:

File Description

Experiments

  1. Generating the embedding matrix for original dictionary and encoded dictionary:

    python build_embedding.py
    
  2. Training the models with the original word dictionary:

    python train_orig.py --data aclImdb --sn 10 --sigma 0.5 --nn_type textrnn
    
  3. Training the models with the encoded word dictionary:

    python train_enc.py --data aclImdb --sn 10 --sigma 0.5 --nn_type textrnn
    
  4. To attack the models by IGA, run:

    python improved_genetic.py --pre enc --sn 10 --data aclImdb --sigma 0.5 --time xxx --nn_type textrnn
    

Contact

This repository is under active development. Questions and suggestions can be sent to xswanghuster@gmail.com.