Skip to content

Latest commit

 

History

14 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

Which Spurious Correlations Impact Reasoning in NLI Models?

Code for the ACL 2023 system demonstration Which Spurious Correlations Impact Reasoning in NLI Models? A Visual Interactive Diagnosis through Data-Constrained Counterfactuals.

The dashboard is a human-in-the-loop tool for finding the spurious features an NLI model relies on, and for writing counterfactual examples that break them. It is seeded with data-constrained counterfactuals (DCCs): SNLI pairs that (i) have close neighbours in the training set carrying a different gold label, and (ii) sit in the hard-to-learn or ambiguous region of the model's data map — easy for annotators, hard for the model. Those two conditions make a DCC a good place to look for a shortcut the model has learned.

Around each DCC the interface supports the three-step loop from the paper: understanding the example and how the model reasons about it, diagnosing the shared feature by comparing the DCC against its nearest neighbours (all neighbours, and neighbours with the same label), and refining — editing a GPT-3 suggestion into a new premise/hypothesis pair, labelling it, and asking the model where the new example would land on the data map. Examples that end up confusing the model are the useful ones, and get written out for later use as training augmentation or as an adversarial test suite.

The app is a FastAPI backend serving pre-computed SNLI artefacts and a RoBERTa model, plus a React/TypeScript frontend with two tabs: a blog-post walkthrough of the method and the interactive dashboard itself.

Setup

Backend, Python 3.8:

cd backend
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
export DCC_CHECKPOINTS=/path/to/checkpoints

Frontend, Node 16 or newer:

cd react-frontend
npm install

Running locally

cd backend
python main.py          # uvicorn on 0.0.0.0:10000, routes documented at /docs
cd react-frontend
npm start               # http://localhost:3000

The frontend talks to http://localhost:10000/api/v1 by default. Set REACT_APP_BACKEND_URL to point it elsewhere, either in react-frontend/.env (see .env.example) or on the command line; Create React App bakes the value into the bundle, so it is a build-time setting. The backend takes its port from PORT and its data directory from DCC_DATA.

Data

Everything under backend/data/ is pre-computed; nothing here trains a model or calls a language model to generate suggestions.

cartography_filtered/htl_ambi_dashboard_2000.pkl is the DCC pool — hard-to-learn and ambiguous SNLI pairs, each with its nearest neighbours, their data map coordinates, and the GPT-3 premise and hypothesis suggestions — filtered down to the premises in NCF_samples.csv to make the dashboard queue. The d3_datamap_test*.csv files are the SNLI points the data map is drawn from. Counterfactuals written in the dashboard are appended to NLI/submitted/cfs_submitted.tsv.

Model feedback

Two routes need the model: one places a newly written pair on the data map, the other records what the model makes of a submission. Both are served by a RoBERTa model fine-tuned on SNLI, kept as one checkpoint per training epoch:

checkpoints/
├── checkpoint-1000/
├── checkpoint-2000/
└── …

Each is an ordinary from_pretrained directory, and the classification head is expected to be trained with the label order entailment, neutral, contradiction. Point DCC_CHECKPOINTS at the parent directory. The checkpoints are not distributed here; without them those two routes answer 503 and the rest of the dashboard still runs.

Deployment

backend/Dockerfile and react-frontend/Dockerfile build the two services. The frontend image needs the backend URL at build time:

docker build --build-arg REACT_APP_BACKEND_URL=https://example.org/api/v1 react-frontend

Citation

@inproceedings{chan-etal-2023-spurious,
    title     = {Which Spurious Correlations Impact Reasoning in {NLI} Models?
                 A Visual Interactive Diagnosis through Data-Constrained Counterfactuals},
    author    = {Chan, Robin and Amini, Afra and El-Assady, Mennatallah},
    booktitle = {Proceedings of the 61st Annual Meeting of the Association for
                 Computational Linguistics (Volume 3: System Demonstrations)},
    month     = jul,
    year      = {2023},
    address   = {Toronto, Canada},
    publisher = {Association for Computational Linguistics},
    url       = {https://aclanthology.org/2023.acl-demo.44/},
    doi       = {10.18653/v1/2023.acl-demo.44},
    pages     = {463--470}
}

About

Code accompanying the ACL 2023 demo paper "Which Spurious Correlations Impact Reasoning in NLI Models? A Visual Interactive Diagnosis through Data-Constrained Counterfactuals"

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages