Giter Club home page Giter Club logo

humans-contrastive-xai's Introduction

An Investigation of Contrastive Explanations: Comparing Model post-hoc Explanations with Human Gaze / Rationales

How to finetune a model?

MODEL_PATH='roberta-base'
DATASET_NAME='sst2' # 'dynabench/dynasent'
DATASET_CONFIG='sst2' # 'dynabench.dynasent.r1.all'
BATCH_SIZE=32
MAX_SEQ_LENGTH=64
export PYTHONPATH=.
export TOKENIZERS_PARALLELISM=false


# DELETE CACHED DATASET
rm -rf ../.cache/huggingface/datasets/${DATASET_NAME}

# TRAIN STANDARD CLASSIFIER
python train_models/finetune_model.py \
    --model_name_or_path ${MODEL_PATH} \
    --dataset_name ${DATASET_NAME} \
    --dataset_config ${DATASET_CONFIG} \
    --output_dir data/finetuned_models/${MODEL_PATH}-${DATASET_NAME} \
    --do_train \
    --do_eval \
    --do_pred \
    --overwrite_output_dir \
    --load_best_model_at_end \
    --metric_for_best_model accuracy \
    --greater_is_better true \
    --max_seq_length ${MAX_SEQ_LENGTH} \
    --evaluation_strategy epoch \
    --save_strategy epoch \
    --save_total_limit 2 \
    --learning_rate 3e-5 \
    --per_device_train_batch_size ${BATCH_SIZE} \
    --per_device_eval_batch_size ${BATCH_SIZE} \
    --seed 42 \
    --num_train_epochs 10 \
    --warmup_ratio 0.1 \
    --weight_decay 0.01 \
    --fp16 \
    --fp16_full_eval \
    --lr_scheduler_type cosine

Available Fine-tuned Models

Model Name Dataset
coastalcph/roberta-{small, base, large}-sst2 sst2
coastalcph/roberta-base-dynasent dynabench/dynasent
coastalcph/{gpt2, roberta, t5}-{small, base, large}-dbpedia-animals coastalcph/dbpedia-datasets
coastalcph/{gpt2, roberta, t5}-{small, base, large}-dbpedia-animals coastalcph/xai_fairness_benchmark

Explanations

How to explain a model's predictions?

MODEL='roberta-base'
DATASET='sst2' # 'dynabench/dynasent'
MODE = true #foil, contrastive
SPLIT = test #validation
XAI_METHOD = lrp #gi, lrp_norm

python ./xai/extract_lrp_relevance.py \  
    --modelname coastalcph/${MODEL}-${DATASET} \
    --dataset_name ${DATASET} \
    --case ${XAI_METHOD} \
    --mode ${MODE} \
    --dataset_split ${SPLIT}
    

How to run comparison across settings and humans/models?

python ./xai/xai_comparison.py \
    --source_path ./results/${MODEL}-${DATASET} \
    --xai_method ${XAI_METHOD} \
    --modelname ${MODEL}
    
python ./xai/compute_human_model_alignment.py \
    --modelname coastalcph/${MODEL}-${DATASET} \
    --dataset_name ${DATASET} \
    --model_type ${MODELTYPE} \
    --importance_aggregator ${AGGREGATOR} \
    --annotations_filename standard_biosbias_rationales \
    --results_dir ./results/${MODEL}-${DATASET}
  
python ./xai/compute_human_model_alignment.py \
    --modelname coastalcph/${MODEL}-${DATASET} \
    --dataset_name ${DATASET} \
    --model_type ${MODELTYPE} \
    --importance_aggregator ${AGGREGATOR} \
    --annotations_filename contrastive_biosbias_rationales \
    --results_dir ./results/${MODEL}-${DATASET}
  
python ./xai/compare_human_rationales_across_settings.py \
    --results_dir ./results/${MODEL}-${DATASET}

humans-contrastive-xai's People

Contributors

iliaschalkidis avatar lautel avatar oeberle avatar stephaniebrandl avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

techthiyanes

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.