├── LICENSE ├── README.md ├── examples └── 1.json ├── python ├── deepcoder.py ├── log │ ├── events.out.tfevents.1507302422.vaporized.local │ ├── events.out.tfevents.1507302441.vaporized.local │ ├── events.out.tfevents.1507303701.vaporized.local │ ├── events.out.tfevents.1507303946.vaporized.local │ ├── events.out.tfevents.1507304236.vaporized.local │ ├── events.out.tfevents.1507306052.vaporized.local │ ├── events.out.tfevents.1507306171.vaporized.local │ ├── events.out.tfevents.1507306196.vaporized.local │ ├── events.out.tfevents.1507306981.vaporized.local │ ├── events.out.tfevents.1507307289.vaporized.local │ ├── events.out.tfevents.1507307392.vaporized.local │ ├── events.out.tfevents.1507307554.vaporized.local │ ├── events.out.tfevents.1507307787.vaporized.local │ ├── events.out.tfevents.1507307909.vaporized.local │ ├── events.out.tfevents.1507308396.vaporized.local │ ├── events.out.tfevents.1507308423.vaporized.local │ ├── events.out.tfevents.1507308569.vaporized.local │ ├── events.out.tfevents.1507308844.vaporized.local │ ├── events.out.tfevents.1507308854.vaporized.local │ ├── events.out.tfevents.1507309344.vaporized.local │ ├── events.out.tfevents.1507309394.vaporized.local │ ├── events.out.tfevents.1507309468.vaporized.local │ ├── events.out.tfevents.1507309487.vaporized.local │ ├── events.out.tfevents.1507351630.vaporized.local │ ├── events.out.tfevents.1507351655.vaporized.local │ ├── events.out.tfevents.1507362114.vaporized.local │ ├── events.out.tfevents.1507362153.vaporized.local │ ├── events.out.tfevents.1507362316.vaporized.local │ ├── events.out.tfevents.1507362642.vaporized.local │ ├── events.out.tfevents.1507362789.vaporized.local │ ├── events.out.tfevents.1507362898.vaporized.local │ ├── events.out.tfevents.1507363212.vaporized.local │ ├── events.out.tfevents.1507363261.vaporized.local │ ├── events.out.tfevents.1507363460.vaporized.local │ ├── events.out.tfevents.1507363528.vaporized.local │ ├── events.out.tfevents.1507363570.vaporized.local │ ├── events.out.tfevents.1507363690.vaporized.local │ ├── events.out.tfevents.1507363964.vaporized.local │ ├── events.out.tfevents.1507364061.vaporized.local │ ├── events.out.tfevents.1507366047.vaporized.local │ ├── events.out.tfevents.1507366079.vaporized.local │ ├── events.out.tfevents.1507366132.vaporized.local │ ├── events.out.tfevents.1507366278.vaporized.local │ ├── events.out.tfevents.1507367454.vaporized.local │ ├── events.out.tfevents.1507367495.vaporized.local │ ├── events.out.tfevents.1507367527.vaporized.local │ ├── events.out.tfevents.1507367572.vaporized.local │ ├── events.out.tfevents.1507367592.vaporized.local │ ├── events.out.tfevents.1507367625.vaporized.local │ ├── events.out.tfevents.1507367856.vaporized.local │ ├── events.out.tfevents.1507368276.vaporized.local │ └── events.out.tfevents.1507368308.vaporized.local ├── model.py ├── model │ ├── checkpoint │ ├── model-100.data-00000-of-00001 │ ├── model-100.index │ ├── model-100.meta │ ├── model-20.data-00000-of-00001 │ ├── model-20.index │ ├── model-20.meta │ ├── model-40.data-00000-of-00001 │ ├── model-40.index │ ├── model-40.meta │ ├── model-60.data-00000-of-00001 │ ├── model-60.index │ ├── model-60.meta │ ├── model-80.data-00000-of-00001 │ ├── model-80.index │ └── model-80.meta └── util_gen.py └── scripts └── gen_program_gen.py /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 vapor 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | DeepCoder-tensorflow 2 | === 3 | 4 | This repository contains a model implementation for DeepCoder in tensorflow. 5 | I did not implement the DSL, because it is too time consuming, instead, I used 6 | the implementation from [this repo](https://github.com/HiroakiMikami/deep-coder). 7 | 8 | Unfortunately, the original author did not include a license. To prevent copyright infringement, 9 | I did not fork that repo and modify directly on github. Instead, I publish the code needed to assemble 10 | a working version. 11 | 12 | Building 13 | --- 14 | Please refer to the guide in the original repo. You may need to compile `gtest` and the program with option 15 | `` -DCMAKE_CXX_COMPILER=`which g++-6` -DCMAKE_C_COMPILER=`which gcc-6` `` for cmake. Make sure the code is 16 | working before proceeding to the next step. 17 | 18 | Generating Code for tensorflow 19 | --- 20 | Download the source code from the original repo: [this commit](https://codeload.github.com/HiroakiMikami/deep-coder/zip/b11a07d4d2113f69d2ea69015c35db18879e7758). 21 | There are two python scripts that will generate the appropriate files from the original source code. 22 | Navigate to `DeepCoder-tensorflow` folder. `deep-coder-master` refers to the folder of the original repo. 23 | ```bash 24 | cd scripts 25 | python3 gen_program_gen.py path/to/deep-coder-master/scripts/ 26 | cd .. 27 | cd python 28 | python3 util_gen.py path/to/deep-coder-master/python/ 29 | ``` 30 | Now copy all the files in `DeepCoder-tensorflow` to `deep-coder-master`, replace the conflicting files. 31 | 32 | Usage 33 | --- 34 | Search with the help of the model 35 | ```bash 36 | $ time ./scripts/gen_program.sh examples/1.json 3 true dfs 37 | 38 | head last take drop access minimum maximum reverse sort sum map filter count zip_with scanl1 >0 <0 %2 == 0 %2 == 1+1 -1 *(-1) *2 *3 *4 /2 /3 /4 **2 MIN MAX 39 | 0.0831 0.0779 0.254 0.0722 0.00302 0.0041 0.0923 0.706 0.273 0.009720.059 0.185 0.154 0.0288 0.035 0.0107 0.0932 0.000624 0.002110.0053 0.00189 0.057 0.00132 0.00355 0.00775 0.000167 0.0171 0.194 0.127 0.0298 0.334 0.111 4.07e-11 4.19e-11 4.19e-11 40 | --- 41 | a <- read_list 42 | b <- read_list 43 | c <- sort a 44 | d <- map **2 c 45 | e <- zip_with MIN d b 46 | --- 47 | 48 | 49 | real 0m18.947s 50 | user 0m18.621s 51 | sys 0m0.275s 52 | ``` 53 | Search without the model 54 | ```bash 55 | $ time ./scripts/gen_program.sh examples/1.json 3 false none 56 | 57 | --- 58 | a <- read_list 59 | b <- read_list 60 | c <- sort a 61 | d <- map **2 c 62 | e <- zip_with MIN d b 63 | --- 64 | 65 | 66 | real 0m31.580s 67 | user 0m31.093s 68 | sys 0m0.307s 69 | 70 | ``` 71 | 72 | Training 73 | --- 74 | ```bash 75 | $ python3 ./python/deepcoder.py train dataset/dataset.json 76 | ``` 77 | -------------------------------------------------------------------------------- /examples/1.json: -------------------------------------------------------------------------------- 1 | [ 2 | {"input":[[5,-2,1,-5,3,-6,6,7,1,-10],[2,-7,4,7,-9,-9,-2,-1,7,9]],"output":[2,-7,4,4,-9,-9,-2,-1,7,9]}, 3 | {"input":[[9],[-6,2,2,7,7,4]],"output":[-6]}, 4 | {"input":[[7,-1,10,10,3,3,-7,8],[]],"output":[]}, 5 | {"input":[[9,-7,-6,-7,-8,10,-4,-3],[5,7]],"output":[5,7]}, 6 | {"input":[[-3],[-9,7,-7,-1,5,9,-7,-9,-9]],"output":[-9]} 7 | ] -------------------------------------------------------------------------------- /python/deepcoder.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import tensorflow as tf 3 | import json, argparse, copy, os 4 | import model 5 | from util import preprocess_json, print_value, convert_example 6 | params = tf.flags.FLAGS 7 | 8 | tf.flags.DEFINE_integer("learning_rate", 0.01, "") 9 | tf.flags.DEFINE_integer("batch_size", 100, "") 10 | tf.flags.DEFINE_integer("num_epoch", 100, "") 11 | tf.flags.DEFINE_integer("num_input", 3, "") 12 | tf.flags.DEFINE_integer("embedding_size", 20, "") 13 | tf.flags.DEFINE_integer("integer_min", -100, "") 14 | tf.flags.DEFINE_integer("integer_max", 100, "") 15 | tf.flags.DEFINE_integer("num_example", 5, "") 16 | tf.flags.DEFINE_integer("num_hidden_layer", 3, "") 17 | tf.flags.DEFINE_integer("max_list_len", 10, "") 18 | tf.flags.DEFINE_integer("hidden_layer_size", 256, "") 19 | tf.flags.DEFINE_integer("attribute_size", 34, "") 20 | 21 | 22 | parser = argparse.ArgumentParser(description='DeepCoder Model') 23 | parser.add_argument('mode', choices=['train', 'predict']) 24 | parser.add_argument('dir', type=str, help='Path to data') 25 | parser.add_argument('-e', '--enable', choices=['true','false'],default='true',help='Whether to use model for searching') 26 | args = parser.parse_args() 27 | 28 | params_dict = {'num_input': params.num_input, 29 | 'integer_min': params.integer_min, 30 | 'integer_range': params.integer_max - params.integer_min + 1, 31 | 'max_list_len': params.max_list_len} 32 | 33 | 34 | def train(): 35 | # Load dataset from json 36 | print("Loading dataset") 37 | file = open(args.dir, 'r') 38 | x = json.load(file) 39 | y = preprocess_json(x, params_dict) 40 | data = np.asarray([y[i][0] for i in range(len(y))]) 41 | target = np.asarray([y[i][1] for i in range(len(y))]) 42 | print("Complete") 43 | 44 | d = model.DeepCoder(num_input = params.num_input, 45 | embedding_size = params.embedding_size, 46 | integer_range = params.integer_max - params.integer_min + 1, 47 | num_example = params.num_example, 48 | max_list_len = params.max_list_len, 49 | num_hidden_layer = params.num_hidden_layer, 50 | hidden_layer_size = params.hidden_layer_size, 51 | attribute_size = params.attribute_size, 52 | batch_size = params.batch_size, 53 | num_epoch = params.num_epoch, 54 | learning_rate = params.learning_rate) 55 | d.train(data, target) 56 | 57 | def predict(): 58 | # Load example 59 | file = open(args.dir, 'r') 60 | data = json.load(file) 61 | data_backup = copy.deepcopy(data) 62 | data_processed = np.array([convert_example(x, params_dict) for x in data]) 63 | 64 | output_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'output') 65 | try: 66 | os.remove(output_path) 67 | except OSError: 68 | pass 69 | output = open(output_path, 'w+') 70 | 71 | # To produce standard input of c++ parser, the output has to be the same 72 | for x in data_backup: 73 | for v in x["input"]: 74 | print_value(v, output) 75 | print("---", file=output) 76 | print_value(x["output"], output) 77 | print("---", file=output) 78 | print("---", file=output) 79 | 80 | x = 'Attribute: ' 81 | if args.enable == 'true': 82 | d = model.DeepCoder(num_input = params.num_input, 83 | embedding_size = params.embedding_size, 84 | integer_range = params.integer_max - params.integer_min + 1, 85 | num_example = params.num_example, 86 | max_list_len = params.max_list_len, 87 | num_hidden_layer = params.num_hidden_layer, 88 | hidden_layer_size = params.hidden_layer_size, 89 | attribute_size = params.attribute_size, 90 | batch_size = params.batch_size, 91 | num_epoch = params.num_epoch, 92 | learning_rate = params.learning_rate) 93 | 94 | attributes = d.predict(np.asarray([data_processed],dtype=np.int32)) 95 | for t in attributes.tolist()[0]: 96 | x += str(t) + " " 97 | else: 98 | x += "1 " * params.attribute_size 99 | print(x, file=output) 100 | output.close() 101 | 102 | 103 | def main(): 104 | if args.mode == 'train': 105 | train() 106 | elif args.mode == 'predict': 107 | predict() 108 | 109 | if __name__ == '__main__': 110 | main() 111 | -------------------------------------------------------------------------------- /python/log/events.out.tfevents.1507302422.vaporized.local: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/log/events.out.tfevents.1507302422.vaporized.local -------------------------------------------------------------------------------- /python/log/events.out.tfevents.1507302441.vaporized.local: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/log/events.out.tfevents.1507302441.vaporized.local -------------------------------------------------------------------------------- /python/log/events.out.tfevents.1507303701.vaporized.local: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/log/events.out.tfevents.1507303701.vaporized.local -------------------------------------------------------------------------------- /python/log/events.out.tfevents.1507303946.vaporized.local: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/log/events.out.tfevents.1507303946.vaporized.local -------------------------------------------------------------------------------- /python/log/events.out.tfevents.1507304236.vaporized.local: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/log/events.out.tfevents.1507304236.vaporized.local -------------------------------------------------------------------------------- /python/log/events.out.tfevents.1507306052.vaporized.local: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/log/events.out.tfevents.1507306052.vaporized.local -------------------------------------------------------------------------------- /python/log/events.out.tfevents.1507306171.vaporized.local: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/log/events.out.tfevents.1507306171.vaporized.local -------------------------------------------------------------------------------- /python/log/events.out.tfevents.1507306196.vaporized.local: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/log/events.out.tfevents.1507306196.vaporized.local -------------------------------------------------------------------------------- /python/log/events.out.tfevents.1507306981.vaporized.local: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/log/events.out.tfevents.1507306981.vaporized.local -------------------------------------------------------------------------------- /python/log/events.out.tfevents.1507307289.vaporized.local: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/log/events.out.tfevents.1507307289.vaporized.local -------------------------------------------------------------------------------- /python/log/events.out.tfevents.1507307392.vaporized.local: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/log/events.out.tfevents.1507307392.vaporized.local -------------------------------------------------------------------------------- /python/log/events.out.tfevents.1507307554.vaporized.local: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/log/events.out.tfevents.1507307554.vaporized.local -------------------------------------------------------------------------------- /python/log/events.out.tfevents.1507307787.vaporized.local: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/log/events.out.tfevents.1507307787.vaporized.local -------------------------------------------------------------------------------- /python/log/events.out.tfevents.1507307909.vaporized.local: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/log/events.out.tfevents.1507307909.vaporized.local -------------------------------------------------------------------------------- /python/log/events.out.tfevents.1507308396.vaporized.local: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/log/events.out.tfevents.1507308396.vaporized.local -------------------------------------------------------------------------------- /python/log/events.out.tfevents.1507308423.vaporized.local: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/log/events.out.tfevents.1507308423.vaporized.local -------------------------------------------------------------------------------- /python/log/events.out.tfevents.1507308569.vaporized.local: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/log/events.out.tfevents.1507308569.vaporized.local -------------------------------------------------------------------------------- /python/log/events.out.tfevents.1507308844.vaporized.local: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/log/events.out.tfevents.1507308844.vaporized.local -------------------------------------------------------------------------------- /python/log/events.out.tfevents.1507308854.vaporized.local: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/log/events.out.tfevents.1507308854.vaporized.local -------------------------------------------------------------------------------- /python/log/events.out.tfevents.1507309344.vaporized.local: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/log/events.out.tfevents.1507309344.vaporized.local -------------------------------------------------------------------------------- /python/log/events.out.tfevents.1507309394.vaporized.local: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/log/events.out.tfevents.1507309394.vaporized.local -------------------------------------------------------------------------------- /python/log/events.out.tfevents.1507309468.vaporized.local: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/log/events.out.tfevents.1507309468.vaporized.local -------------------------------------------------------------------------------- /python/log/events.out.tfevents.1507309487.vaporized.local: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/log/events.out.tfevents.1507309487.vaporized.local -------------------------------------------------------------------------------- /python/log/events.out.tfevents.1507351630.vaporized.local: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/log/events.out.tfevents.1507351630.vaporized.local -------------------------------------------------------------------------------- /python/log/events.out.tfevents.1507351655.vaporized.local: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/log/events.out.tfevents.1507351655.vaporized.local -------------------------------------------------------------------------------- /python/log/events.out.tfevents.1507362114.vaporized.local: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/log/events.out.tfevents.1507362114.vaporized.local -------------------------------------------------------------------------------- /python/log/events.out.tfevents.1507362153.vaporized.local: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/log/events.out.tfevents.1507362153.vaporized.local -------------------------------------------------------------------------------- /python/log/events.out.tfevents.1507362316.vaporized.local: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/log/events.out.tfevents.1507362316.vaporized.local -------------------------------------------------------------------------------- /python/log/events.out.tfevents.1507362642.vaporized.local: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/log/events.out.tfevents.1507362642.vaporized.local -------------------------------------------------------------------------------- /python/log/events.out.tfevents.1507362789.vaporized.local: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/log/events.out.tfevents.1507362789.vaporized.local -------------------------------------------------------------------------------- /python/log/events.out.tfevents.1507362898.vaporized.local: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/log/events.out.tfevents.1507362898.vaporized.local -------------------------------------------------------------------------------- /python/log/events.out.tfevents.1507363212.vaporized.local: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/log/events.out.tfevents.1507363212.vaporized.local -------------------------------------------------------------------------------- /python/log/events.out.tfevents.1507363261.vaporized.local: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/log/events.out.tfevents.1507363261.vaporized.local -------------------------------------------------------------------------------- /python/log/events.out.tfevents.1507363460.vaporized.local: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/log/events.out.tfevents.1507363460.vaporized.local -------------------------------------------------------------------------------- /python/log/events.out.tfevents.1507363528.vaporized.local: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/log/events.out.tfevents.1507363528.vaporized.local -------------------------------------------------------------------------------- /python/log/events.out.tfevents.1507363570.vaporized.local: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/log/events.out.tfevents.1507363570.vaporized.local -------------------------------------------------------------------------------- /python/log/events.out.tfevents.1507363690.vaporized.local: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/log/events.out.tfevents.1507363690.vaporized.local -------------------------------------------------------------------------------- /python/log/events.out.tfevents.1507363964.vaporized.local: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/log/events.out.tfevents.1507363964.vaporized.local -------------------------------------------------------------------------------- /python/log/events.out.tfevents.1507364061.vaporized.local: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/log/events.out.tfevents.1507364061.vaporized.local -------------------------------------------------------------------------------- /python/log/events.out.tfevents.1507366047.vaporized.local: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/log/events.out.tfevents.1507366047.vaporized.local -------------------------------------------------------------------------------- /python/log/events.out.tfevents.1507366079.vaporized.local: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/log/events.out.tfevents.1507366079.vaporized.local -------------------------------------------------------------------------------- /python/log/events.out.tfevents.1507366132.vaporized.local: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/log/events.out.tfevents.1507366132.vaporized.local -------------------------------------------------------------------------------- /python/log/events.out.tfevents.1507366278.vaporized.local: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/log/events.out.tfevents.1507366278.vaporized.local -------------------------------------------------------------------------------- /python/log/events.out.tfevents.1507367454.vaporized.local: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/log/events.out.tfevents.1507367454.vaporized.local -------------------------------------------------------------------------------- /python/log/events.out.tfevents.1507367495.vaporized.local: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/log/events.out.tfevents.1507367495.vaporized.local -------------------------------------------------------------------------------- /python/log/events.out.tfevents.1507367527.vaporized.local: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/log/events.out.tfevents.1507367527.vaporized.local -------------------------------------------------------------------------------- /python/log/events.out.tfevents.1507367572.vaporized.local: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/log/events.out.tfevents.1507367572.vaporized.local -------------------------------------------------------------------------------- /python/log/events.out.tfevents.1507367592.vaporized.local: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/log/events.out.tfevents.1507367592.vaporized.local -------------------------------------------------------------------------------- /python/log/events.out.tfevents.1507367625.vaporized.local: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/log/events.out.tfevents.1507367625.vaporized.local -------------------------------------------------------------------------------- /python/log/events.out.tfevents.1507367856.vaporized.local: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/log/events.out.tfevents.1507367856.vaporized.local -------------------------------------------------------------------------------- /python/log/events.out.tfevents.1507368276.vaporized.local: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/log/events.out.tfevents.1507368276.vaporized.local -------------------------------------------------------------------------------- /python/log/events.out.tfevents.1507368308.vaporized.local: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/log/events.out.tfevents.1507368308.vaporized.local -------------------------------------------------------------------------------- /python/model.py: -------------------------------------------------------------------------------- 1 | import tensorflow as tf 2 | import numpy as np 3 | import os 4 | 5 | class DeepCoder: 6 | def __init__(self, 7 | num_input = 3, 8 | embedding_size = 20, 9 | integer_range = 201, 10 | num_example = 5, 11 | max_list_len = 10, 12 | num_hidden_layer = 3, 13 | hidden_layer_size = 256, 14 | attribute_size = 34, 15 | batch_size = 100, 16 | num_epoch = 100, 17 | learning_rate = 0.01, 18 | save_dir = os.path.dirname(os.path.realpath(__file__)) 19 | ): 20 | 21 | """ 22 | Args: 23 | num_input: Number of inputs(parameters) of a program 24 | embedding_size: Dimension of the integer embedding 25 | integer_range: Range of all possible outputs of a program 26 | num_example: Number of example provided per attribute 27 | max_list_len: Maximum length of a input/output list 28 | num_hidden_layer: Number of hidden layers 29 | hidden_layer_size: Dimension of hidden layer 30 | attribute_width: Number of functions in DSL 31 | batch_size: Number of samples per batch 32 | num_epoch: Number of epoch 33 | learning_rate: Learning rate 34 | """ 35 | 36 | self._num_input = num_input 37 | self._embedding_size = embedding_size 38 | self._integer_range = integer_range 39 | self._num_example = num_example 40 | self._max_list_len = max_list_len 41 | self._num_hidden_layer = num_hidden_layer 42 | self._hidden_layer_size = hidden_layer_size 43 | self._attribute_size = attribute_size 44 | self._batch_size = batch_size 45 | self._num_epoch = num_epoch 46 | self._learning_rate = learning_rate 47 | self._save_dir = save_dir 48 | 49 | self._build_model() 50 | 51 | def _build_model(self): 52 | 53 | # Placeholders 54 | 55 | # data (x) 56 | # num_input + num_output == num_input + 1 57 | # max_list_len + type_vec_len == max_list_len + 2 58 | self._prog_data = tf.placeholder(tf.int32, shape=[None, 59 | self._num_example, 60 | self._num_input + 1, 61 | self._max_list_len + 2]) 62 | 63 | # target (y) 64 | self._attribute = tf.placeholder(tf.float32, shape=[None, self._attribute_size]) 65 | 66 | # Trainable variables 67 | 68 | # integer embedding 69 | self._integer_embedding = tf.Variable(tf.random_normal([self._integer_range + 1, self._embedding_size]), name='int_embed') 70 | 71 | # main network 72 | self._encoded = self._encoder(self._prog_data) 73 | self._decoded = self._decoder(self._encoded) 74 | 75 | self._loss = tf.reduce_mean(tf.nn.sigmoid_cross_entropy_with_logits(logits=self._decoded, 76 | labels=self._attribute), 77 | name='loss') 78 | 79 | self._optimizer = tf.train.AdamOptimizer(learning_rate=self._learning_rate) 80 | self._train_op = self._optimizer.minimize(self._loss) 81 | self._predict_op = tf.sigmoid(self._decoded) 82 | 83 | self._summary_writer = tf.summary.FileWriter(logdir=os.path.join(self._save_dir, 'log'), 84 | graph=tf.get_default_graph()) 85 | 86 | s1 = tf.summary.histogram('Integer_Embedding', self._integer_embedding) 87 | s2 = tf.summary.scalar('Loss', self._loss) 88 | self._summary_op = tf.summary.merge([s1, s2]) 89 | 90 | 91 | def _encoder(self, x): 92 | 93 | # Split type tensor and value tensor 94 | # Input: [batch_size, num_example, num_input + 1, max_list_len + 2] 95 | # Output: type: [batch_size, num_example, num_input + 1, 2] 96 | # values: [batch_size, num_example, num_input + 1, max_list_len] 97 | types, values = tf.split(x, [2, self._max_list_len], axis=3) 98 | 99 | # Output: [batch_size, num_example, num_input + 1, max_list_len, embedding_size] 100 | values_embeded = tf.nn.embedding_lookup(self._integer_embedding, values) 101 | 102 | values_embeded_reduced = tf.reshape(values_embeded, [-1, 103 | self._num_example, 104 | self._num_input + 1, 105 | self._max_list_len * self._embedding_size]) 106 | 107 | types = tf.cast(types, tf.float32) 108 | 109 | # Output: [batch_size, num_example, num_input + 1, max_list_len*embedding_size + 2] 110 | x_embeded = tf.concat([types, values_embeded_reduced], axis=3) 111 | 112 | output = x_embeded 113 | 114 | # Hidden dense layers 115 | # Output: [batch_size, num_example, num_input + 1, hidden_layer_size] 116 | for i in range(self._num_hidden_layer): 117 | with tf.variable_scope('layer_{}'.format(i)) as scope: 118 | output = tf.layers.dense(inputs=output, 119 | units=self._hidden_layer_size, 120 | activation=tf.sigmoid) 121 | 122 | return output 123 | 124 | 125 | 126 | def _decoder(self, encoded): 127 | 128 | # Average pooling by reducing in examples 129 | # Input: [batch_size, num_example, num_input + 1, hidden_layer_size] 130 | # Output: [batch_size, num_example, (num_input + 1) * hidden_layer_size] 131 | reduced = tf.reshape(encoded, [-1, self._num_example, (self._num_input + 1) * self._hidden_layer_size]) 132 | 133 | # Output: [batch_size, (num_input + 1) * hidden_layer_size] 134 | pooled = tf.reduce_mean(reduced, axis=1, name='pooling') 135 | result = tf.layers.dense(inputs=pooled, 136 | units=self._attribute_size, 137 | #activation=tf.sigmoid, 138 | name='decoded') 139 | 140 | return result 141 | 142 | 143 | def train(self, data, target): 144 | 145 | # Ratio of train test split 146 | split_idx = len(data)//10*9 147 | 148 | # Shuffle training data, unfortunately shuffle cannot take two arrays 149 | # A random seed is created randomly and is used to see both shuffles 150 | some_seed = np.random.randint(1000000) 151 | np.random.seed(some_seed) 152 | np.random.shuffle(data) 153 | np.random.seed(some_seed) 154 | np.random.shuffle(target) 155 | 156 | # Generate train and test data 157 | train_data, train_target= data[:split_idx], target[:split_idx] 158 | test_data, test_target= data[split_idx:], target[split_idx:] 159 | 160 | # Random batch 161 | def get_batch(d, t): 162 | idx = np.random.choice(d.shape[0], size=self._batch_size) 163 | return d[idx], t[idx] 164 | 165 | with tf.Session() as sess: 166 | tf.global_variables_initializer().run() 167 | saver = tf.train.Saver() 168 | for ep in range(1, self._num_epoch + 1): 169 | for _ in range(len(data)//self._batch_size): 170 | train_data_batch, train_target_batch = get_batch(train_data, train_target) 171 | feed = {self._prog_data: train_data_batch, self._attribute: train_target_batch} 172 | sess.run(self._train_op, feed) 173 | loss, summary = sess.run([self._loss, self._summary_op], feed) 174 | 175 | # Report loss every epoch 176 | print('Epoch: ', ep, 'Loss: ',loss) 177 | 178 | # Evaluate model every 10 epoches 179 | if ep%10 == 0: 180 | 181 | test_data_batch, test_target_batch = get_batch(test_data, test_target) 182 | test = sess.run(self._loss, feed_dict={self._prog_data: test_data_batch, 183 | self._attribute: test_target_batch}) 184 | self._summary_writer.add_summary(summary, ep) 185 | print('Epoch: ', ep, 'Test loss:',test) 186 | 187 | # Save model every 20 epoches 188 | if ep%20 == 0: 189 | saver.save(sess, os.path.join(self._save_dir, 'model/model'), global_step=ep) 190 | 191 | def predict(self, data): 192 | 193 | with tf.Session() as sess: 194 | saver = tf.train.Saver() 195 | saver = tf.train.import_meta_graph(os.path.join(self._save_dir, 196 | 'model/model-{}.meta'.format(self._num_epoch))) 197 | saver.restore(sess,tf.train.latest_checkpoint(os.path.join(self._save_dir, 'model/'))) 198 | return sess.run(self._predict_op, feed_dict={self._prog_data: data}) 199 | 200 | -------------------------------------------------------------------------------- /python/model/checkpoint: -------------------------------------------------------------------------------- 1 | model_checkpoint_path: "model-100" 2 | all_model_checkpoint_paths: "model-20" 3 | all_model_checkpoint_paths: "model-40" 4 | all_model_checkpoint_paths: "model-60" 5 | all_model_checkpoint_paths: "model-80" 6 | all_model_checkpoint_paths: "model-100" 7 | -------------------------------------------------------------------------------- /python/model/model-100.data-00000-of-00001: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/model/model-100.data-00000-of-00001 -------------------------------------------------------------------------------- /python/model/model-100.index: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/model/model-100.index -------------------------------------------------------------------------------- /python/model/model-100.meta: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/model/model-100.meta -------------------------------------------------------------------------------- /python/model/model-20.data-00000-of-00001: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/model/model-20.data-00000-of-00001 -------------------------------------------------------------------------------- /python/model/model-20.index: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/model/model-20.index -------------------------------------------------------------------------------- /python/model/model-20.meta: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/model/model-20.meta -------------------------------------------------------------------------------- /python/model/model-40.data-00000-of-00001: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/model/model-40.data-00000-of-00001 -------------------------------------------------------------------------------- /python/model/model-40.index: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/model/model-40.index -------------------------------------------------------------------------------- /python/model/model-40.meta: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/model/model-40.meta -------------------------------------------------------------------------------- /python/model/model-60.data-00000-of-00001: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/model/model-60.data-00000-of-00001 -------------------------------------------------------------------------------- /python/model/model-60.index: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/model/model-60.index -------------------------------------------------------------------------------- /python/model/model-60.meta: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/model/model-60.meta -------------------------------------------------------------------------------- /python/model/model-80.data-00000-of-00001: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/model/model-80.data-00000-of-00001 -------------------------------------------------------------------------------- /python/model/model-80.index: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/model/model-80.index -------------------------------------------------------------------------------- /python/model/model-80.meta: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/water-vapor/DeepCoder-tensorflow/1fe708478636daa632cc9ea5249142cbf396fc59/python/model/model-80.meta -------------------------------------------------------------------------------- /python/util_gen.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | import os 3 | 4 | parser = argparse.ArgumentParser(description='util.py generator') 5 | parser.add_argument('path', type=str, help='Path(folder) to original model.py and predictor.py') 6 | args = parser.parse_args() 7 | 8 | with open(os.path.join(args.path, 'model.py')) as m: 9 | model_lines = m.read().split("\n") 10 | with open(os.path.join(args.path, 'predictor.py')) as p: 11 | pred_lines = p.read().split("\n") 12 | part1 = model_lines[-45:] 13 | to_replace = [('integer_min','params[\'integer_min\']'), 14 | ('integer_range','params[\'integer_range\']'), 15 | ('list_length','params[\'max_list_len\']'), 16 | ('input_num','params[\'num_input\']')] 17 | 18 | def fold_replace(expr, li): 19 | for old, new in li: 20 | expr=expr.replace(old, new) 21 | return expr 22 | 23 | rep1 = [fold_replace(l, to_replace) for l in part1] 24 | 25 | for i in [7,24,35,42]: 26 | rep1[i]=rep1[i].replace('):', ', params):') 27 | for i in [31,38,43]: 28 | rep1[i]=rep1[i].replace(') for', ', params) for') 29 | rep1[32]=rep1[32].replace(')])', ', params)])') 30 | rep1[16]=rep1[16].replace('convert_integer(x)', 'x-params[\'integer_min\']') 31 | part2 = pred_lines[27:37] 32 | part2[0]=part2[0].replace('):',', f):') 33 | part2[-2]=part2[-2].replace(')',', file=f)') 34 | imp=['import numpy as np',''] 35 | script = imp+part2+rep1 36 | 37 | try: 38 | os.remove('util.py') 39 | except OSError: 40 | pass 41 | with open('util.py','w+') as f: 42 | for line in script: 43 | f.write(line +'\n') 44 | -------------------------------------------------------------------------------- /scripts/gen_program_gen.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | import os 3 | 4 | parser = argparse.ArgumentParser(description='gen_program.sh generator') 5 | parser.add_argument('path', type=str, help='Path(folder) to original gen_program.sh') 6 | args = parser.parse_args() 7 | 8 | with open(os.path.join(args.path, 'gen_program.sh')) as f: 9 | script = f.read().split("\n") 10 | 11 | script[2]='' 12 | script[3]=script[3][:-2]+'$1' 13 | script[4]=script[4][:-2]+'$2' 14 | script.insert(5,'enablemodel=$3') 15 | cmd1 = script[8][:32]+'deepcoder.py predict ${example} -e ${enablemodel} ' 16 | cmd2 = script[8][-82:-62]+'$(dirname $0)/../python/output '+script[8][-62:] 17 | del(script[-2]) 18 | script.insert(8, cmd1) 19 | script.insert(9, cmd2) 20 | del(script[2]) 21 | 22 | try: 23 | os.remove('gen_program.sh') 24 | except OSError: 25 | pass 26 | with open('gen_program.sh','w+') as f: 27 | for line in script: 28 | f.write(line +'\n') 29 | --------------------------------------------------------------------------------