Suggested use is to use Anaconda and do pip install -r requirements.txt .
data: Folder to store datasetsRationale_Analysis/models: Folder to store allennlp modelsclassifiers: Models that do actually learningsaliency_scorer: Takes a trained model and return saliency scorers for inputsrationale_extractors: Models that take saliency scores and generate rationales in form readable byrationale_reader.pybase_predictor.py: Simple predictor to use with allennlp predict command as needed
Rationale_Analysis/subcommands: Subcommands to run saliency and rationale extractors since allennlp existingcommand semantics doesn't map quite as well to what we wanna do.Rationale_Analysis/training_config: Contains jsonnet training configs to use with allennlp for each of the three types of models above.Rationale_Analysis/commands: Actual bash scripts to run stuff.Rationale_Analysis/data/dataset_readers: Contains dataset readers to work with Allennlp.rationale_reader.py: Code to load actual datasets (jsonl with 3 fields - document, query, label)saliency_reader.py: Read output of Saliency scorer to pass into rationale extractors.
- Train any model
CUDA_DEVICE=0 \
DATASET_NAME=<dataset name> \
CLASSIFIER=<classifier type> \
DATA_BASE_PATH=<path to data> \
EXP_NAME=<your experiment name> \
bash Rationale_Analysis/commands/model_train_script.shYou path to data folder should contain three files - {train/dev/test}.jsonl . Each should be a list of dicts containing atleast two fields -
{
"document" : str,
"label" : str,
"query" : Optional[str]
}Output generated in outputs/<classifier type>/<dataset name>/<your experiment name>/ .
- Generate saliency scores
CUDA_DEVICE=0 \
DATASET_NAME=SST \
CLASSIFIER=<classifier type> \
DATA_BASE_PATH=Datasets/SST/data \
EXP_NAME=<your model-A exp name> \
SALIENCY=<saliency name> \
bash Rationale_Analysis/commands/saliency_script.shOutput generate in outputs/<classifier type>/SST/<your model-A exp name>/<saliency name>_saliency .
- Extract rationales from saliency
CUDA_DEVICE=0 \
DATASET_NAME=SST \
CLASSIFIER=<classifier type> \
EXP_NAME=<your model-A exp name> \
SALIENCY=<saliency name> \
RATIONALE=<rationale extraction type> \
RATIONALE_EXP_NAME=<your rationale exp name> \
bash Rationale_Analysis/commands/rationale_extractor_script.shOutput generated in outputs/<classifier type>/SST/<your model-A exp name>/<saliency name>_saliency/<rationale extraction type>_rationale/<your rationale exp name>.
- Extract Rationales and train model b.
CUDA_DEVICE=0 \
DATASET_NAME=SST \
CLASSIFIER=<classifier type> \
EXP_NAME=<your model-A exp name> \
SALIENCY=<saliency name> \
RATIONALE=<rationale extraction type> \
RATIONALE_EXP_NAME=<your exp name> \
bash Rationale_Analysis/commands/rationale_and_train_model_b_script.shAllowed values for now
- saliency name - file names in training_config/saliency_scorers
- classifier type - "bert_classification"
- rationale extraction type - filenames in training_config/rationale_extractors . Note each rationale extractor may also need some hyperparameter setting through env variables.