# CLIPPER

We provide the code for the experiments for the paper "ON IMPROVING NEUROSYMBOLIC LEARNING BY EXPLOITING THE REPRESENTATION SPACE".


## Code

We provide the code for the following experiments:
- MNIST SUM and MAX
  + The script to run the experiment for dolphin and scallop is `./experiments/mnist/run_balanced_mnist_sum.sh`. For example, run `./run_balanced_mnist_sum.sh mnist 100 3 msum dolphin` for dolphin results with MNIST Sum-3 with 100 training samples. Replace `mnist` with `cifar10` for CIFAR results.
  + The script to run these experiments with ISED is in `./ISED/generation-pipeline/run_experiments.sh` for MNIST. For example, run `./run_experiments.sh sum_3_mnist` for ISED results with MNIST Sum-3 with both 100 and 500 training samples. Similarly, for CIFAR10, the script is in `ISED/generation-pipeline/run_experiments_cifar10.sh`.
- HWF
  + The script to run the scallop experiment is `./experiments/hwf/run_exp_scallop.sh`
  + The script to run the dolphin experiment is `./experiments/hwf/run_exp_dolphin.sh`
  + The script to run the ISED experiment is `./ISED/custom/hwf/run_exps.sh`
- VQAR
  + The experiment script is in `./experiments/vqar/call`, while the script to generate the data is in `./experiments/vqar/benchmark`
  + You will have to download the data for VQAR from https://drive.google.com/file/d/1MLLabCNtv4Crl4CPBLSnCtpEkfbplQIw/view?usp=drive_link into the `./experiments/data/VQAR/dataset` folder.
  + Then run `python vqar_trainer.py  --gpu 0 --epochs 50  --early_stopping 5  --lr 0.0001` in `./experiments/vqar/call` to run the vqar trainer. Add the `--with_purification --structure-k 1` options for running VQAR with CLIPPER(ENC) and add the `--mock-proximity` argument to run it with CLIPPER(GOLD).
- Mugen
  + The scripts are in `./experiments/mugen/`
  + For Dolphin use the `run_dolphin.py` script as follows: `python run_dolphin.py --use_cuda --phase=train --epochs 35 --early_stopping --train_size 250 --use_cuda --batch_size 3`, and add `--with_purification --structure-k 1` to get the results with CLIPPER(ENC), and add `--with_purification --structure-k 1 --mock_proximity` for CLIPPER(GOLD).
  + Similarly, for scallop, use the `run_scallop.py` script as follows: `python run_scallop.py --use_cuda --phase=train --epochs 35 --early_stopping --train_size 250 --use_cuda --batch_size 4`. Add the same arguments as with Dolphin to run with CLIPPER.

## Installation
Before installing any of the frameworks, first install some prerequisites for CLIPPER:
- faiss : https://github.com/facebookresearch/faiss/blob/main/INSTALL.md 
- ortools : https://developers.google.com/optimization/install/python 

Then install Dolphin by running `pip install .`. This should also install other dependencies.
Then install Scallop by following the instructions here: https://www.scallop-lang.org/download.html. Make sure to also install the python API endpoints called `scallopy`.
Then install ISED by changing directories to `./ISED` and running `bash setup.sh`.
