Implementation of End-To-End Memory Networks with hyperparameter optimization. Tasks are from the bAbl dataset. Original GitHub repo can be found here.
- tensorflow 1.13.1
- scikit-learn 0.17.1
- six 1.10.0
For requirements information and installation instructions see here.
git clone https://github.com/sigopt/optimizing-memn2n.git
mkdir ./end2end_mem_nn_tensorflow/data/
cd ./end2end_mem_nn_tensorflow/data/
wget http://www.thespermwhale.com/jaseweston/babi/tasks_1-20_v1-2.tar.gz
(or if you don't have wget try:
curl http://www.thespermwhale.com/jaseweston/babi/tasks_1-20_v1-2.tar.gz -o tasks_1-20_v1-2.tar.gz)
tar xzvf ./tasks_1-20_v1-2.tar.gz
cd ../
source <[Path to virtual environment]>/bin/activate
python sigopt_optimization_run.py --run_single_exp True --run_joint_exp False --task_id 20 --sigopt_observation_budget 4 --sigopt_connection_token <SIGOPT API TOKEN> --sigopt_experiment_name 'task 20 conditionals optimization' --experiment_type 'conditionals'
python sigopt_optimization_run.py [--log_file <file path>] {--run_single_exp --task_id <task id> --sigopt_calc_accuracy_tasks None | --run_joint_exp --sigopt_calc_accuracy_tasks <string of comma separated task ids> --task_id None} [--max_grad_norm <l2 norm clipping>] [--batch_size <batch size>] [--epochs <total number of epochs>] [--random_state <random seed>] [--data_dir <path to bAbI data directory>] --sigopt_connection_token <API token for Sigopt account> {--sigopt_observation_budget <number of Sigopt observations> --sigopt_experiment_name <Sigopt experiment name> --experiment_type {random|sigopt|conditionals} | --sigopt_experiment_id <existing Sigopt experiment id>}
If optional arguments are not provided, the above command line will use the following default parameters and assumes the working directory is ./end2end_mem_nn_tensorflow:
- log_file = [WORKING DIRECTORY]/memn2n_optimization_run.log
- max_grad_norm = 40
- batch_size = 32
- epochs = 60
- random_state = None
- data_dir = ./data/tasks_1-20_v1-2/en/ (English 1k dataset)
- sigopt_experiment_id = None
Validation is performed on the validation and test sets of the data at the end of the specified number of epochs. The test accuracy calculated (either averaged over 20 tasks for joint training or specified task for single training) at this point is reported back as the optimization metric to Sigopt.
python sigopt_optimization_run.py --log_file '/Users/username/memory_network_opt.log' --run_single_exp --task_id 20 --sigopt_observation_budget 4 --sigopt_connection_token 'OEIUROEAHE889823I' --sigopt_experiment_name 'task 20 conditionals optimization' --experiment_type 'conditionals'
The above command will optimize bAbI task 20 using Sigopt Conditionals for 4 observation cycles using default parameters for max_grad_norm, batch_size, epochs, random_state, and data_dir
. Must be run with end2end_mem_nn_tensorflow as the working directory.
python sigopt_optimization_run.py --log_file '/Users/username/memory_network_opt.log' --run_single_exp --task_id 20 --max_grad_norm 10 --batch_size 31 --epochs 10 --data_dir '/Users/username/Downloads/tasks_1-20_v1-2/hn' --sigopt_observation_budget 2 --sigopt_connection_token 'OEIUROEAHE889823I' --sigopt_experiment_name 'task 1 random optimization' --experiment_type random
The above command will optimize bAbI task 1 using Sigopt's Random search implementation for 2 observation cycles with the specified max_grad_norm, batch_size, and epochs.
python sigopt_optimization_run.py --log_file '/Users/username/memory_network_opt.log' --run_single_exp --task_id 4 --sigopt_connection_token 'OEIUROEAHE889823I' --sigopt_experiment_id 67770
The above command will pick up an existing/already created experiment and continue to optimize until it meets the predefined number of optimization cycles. This can be found under the Experiment properties page. Must be run with end2end_mem_nn_tensorflow as the working directory. The task id specified on the CLI must match the task id previously specified for the experiment.
python sigopt_optimization_run.py --log_file '/Users/username/memory_network_opt.log' --run_joint_exp --sigopt_calc_accuracy_tasks '7,8,10' --max_grad_norm 10 --batch_size 31 --epochs 10 --sigopt_observation_budget 200 --sigopt_connection_token 'OEIUROEAHE889823I' --sigopt_experiment_name '20 task sigopt optimization' --experiment_type sigopt
The above command will run optimization on all 20 tasks using Sigopt's Bayesian Optimization for 200 observation cycles. For each Sigopt observation cycle, it will store the test accuracies for tasks 7,8,10 as experiment metadata. Must be run with end2end_mem_nn_tensorflow as the working directory.
python sigopt_optimization_run.py --log_file '/Users/username/memory_network_opt.log' --run_joint_exp --sigopt_calc_accuracy_tasks '7,8,10' --sigopt_connection_token 'OEIUROEAHE889823I' --sigopt_experiment_id 67773
The above command will pick up an existing experiment and continue to optimize until it meets the predefined number of optimization cycles. Must be run with end2end_mem_nn_tensorflow as the working directory.
Using the AWS dashboard, choose the latest Ubuntu Deep Learning AMI.
Select to launch the GPU compute p2.xlarge instance.
For this repo to run with GPU, it requires Tensorflow-gpu 1.0.0, Cuda 8.0, and CudNN 5.1.
You will need a Nvidia developer's login to download the archived CudNN version. Once you have the archived on your instance run the following commands:
unzip cudnn package:
tar -xvzf ./cudnn-8.0-linux-x64-v5.1-tgz
rm -rf /usr/local/cuda
sudo rm /usr/local/cuda8.0/lib64/libcudnn*
copy cudnn to cuda8.0:
sudo cp -P ./cuda/include/cudnn.h /usr/local/cuda8.0/include
copy cudnn libraries to cuda8:
sudo cp -P ./cuda/lib64/libcudnn* /usr/local/cuda8.0/lib64
create symlink from cuda8 to cuda:
ln -s /usr/local/cuda8.0 /usr/local/cuda
Now the Cuda version on your instance will be set to 8.0 and the cuDNN will be 5.1.0.
sudo apt-get install python3-pip
pip3 install virtualenv
virtualenv -p $(which python3) <LOCATION OF ENVIRONMENT>
source <LOCATION OF ENVIRONMENT>/bin/activate
scp -i <LOCATION OF PEM KEY> [...]/optimizing-memn2n/virtualenv_env_setup/python3_memn2n_tf_env_gpu_requirements.txt ubuntu@<INSTANCE PUBLIC DNS>:~
pip install -r [...]/python3_memn2n_tf_env_gpu_requirements.txt
As we activated our virtual environment in a previous step, these requirements will be installed within the environment.
scp -i <LOCATION OF PEM KEY> [...]/optimizing-memn2n.zip ubuntu@<INSTANCE PUBLIC DNS>:~
ssh -i <LOCATION OF PEM KEY> ubuntu@<INSTANCE PUBLIC DNS>
unzip optimizing-memn2n.zip
source <LOCATION OF PEM KEY>/bin/activate
python sigopt_optimization_run.py --log_file '/home/ubuntu/memory_network_opt.log' --data_dir '/home/ubuntu/data/tasks_1-20_v1-2/en' --run_single_exp False --run_joint_exp True --sigopt_calc_accuracy_tasks '7,8,10' --max_grad_norm 10 --batch_size 31 --epochs 10 --sigopt_observation_budget 200 --sigopt_connection_token 'OEIUROEAHE889823I' --sigopt_experiment_name '20 task sigopt optimization' --experiment_type sigopt