Skip to content

Latest commit

 

History

History
85 lines (63 loc) · 3.1 KB

README.md

File metadata and controls

85 lines (63 loc) · 3.1 KB

Adversarial Learning for Zero-Shot Stance Detection on Social Media

This repository contains the data and source code used in NAACL 2021 main conference paper Adversarial Learning for Zero-Shot Stance Detection on Social Media.

Requirements

python 3.7.6
transformers 3.4.0
pytorch 1.5.1
numpy 1.18.1
pandas 1.0.3
scipy 1.4.1

Instalation

Create an environment with dependencies specified in stance_local_env.yml (note that this can take some time):

    conda env create -f stance_local_env.yml

Activate the new environment:

    conda activate stance_env

To deactivate an active environment, use

    conda deactivate

Training TOAD

cd src/

Create folder data and within it create a folder named resources.

In data/resources, place pretrained GloVe word embeddings and topic dictionary (which maps topics in training data to indices).

Run

python train_and_eval_model.py --mode "train" --config_file <config_name> --trn_data <train_data> --dev_data <dev_data> --score_key <score_key> --topics_vocab <topic_dictionary> --mode train 

For example:

python train_and_eval_model.py --mode "train" --config_file data/config-0.txt --trn_data data/twitter_testDT_seenval/development_setup/train.csv --dev_data data/twitter_testDT_seenval/development_setup/validation.csv --score_key f_macro --topics_vocab twitter-topic-TRN-semi-sup.vocab.pkl --mode train 

Score key is evaluated on the development data and used for saving the best model across epochs.

Config file for TOAD should follow the format of our example TOAD config file - src/config_example_toad.txt

Evaluating a saved TOAD model

To evaluate a saved model on test_data, run

python train_and_eval_model.py --mode "eval" --config_file <config_name> --trn_data <train_data> --dev_data <test_data> --topics_vocab <topic_dictionary> --saved_model_file_name <saved_model_file_name> --mode eval 

For example:

python train_and_eval_model.py --mode "eval" --config_file data/config-0.txt --trn_data data/twitter_testDT_seenval/development_setup/train.csv --dev_data data/twitter_testDT_seenval/test_setup/test.csv --saved_model_file_name data/checkpoints/DT_checkpoint.tar --topics_vocab twitter-topic-TRN-semi-sup.vocab.pkl --mode eval 

Baseline models

BiCond

Run

python train_and_eval_model.py --mode "train" --config_file <config_name> --trn_data <train_data> --dev_data <dev_data> --score_key <score_key>

Config file should follow the format of our example BiCond config file - src/config_example_bicond.txt

BERT

Run

python train_and_eval_model.py --mode "train" --config_file <config_name> --trn_data <train_data> --dev_data <dev_data> --score_key <score_key>

Hyperparameter search for TOAD

Run

python hyperparam_selection.py -m 1 -s <config_file_for_hyperparam_tuning> -k <score_key>

Config file should follow the format of our example TOAD hyperparameter search config file - src/hyperparam-twitter-adv.txt