This is a repository for the paper EPTX.
-
You need Python 3.8+ to run this repository.
-
Install libraries using:
pip install -r requirements.txt
- Download dataset files from here, and extract it.
- Modify dataset path specified in the './run.sh' and execute the file.
- Or, run python script files
usage: train_model.py [-h] --name NAME --dataset DATASET [--seed SEED]
--experiment-dir EXPERIMENT_DIR [--beam-expl BEAM_EXPL]
[--beam-expr BEAM_EXPR]
[--window-size WINDOW_SIZE [WINDOW_SIZE ...]]
[--max-iter MAX_ITER]
[--stop-conditions [STOP_CONDITIONS [STOP_CONDITIONS ...]]]
[--model {EPT,EPTX,SWAN_A,SWAN_B,SWAN_P1} [{EPT,EPTX,SWAN_A,SWAN_B,SWAN_P1} ...]]
[--encoder ENCODER] [--equation-hidden EQUATION_HIDDEN]
[--equation-intermediate EQUATION_INTERMEDIATE]
[--equation-layer EQUATION_LAYER [EQUATION_LAYER ...]]
[--equation-head EQUATION_HEAD]
[--explanation-shuffle EXPLANATION_SHUFFLE]
[--log-path LOG_PATH] [--num-cpu NUM_CPU]
[--num-gpu NUM_GPU] [--opt-lr OPT_LR [OPT_LR ...]]
[--opt-beta1 OPT_BETA1] [--opt-beta2 OPT_BETA2]
[--opt-eps OPT_EPS] [--opt-grad-clip OPT_GRAD_CLIP]
[--opt-warmup OPT_WARMUP [OPT_WARMUP ...]]
[--batch-size BATCH_SIZE]
optional arguments:
-h, --help show this help message and exit
Dataset & Evaluation:
--name NAME, -name NAME
--dataset DATASET, -data DATASET
--seed SEED, -seed SEED
--experiment-dir EXPERIMENT_DIR, -exp EXPERIMENT_DIR
--beam-expl BEAM_EXPL, -beamX BEAM_EXPL
--beam-expr BEAM_EXPR, -beamQ BEAM_EXPR
--window-size WINDOW_SIZE [WINDOW_SIZE ...], -win WINDOW_SIZE [WINDOW_SIZE ...]
--max-iter MAX_ITER, -iter MAX_ITER
--stop-conditions [STOP_CONDITIONS [STOP_CONDITIONS ...]], -stop [STOP_CONDITIONS [STOP_CONDITIONS ...]]
Model:
--model {EPT,EPTX,EPTX_U,EPTX_F,EPTX_P1} [{EPT,EPTX,EPTX_U,EPTX_F,EPTX_P1} ...], -model {EPT,EPTX,EPTX_U,EPTX_F,EPTX_P1} [{EPT,EPTX,EPTX_U,EPTX_F,EPTX_P1} ...]
--encoder ENCODER, -enc ENCODER
--equation-hidden EQUATION_HIDDEN, -eqnH EQUATION_HIDDEN
--equation-intermediate EQUATION_INTERMEDIATE, -eqnI EQUATION_INTERMEDIATE
--equation-layer EQUATION_LAYER [EQUATION_LAYER ...], -eqnL EQUATION_LAYER [EQUATION_LAYER ...]
--equation-head EQUATION_HEAD, -eqnA EQUATION_HEAD
--explanation-shuffle EXPLANATION_SHUFFLE, -expS EXPLANATION_SHUFFLE
Logger setup:
--log-path LOG_PATH, -log LOG_PATH
Worker setup:
--num-cpu NUM_CPU, -cpu NUM_CPU
--num-gpu NUM_GPU, -gpu NUM_GPU
Optimization setup:
--opt-lr OPT_LR [OPT_LR ...], -lr OPT_LR [OPT_LR ...]
--opt-beta1 OPT_BETA1, -beta1 OPT_BETA1
--opt-beta2 OPT_BETA2, -beta2 OPT_BETA2
--opt-eps OPT_EPS, -eps OPT_EPS
--opt-grad-clip OPT_GRAD_CLIP, -clip OPT_GRAD_CLIP
--opt-warmup OPT_WARMUP [OPT_WARMUP ...], -warmup OPT_WARMUP [OPT_WARMUP ...]
--batch-size BATCH_SIZE, -bsz BATCH_SIZE
usage: train_fold.py [-h] --name NAME --experiment-dir EXPERIMENT_DIR
[EXPERIMENT_DIR ...] --model-config MODEL_CONFIG
[MODEL_CONFIG ...] [--log-path LOG_PATH]
optional arguments:
-h, --help show this help message and exit
Dataset & Evaluation:
--name NAME, -name NAME
--experiment-dir EXPERIMENT_DIR [EXPERIMENT_DIR ...], -exp EXPERIMENT_DIR [EXPERIMENT_DIR ...]
--model-config MODEL_CONFIG [MODEL_CONFIG ...], -model MODEL_CONFIG [MODEL_CONFIG ...]
Logger setup:
--log-path LOG_PATH, -log LOG_PATH
usage: test_model.py [-h] --model MODEL [MODEL ...] --dataset DATASET
--experiment-dir EXPERIMENT_DIR [--seed SEED]
[--faithfulness {sufficiency,comprehensiveness,error_propagation_corr,error_propagation_tree} [{sufficiency,comprehensiveness,error_propagation_corr,error_propagation_tree} ...]]
[--bootstrap-trials BOOTSTRAP_TRIALS]
[--sample-size SAMPLE_SIZE]
[--repeating-counts REPEATING_COUNTS [REPEATING_COUNTS ...]]
[--digressing-counts DIGRESSING_COUNTS [DIGRESSING_COUNTS ...]]
[--perturbation-samples PERTURBATION_SAMPLES]
[--num-cpu NUM_CPU] [--num-gpu NUM_GPU]
optional arguments:
-h, --help show this help message and exit
--model MODEL [MODEL ...], -model MODEL [MODEL ...]
--dataset DATASET, -data DATASET
--experiment-dir EXPERIMENT_DIR, -exp EXPERIMENT_DIR
--seed SEED, -seed SEED
--faithfulness {sufficiency,comprehensiveness,error_propagation_corr,error_propagation_tree} [{sufficiency,comprehensiveness,error_propagation_corr,error_propagation_tree} ...], -faith {sufficiency,comprehensiveness,error_propagation_corr,error_propagation_tree} [{sufficiency,comprehensiveness,error_propagation_corr,error_propagation_tree} ...]
--bootstrap-trials BOOTSTRAP_TRIALS, -ntr BOOTSTRAP_TRIALS
--sample-size SAMPLE_SIZE, -smp SAMPLE_SIZE
--repeating-counts REPEATING_COUNTS [REPEATING_COUNTS ...], -rep REPEATING_COUNTS [REPEATING_COUNTS ...]
--digressing-counts DIGRESSING_COUNTS [DIGRESSING_COUNTS ...], -dig DIGRESSING_COUNTS [DIGRESSING_COUNTS ...]
--perturbation-samples PERTURBATION_SAMPLES, -ptr PERTURBATION_SAMPLES
--num-cpu NUM_CPU, -cpu NUM_CPU
--num-gpu NUM_GPU, -gpu NUM_GPU
- To use BLEURT, please download BLEURT-D6-20.zip from the BLEURT repository and unzip it under 'resource/bleurt'.
-
/train_model.pyPython script file for hyperparameter searching or training model -
/train_model_debug.pyPython script file for debug purpose -
/train_fold.pyPython script file for training cross-validation folds based on the result oftrain_model.py -
/test_model.pyPython script file for evaluating model -
/run.shShell script for training models across datasets -
/commonpython package for constants or common functionalities/common/constpython package for constants/common/const/model.pymodel-specific key names/common/const/operand.pydefinition of constant operands, index of operands, and how to represent it in the text./common/const/operator.pydefinition of operators, its computational procedure, and how to represent it in the text./common/const/pad.pydefines PAD_ID and *_INF values
/common/datapython package for data classes/common/data/__init__.pyExample-level data class and its information data class/common/data/base.pyBase abstract classes for data representation/common/data/explanation.pyExplanation-related data classes/common/data/encoded.pyData class for context vectors/common/data/equation.pyEquation-related data classes/common/data/label.pyData class for target labels/common/data/prediction.pyData class for predicted result/common/data/text.pyData class for text input labels
/common/seedpython package for evaluating SEED dataset/common/seed/metric.pyMetric for explanation plausibility/common/seed/parse.pyParser function for infix equation/common/seed/pattern.pyFrequently used regex patterns, like numbers or fractions./common/seed/solve.pySolver class that evaluates the output equation, and related functions/constants.
/common/torchpython package for adopting PyTorch/common/torch/loss.pyDefines Cross-entropy loss with label smoothing/common/torch/util.pyVarious utility function for models
/common/dataset.pyClass for build minibatch and other dataset-specific things/common/tester.pyClass for evaluating correctness & plausibility/common/trial.pyUtility for building trial directory names (for Ray)
-
/experimentpython package for evaluation experiments/experiment/__init__.pyDefines experimet loader/experiment/base.pyAbstrat class for evaluation experiment/experiment/endtask.pyClasses for error propagation analyses/experiment/faithfulness.pyClasses for faithfulness experiment
-
/modelpython package for model classes/model/__init__.pyDefines model loader/model/basepython package for defining base classes/model/base/beamsearch.pyUtility for beam search/model/base/chkpt.pyAbstract class for checkpointing a model/model/base/layernorm.pyClass for LayerNorm with pad masked/model/base/posenc.pyDefines position encoding/model/base/util.pyDefines utility function for defining EPT
/model/eptpython package for defining EPT (EMNLP 2020)/model/ept/__init__.pyDefines EPT model/model/ept/attention.pyImplements Multi-head Attention and Transformer Decoder layer/model/ept/decoder.pyDefines decoder part of EPT, except operand-context pointer/model/ept/encoder.pyDefines encoder part of EPT
/model/eptxpython package for defining EPTX (the proposed model)/model/eptx/__init__.pyDefines EPTX model (based on EPT)/model/eptx/explain.pyDefines explanation decoder part of EPTX, except pointer-generator head./model/eptx/pg_head.pyDefines pointer-generator head for explanation decoder.
-
/learnerpython package for defining learning algorithm/learner/__init__.pyDefines Supervised Trainer class/learner/const.pyDefines constants for learner-specific options/learner/scheduler.pyDefines various warm-up scheduling methods/learner/util.pyDefines utility for defining Trainer class
-
/resourceDirectory for storing resources: Please download this folder from here./resource/dataset/pen.jsonthe PEN dataset/resource/experimentsDirectory containing split specifications/resource/experiments/penDirectory containing splits of PEN dataset/resource/experiments/drawDirectory containing splits of DRAW-1K dataset/resource/experiments/alg514-fold*Directory containing splits of ALG514-fold* dataset/resource/experiments/mawps-fold*Directory containing splits of MAWPS-fold* dataset- Each directory has train, test, and/or dev file.
Whenever you use this code for any academic purpose, please cite the paper below.
@inproceedings{kim-etal-2022-ept,
title = "{EPT}-{X}: An Expression-Pointer Transformer model that generates e{X}planations for numbers",
author = "Kim, Bugeun and
Ki, Kyung Seo and
Rhim, Sangkyu and
Gweon, Gahgene",
booktitle = "Proceedings of the 60th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers)",
month = may,
year = "2022",
address = "Dublin, Ireland",
publisher = "Association for Computational Linguistics",
url = "https://aclanthology.org/2022.acl-long.305",
doi = "10.18653/v1/2022.acl-long.305",
pages = "4442--4458",
abstract = "In this paper, we propose a neural model EPT-X (Expression-Pointer Transformer with Explanations), which utilizes natural language explanations to solve an algebraic word problem. To enhance the explainability of the encoding process of a neural model, EPT-X adopts the concepts of plausibility and faithfulness which are drawn from math word problem solving strategies by humans. A plausible explanation is one that includes contextual information for the numbers and variables that appear in a given math word problem. A faithful explanation is one that accurately represents the reasoning process behind the model{'}s solution equation. The EPT-X model yields an average baseline performance of 69.59{\%} on our PEN dataset and produces explanations with quality that is comparable to human output. The contribution of this work is two-fold. (1) EPT-X model: An explainable neural model that sets a baseline for algebraic word problem solving task, in terms of model{'}s correctness, plausibility, and faithfulness. (2) New dataset: We release a novel dataset PEN (Problems with Explanations for Numbers), which expands the existing datasets by attaching explanations to each number/variable.",
}