Giter Club home page Giter Club logo

adversarial_stance_detection's Introduction

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

adversarial_stance_detection's People

Contributors

ghazaleh-mahmoodi avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 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.