GithubHelp home page GithubHelp logo

explain-preds's Introduction

Explain-preds

Code repo of the final LFD paper

Setup

Installing the requirements

conda create -n lfdenvg8 python=3.9
conda activate lfdenvg8
pip install -r requirements.txt

Weights

The best performing T5-explanation prompt-3 model can be downloaded from here. Follow the instructions in this readme below to run the saved model for evaluation and prediction.

Structure

  • Discriminatory models are present inside "baselines/" folder

  • Generative models (our approach) are present in "t5-scripts/" folder

├── data
├── baselines
│   ├── neural
│   │   ├── **bert/**
│   │   ├── **lstm/**
│   │   └── utils.py
│   └── **svm**
└── t5-scripts
    ├── common_utils.py
    ├── **explain-w-t5/**
    └── **t5-wo-explanation/**
    ├── lexicon_words
    │   └── final_offensive_lexicon.txt
├── LICENSE
├── README.md
├── requirements.txt

Running baselines

  1. Navigate to "baselines/" folder for running them. The README.md inside it will guide on how to train/evaluate/predict.

Running T5 experiments (with explanations)

  1. For running the model with explanations, navigate to

cd t5-scripts/explain-w-t5/

  1. Selecting a template: This folder contains multiple templatefile_{1,2,3,4,6}.py template files. Decide which template you want to try out. Currently, we use the template (template 3) that gave us good results (table in the end). If you want to try other templates, update specific_utils.py with the filename you want while importing TemplateHandler from templatefile_{1,2,3,4,6}.py. For example, change the following in specific_utils.py for template-1.

    From

    from templatefile_3 import TemplateHandler

    to

    from templatefile_1 import TemplateHandler

  2. Run the training script

python train.py --train_file ../../data/train.tsv --dev_file ../../data/dev.tsv --learning_rate 1e-4 --batch_size 8 --num_epochs 5 --max_seq_len 150 --langmodel_name t5-base --offensive_lexicon ../lexicon_words/final_offensive_lexicon.txt --ckpt_folder ./t5explain-files/ --seed 1234 --device cpu
  1. The best model will be stored in t5explain-files/best-model.ckpt

  2. Evaluating the model on the test file

python evaluate.py --test_file ../../data/test.tsv --best_modelname t5explain-files/bestmodel.ckpt --offensive_lexicon ../lexicon_words/final_offensive_lexicon.txt --batch_size 16 --device cpu
  1. Getting the predictions into a file
python predict.py --test_file ../../data/test.tsv --best_modelname t5explain-files/bestmodel.ckpt --offensive_lexicon ../lexicon_words/final_offensive_lexicon.txt --batch_size 16 --device cpu --output_predfile preds.txt

T5-explanation-model-performance-on-different-prompts

Prompt Macro-F1
prompt-1

the model observed classified offensive since the following words showed up

the model observed classified not offensive
78.93 +_ 0.9
prompt-2

we had several words that rendered this offensive they were

we had no words that rendered this offensive, they are non-existent!
79.64 +_ 0.45
prompt-3

which words made us decide this is offensive, you ask? here you go:

which words made us decide this is not offensive, you ask?
78.53 +_ 0.465
prompt-4

the provided sentence may be interpreted as offensive by some users as certain offensive words occur such as

the provided sentence may not be found offensive by most users.
79.51 +_ 0.6

explain-preds's People

Contributors

gitlost-murali avatar gitlost-murali-askui avatar

Watchers

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