Official repository for the "A Benchmark Suite for Systematically Evaluating Reasoning Shortcuts" paper.
The data generator includes:
MNISTMathMNISTLogicKandLogicCLE4EVRSDDOIA
NOTE: The
bpylibrary is compatible only withPython 3.7. If you intend to generateCLE4EVRorSDDOIAdata using this library, ensure that you are using Python version 3.7 for compatibility.
Remember to run this for bpy
pip install bpy==2.91a0 && bpy_post_install
CLE4EVR and SDDOIA use Blender:
apt-get install blender
Access the linux terminal and use the conda installation followed by pip3:
$conda env create -n rs python=3.7
$conda activate rs
$pip install -r requirements.txt
Before running the code you should edit the conf.yml file specifying all the characteristic your dataset should have, some examples will be provided in the folder named examples_conf.
The repository is structured in the following way:
rssgen: the main module of the repositoryexamples_conf: contains some examples for the datasets configurationsboia_conf: contains the configuration files forSDDOIAclevr_config: contains the configuration files forCLE4EVRrssgen/parsers: contains the parsers for the yaml contentrssgen/generator: contains the stuff for generating the synthetic datasets
The general flow should be the following:
MAIN
--------------
| ^ | ^
v | v |
parsers generators
First, ensure that you modify the YAML configuration files for KandLogic, MNISTMath, and MNISTLogic. For CLE4EVR and SDDOIA, provide the necessary command-line arguments. The following lines assume these configurations are already set.
python -m rssgen examples_config/mnist.yml mnist MNIST_MATH_OUT_FOLDER
python -m rssgen examples_config/xor.yml xor MNIST_LOGIC_OUT_FOLDER
python -m rssgen examples_config/kandinsky.yml kandinsky KAND_LOGIC_OUT_FOLDER
CLE4EVR and SDDOIA need to be run inside Blender. Therefore, please make sure to modify the import lines in rssgen/clevr/clevr_renderer.py and rssgen/sddoia/sddoia.py to point to the location of the repository on your PC. Additionally, ensure that the import points to the libraries in your environment so that Blender's built-in Python interpreter can access them.
cd rssgen/clevr
Xvfb :1 -screen 0 1024x768x24 & export DISPLAY=:1
blender -noaudio -b -P clevr_renderer.py
NOTE: Due to licensing restrictions, the traffic light models cannot be provided directly in this repository. Therefore, you have two options:
-
Create Your Own Traffic Light Models: You can build your own models in Blender and place them in the
boia_config/shapesfolder. Make sure to name the files as follows:TLG.blendfor the green traffic light,TLY.blendfor the yellow traffic light, andTLR.blendfor the red traffic light.
Additionally, the names of the objects inside each file should be
TLG,TLY, andTLR, respectively. -
Download and Modify Existing Models: You can download traffic light models from TurboSquid and modify them to fit the project requirements.
If you need to change the names of the models, you can modify the config.py file, which refers to all the models included in the project.
cd rssgen/sddoia
Xvfb :1 -screen 0 1024x768x24 & export DISPLAY=:1
blender -noaudio -b -P sddoia.py
For all kind of problems do not hesitate to contact me. If you have additional mitigation strategies that you want to include as for others to test, please send me a pull request.
To see the Makefile functions, simply call the appropriate help command with GNU/Make
make helpThe Makefile provides a simple and convenient way to manage Python virtual environments (see venv).
In order to create the virtual enviroment and install the requirements be sure you have Python 3.8
make env
source ./venv/reasoning-shortcut/bin/activate
make installRemember to deactivate the virtual enviroment once you have finished dealing with the project
deactivateThe automatic code documentation is provided Sphinx v4.5.0.
In order to have the code documentation available, you need to install the development requirements
pip install --upgrade pip
pip install -r requirements.dev.txtSince Sphinx commands are quite verbose, I suggest you to employ the following commands using the Makefile.
make doc-layout
make docThe generated documentation will be accessible by opening docs/build/html/index.html in your browser, or equivalently by running
make open-docHowever, for the sake of completeness one may want to run the full Sphinx commands listed here.
sphinx-quickstart docs --sep --no-batchfile --project rssgen --author "X" -r 0.1 --language en --extensions sphinx.ext.autodoc --extensions sphinx.ext.napoleon --extensions sphinx.ext.viewcode --extensions myst_parser
sphinx-apidoc -P -o docs/source .
cd docs; make html