Git Product home page Git Product logo

court-of-xai's Introduction

Court of XAI

Introduction

Code to reproduce the results reported in the paper: "A Song of (Dis)agreement: Evaluating the Evaluation of Explainable Artificial Intelligence in Natural Language Processing" (see song_of_disagreement/paper.pdf). Appendices can be found in song_of_disagreement/appendices.

This framework can be used to design and run additional experiments to calculate different correlation metrics between feature additive explanation methods. Currently, we assume you are interested in comparing at least one attention-based explanation method.

Setup

Installation

Prepare a Python virtual environment and install the necessary packages.

python3 -m venv v-xai-court
source v-xai-court/bin/activate
pip install --upgrade pip
pip install torch torchtext
pip install -r requirements.txt
python -m spacy download en

Datasets

Datasets are stored in the datasets/ folder. We include the IMDb and SST-2 datasets with the same splits and pre-processing steps as used in (Jain and Wallace 2019). To download the other datasets:

  • Quora
    • Our split (80/10/10), question pairs with combined word count greater than 200 were removed.
  • SNLI
  • MultiNLI
    • Get the test set from here and run scripts/extract_mnli_test_en.py

Reproducing our Paper

We have implemented a custom AllenNLP command to run our experiments. We define each experiment as consisting of four variables:

  • The dataset (IMDb, SST-2, Quora Question Pair, SNLI, MultiNLI)
  • The model (BiLSTM, DistilBERT)
  • The attention mechanism (additive (tanh), self-attention)
  • The attention activation function (softmax, uniform, etc...)

Thus the experiment files are named {dataset}_{model}_{attention_mechanism}_{activation_function}.jsonnet. Our experiments are located in the experiments/ folder.

Since we train three independently-seeded models PER experiment, it may take several days to run all of our experiments. A GPU with CUDA and 16GB of memory is strongly recommended.

To run an experiment simply call our custom command with the path to the experiment file. For example:

allennlp attn-experiment experiments/sst_distilbert_self_softmax.jsonnet

By default, the generated artifacts are available in the outputs directory. This includes the models, their configurations, and their metrics. When the experiments finish, a .csv summary of the correlation results in available in outputs/{experiment_file_name}/summary.csv. We used these summary files to generate our tables.

Running your own Experiment

Since our code uses AllenNLP, you can easily add a new Jsonnet experiment file to the experiments directory.

We currently support the following components (see the existing experiment files for examples on how to use them):

  • Tasks/Datasets
    • Single Sequence: Binary Sentiment Classification
      • IMDb Movie Reviews
      • Stanford Sentiment Treebank
    • Pair Sequence: Natural Language Inference
      • Quora Question Pairs
      • SNLI
      • MultiNLI
  • Models
    • BiLSTM with (tanh) additive attention
    • DistilBERT
  • Attention activation functions
  • Attention aggregation and analysis methods:
    • Average: for the Transformer, averages attention across layers, heads, and max pools across the last dimension of attention matrix
    • Attention Flow: for the Transformer
    • Attention Rollout: for the Transformer
    • Attention Norms: as an additional analysis method for any attention mechanism
  • Additive Feature Importance Methods (from Captum)
  • Correlation metrics
    • Kendall-tau
    • Top-k Kendall-tau. This is a custom implementation where k can be a fixed number of tokens, variable percentage, or non-zero attribution values.
    • Weighted Kendall-tau
    • Yilmaz tauAP where ties are allowed. Taken from Pyircor
    • Spearman-r
    • Pearson-rho

Citation

To cite our work, please cite: A Song of (Dis)agreement: Evaluating the Evaluation of Explainable Artificial Intelligence in Natural Language Processing.

@incollection{neely_song_2022,
	title = {A {Song} of ({Dis})agreement: {Evaluating} the {Evaluation} of {Explainable} {Artificial} {Intelligence} in {Natural} {Language} {Processing}},
	copyright = {All rights reserved},
	shorttitle = {A {Song} of ({Dis})agreement},
	url = {https://ebooks.iospress.nl/doi/10.3233/FAIA220190},
	booktitle = {{HHAI2022}: {Augmenting} {Human} {Intellect}},
	publisher = {IOS Press},
	author = {Neely, Michael and Schouten, Stefan F. and Bleeker, Maurits and Lucic, Ana},
	year = {2022},
	doi = {10.3233/FAIA220190},
	pages = {60--78},
}


Our results were also presented at the ICML Workshop on Theoretic Foundation, Criticism, and Application Trend of Explainable AI in our earlier paper Order in the Court: Explainable AI Methods Prone to Disagreement.

@inproceedings{neely2021order,
    title = "Order in the Court: Explainable AI Methods Prone to Disagreement",
    author = {Neely, Michael  and
      Schouten, Stefan F. and
      Bleeker, Maurits J. R. and
      Lucic, Ana},
    booktitle = "ICML 2021 Workshop on Theoretic Foundation, Criticism, and Application Trend of Explainable AI",
    month = jul,
    year = "2021",
    publisher = "International Conference on Machine Learning",
    url = "https://arxiv.org/abs/2105.03287",
    doi = "https://doi.org/10.48550/arXiv.2107.08821"
}

court-of-xai's People

Contributors

michaeljneely avatar sfschouten avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

court-of-xai's Issues

Add Machine Translation Task

Attention was originally proposed in the context of Machine Translation, so it makes since to include it in our list of tasks.

Components:

  • Select dataset
  • Add Recurrent seq2seq model
  • Add Transformer seq2seq model

Display progress of interpretation

Use Tqdm to show how far along the interpretation is for each SaliencyInterpreter. So we can have some idea of how much longer it will take.

LIME on DistilBERT

The LIME code fails when there's a datareader that concatenates the sequences for DistilBERT. We convert instances back to text, but the concatenated sequence gets converted to a single string, but the datareader expects two separate string sequences to make an Instance.

There's a way to fix this that would also make the code nicer. The implementation of LIME we use assumes unprocessed text, which is why we convert our tokenized Instances back to strings. Instead we should replace some of the LIME code so we can do the replacing of some of the tokens with UNKs ourselves, that way the datareader wouldn't be involved anymore.

This would also have as an added benefit that it would eliminate (possible) mistakes occuring in converting back to raw text and then re-tokenizing. I suspect this is introducing at least some weirdness.

Instantiate Evaluator from JsonNet file.

  • Allow for specifying:
    • directory of trained model to experiment on;
    • which interpreters to include and/or which combinations of interpreters to include;
    • wether to run experiments on cuda;
    • batch size to use during experiment;
  • Rename Evaluator to AttentionExperiment[er] to avoid confusion with the evaluate command in AllenNLP.
  • [Optional] Add attn_experiment command that starts the experiment from the commandline.

We can use Params.from_file and FromParams.from_params like it is done in allennlp/commands/train.py

nan-loss on entmax with Quora dataset.

It seems the entmax function can't handle an alpha of <=1, but it still returns gradients that allow it to get there during training.
This causes the loss to become 'nan'.

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.